Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception :com.sun.jersey.spi.inject.Errors$ErrorMessagesException

I am using the Jersey API for the web services. I am sending the multipart data from client to server. I am getting exception when web services start to execute.

@POST
@Path("uploadphoto")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
public String uploadNotices(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) {
    String uploadedFileLocation = "d:/" + fileDetail.getFileName();
    // save it
    try {
        writeToFile(uploadedInputStream, uploadedFileLocation);
    } catch(Exception e) {
        return "no";
    }
    return "yes";
}

// save uploaded file to new location
private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) throws Exception {
    OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
    int read = 0;
    byte[] bytes = new byte[1024];

    out = new FileOutputStream(new File(uploadedFileLocation));
    while ((read = uploadedInputStream.read(bytes)) != -1) {
        out.write(bytes, 0, read);
    }
    out.flush();
    out.close();
}

Stacktrace:

SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public java.lang.String com.homebulletin.resources.NoticeResources.uploadNotices(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 0
  SEVERE: Missing dependency for method public java.lang.String com.homebulletin.resources.NoticeResources.uploadNotices(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 1
  SEVERE: Method, public java.lang.String com.homebulletin.resources.NoticeResources.uploadNotices(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition), annotated with POST of resource, class com.homebulletin.resources.NoticeResources, is not recognized as valid resource method.
Jun 18, 2013 10:55:17 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:760)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)

Jun 18, 2013 10:55:17 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Home Bulletin
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:760)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
like image 230
N Sharma Avatar asked Jun 18 '13 05:06

N Sharma


4 Answers

It seems your missing few jars in your project.Try adding these to your project:

jersey-multipart.jar

mimepull.jar

If you are using maven, you can add this dependency:

<dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.8</version>
    </dependency>

Change the version of jar if you need

Also make sure that the version of your jersey-multipart jar should be same as the version of jersey bundle jar

like image 111
Juned Ahsan Avatar answered Nov 15 '22 13:11

Juned Ahsan


Forgetting to add @POST or @Get on top of the method name will also cause this error

like image 45
code511788465541441 Avatar answered Nov 15 '22 13:11

code511788465541441


It faced me the same error because having same @Path annotations with the same path names( strings).

@Path('samepath')   /// samepath cause Jersey Error at run time.
/* Method 1*/

@Path('samepath')
/* Method 2 */
like image 45
Yergalem Avatar answered Nov 15 '22 13:11

Yergalem


com.sun.jersey.spi.inject.Errors$ErrorMessagesException

occured when I had two @GET methods with the same path but different query params.

Also it may happen if you rename your controller class, do mvn install without mvn clean and put war file to /webapps folder.

like image 4
Justinas Jakavonis Avatar answered Nov 15 '22 12:11

Justinas Jakavonis