exception - Jersey: How to register MultiPartConfigProvider class -
i'm trying load multiple files jersey, demands me configuration can't find. dependency, had add because jersey couldn't resolver type "multipart/related":
<dependency> <groupid>org.glassfish.jersey.media</groupid> <artifactid>jersey-media-multipart</artifactid> <version>2.7</version> </dependency>
this api use multipart:
@put @consumes("multipart/related") @path("/{id}/user/{userid}") public response loadfile(@pathparam("id") int id, @pathparam("userid") int userid, multipart files) throws exception{ int resultado = tool.loadfile(id, userid, files); switch (resultado){ case 401: return response.status(401).entity("no existe el experimento con id: "+id).build(); case 402: return response.status(402).entity("el tipo de uno de los archivos no se encuentra en los tipos de entregables del experimento").build(); case 403: return response.status(403).entity("el usuario: "+userid+" no participa en el experimento").build(); case 405: return response.status(405).entity("debe ingresar un comentario").build(); case 406: return response.status(406).entity("hay entregables sin subir").build(); case 200: return response.status(200).build(); } return null; }
this web.xml, think missing here:
<?xml version="1.0" encoding="utf-8"?> <!-- web.xml file not required when using servlet 3.0 container, see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>jersey web application</servlet-name> <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>org.mockapi</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey web application</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app>
and exception:
a multiexception has 3 exceptions. are: 1. java.lang.illegalargumentexception: multipartconfig instance expected not present. have registered multipartconfigprovider class? 2. java.lang.illegalstateexception: unable perform operation: create on com.sun.jersey.multipart.impl.multipartreaderclientside 3. java.lang.illegalstateexception: unable perform operation: create on org.glassfish.jersey.message.internal.messagebodyfactory
if using new version of dropwizard, dependency should be, <dependency> <groupid>org.glassfish.jersey.media</groupid> <artifactid>jersey-media-multipart</artifactid> <version>2.15</version> </dependency>
because new version of dropwizard
uses org.glassfish.jersey.core:jersey-server:jar
.
, have register multipartfeature
in our application's run
method environment.jersey().register(multipartfeature.class);
more information can check here
Comments
Post a Comment