I get this error when I do a POST with POSTMAN to my RestService, I searched and just appear libraries problem but i guess i have everything fine.
Web.xml
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>Jersey Servlet</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.netbeans.rest.application.config.ApplicationConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
ApplicationConfig.java
@javax.ws.rs.ApplicationPath("webresources")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
addRestResourceClasses(resources);
resources.add(MultiPartFeature.class);
return resources;
}
/**
* Do not modify addRestResourceClasses() method.
* It is automatically populated with
* all resources defined in the project.
* If required, comment out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(com.src.servicio.service.ServicioREST.class);
}
}
Class
@Path("/service")
public class ServicioREST {
private final java.sql.Date fecha_Actual = new java.sql.Date(new java.util.Date().getTime());
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat dateFormat2 = new SimpleDateFormat("dd-MM-yyyy-HH-mm");
SimpleDateFormat yearformat = new SimpleDateFormat("yyyy");
DateFormat hourFormat = new SimpleDateFormat("HH:mm:ss");
@POST
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Path("test")
public Response prueba(@HeaderParam("token") String token, @FormDataParam("unix_time") String fecha,
@FormDataParam("plate") String placa, @FormDataParam("lng") float longitud, @FormDataParam("lat") float latitud,
@FormDataParam("speed_allowed") float velPermitida, @FormDataParam("over_speed") float velVehiculo,
@FormDataParam("video") InputStream video, @FormDataParam("evidence") InputStream fotoLejana,
@FormDataParam("fragment") InputStream fotoCercana) throws Exception {
OutputStream out;
int read;
byte[] bytes = new byte[1024];
//Guarda la foto panoramica del vehiculo
out = new FileOutputStream(new File(dir + "\\" + placa + "_panoramica.jpg"));
while ((read = fotoLejana.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
fotoLejana.close();
out.close();
plano_detalle.setFoto_lejos(dir + "\\" + placa + "_panoramica.jpg");
//Guarda la foto cercana de la placa del vehiculo
out = new FileOutputStream(new File(dir + "\\" + placa + "_cerca.jpg"));
while ((read = fotoCercana.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
fotoCercana.close();
out.close();
plano_detalle.setFoto_cerca(dir + "\\" + placa + "_cerca.jpg");
return Response.ok().build();
}
}
Libraries
jersey-media-multipart-2.26.jar mimepull-1.9.7.jar
Stack Trace
java.lang.NoSuchMethodError: org.jvnet.mimepull.MIMEMessage.close()V
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide.getMimeParts(MultiPartReaderClientSide.java:276)
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide.readMultiPart(MultiPartReaderClientSide.java:231)
at org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide.readMultiPart(MultiPartReaderServerSide.java:91)...
Im working with GlassFish 4.1.1, Java EE 7 and Jersey
I think you may downgrade your jeresy lib. Since jersey 2.26 is for java ee 8.