org.glassfish.jersey.server.ContainerException:java.lang.NoSuchMethodError:org.jvnet.mimepull.MIMEMessage.close()V

时间:2017-10-19 19:56:20

标签: java rest java-ee glassfish multipartform-data

当我使用POSTMAN对我的RestService进行POST时,我收到此错误,我搜索并出现库问题,但我想我一切都很好。

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);
    }

}

@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();

    }
}

图书馆

Jersey的媒体多部分2.26.jar mimepull-1.9.7.jar

堆栈跟踪

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)...

我正在使用GlassFish 4.1.1,Java EE 7和Jersey

1 个答案:

答案 0 :(得分:0)

我想你可能会降级你的jeresy lib。因为jersey 2.26适用于java ee 8。