java - Null MultiPartConfig when creating GrizzlyHttpServer -
i´m trying create grizzly http server main method , getting illegalargumentexception:
java.lang.illegalargumentexception: multipartconfig instance expected not present. have registered multipartconfigprovider class?
i have tried register manually both new instance of multipartconfigprovider , class (see commented lines). missing?
this 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 stacktrace:
java.lang.illegalargumentexception: multipartconfig instance expected not present. have registered multipartconfigprovider class? @ com.sun.jersey.multipart.impl.multipartreaderclientside.<init>(multipartreaderclientside.java:102) com.mycompany.myapp.resource.server.resourceserver.startserver(resourceserver.java:37) @ com.mycompany.myapp.resource.server.resourceserver.main(resourceserver.java:47)
and these relevant dependencies in 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: file resource trying use multipart support uploading file. resource causing 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 }
i managed resolve problem myself: removed these annotations fileresource:
@formdataparam("file") inputstream uploadedinputstream, @formdataparam("file") formdatacontentdisposition filedetail)
and library pom.xml file:
<dependency> <groupid>com.sun.jersey.contribs</groupid> <artifactid>jersey-multipart</artifactid> <version>1.8</version> </dependency>
and problem dissapears... can upload files without problem. hope helps having same stupid problem. if happens know reason of failue, please let me know.
Comments
Post a Comment