Question

I´m trying to create a Grizzly HTTP Server from a main method and I am getting this IllegalArgumentException:

java.lang.IllegalArgumentException: The MultiPartConfig instance we expected is not    present.  Have you registered the MultiPartConfigProvider class?

I have tried to register manually both a new instance of MultiPartConfigProvider and the class itself (see commented lines). What could I be missing?

This is the code:

public class ResourceServer
{

public static final String HOST = "localhost";
public static final int PORT = 8080;
public static final String ROOT = "dummy";

public static final URI BASE_URI = ResourceUriBuilder.getBaseURI(HOST, PORT, ROOT);
private static final String BASE_PACKAGE_NAME = "com.mycompany.myapp.resource";

public static HttpServer startServer()
{
    final ResourceConfig rc = new ResourceConfig().packages(true, BASE_PACKAGE_NAME);

//        rc.register(new MultiPartConfig());
//
//        MultiPartConfigProvider provider = new MultiPartConfigProvider();
//        rc.register(provider);

//        rc.register(MultiPartConfig.class);


    return GrizzlyHttpServerFactory.createHttpServer(BASE_URI,rc);
}

public static void main(String[] args) throws IOException
{
    final HttpServer server = startServer();
    // ...
}
}

This is the stacktrace:

 java.lang.IllegalArgumentException: The MultiPartConfig instance we expected is not present.
 Have you registered the MultiPartConfigProvider class?
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.<init>(MultiPartReaderClientSide.java:102)
com.mycompany.myapp.resource.server.ResourceServer.startServer(ResourceServer.java:37)
at com.mycompany.myapp.resource.server.ResourceServer.main(ResourceServer.java:47)

And these are the relevant dependencies in the POM file:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>16.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.6</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-grizzly2-http</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.8</version>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>2.5.0</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>2.5.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.5</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<properties>
    <jersey.version>2.7</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

EDIT: This is the File Resource where I am trying to use the MultiPart support for uploading a file. This Resource is causing the error:

@Path("/file")
public class FileResource
{
    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) {
    // Empty method here
}
Was it helpful?

Solution

I managed to resolve the problem myself: I removed these annotations for the FileResource:

@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail)

And this library from the pom.xml file:

<dependency>
     <groupId>com.sun.jersey.contribs</groupId>
     <artifactId>jersey-multipart</artifactId>
     <version>1.8</version>
</dependency>

And the problem just dissapears... You can upload files without any problem. Hope it helps to anyone having the same stupid problem. If anyone happens to know the reason of this failue, please let me know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top