我试图加载具有球衣多个文件,但它要求我一些配置,我无法找到。 这是依赖,我不得不添加,因为球衣无法解析器类型“多部分/相关”:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.7</version>
</dependency>
这是我用的是多的API:
@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;
}
这是web.xml中,我想我在这里失去了一些东西:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is 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>
这是个例外:
A MultiException has 3 exceptions. They are:
1. java.lang.IllegalArgumentException: The MultiPartConfig instance we expected is not present. Have you registered the MultiPartConfigProvider class?
2. java.lang.IllegalStateException: Unable to perform operation: create on com.sun.jersey.multipart.impl.MultiPartReaderClientSide
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory