Exception :com.sun.jersey.spi.inject.Errors$ErrorMessagesException
Solution 1
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
Solution 2
Forgetting to add @POST
or @Get
on top of the method name will also cause this error
Solution 3
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 */
Solution 4
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.
Solution 5
I have seen exactly the same error when using @FormParam
(which expects @POST
) with @GET
parameters.
Hope it will help someone as it wasn't very intuitive to find out.
Related videos on Youtube
N Sharma
I have done masters in Advanced Software Engineering. I have worked on various technologies like Java, Android, Design patterns. My research area during my masters is revolving around the Recommendation algorithms that E-commerce websites are using in order to recommend the products to their customers on the basis of their preferences.
Updated on September 05, 2020Comments
-
N Sharma over 3 years
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)
-
Juned Ahsan almost 11 yearsDo you have all the required libs in your project? using maven?
-
-
N Sharma almost 11 yearsI added the mimepull-1.3.jar and jersey-multipart-1.8.jar. But still getting exception.
-
Juned Ahsan almost 11 yearsWhere have you added? Make sure those are available at run-time
-
N Sharma almost 11 yearsSEVERE: Missing dependency for method public java.lang.String com.homebulletin.resources.NoticeResources.uploadNotices(java.io.InputStream) at parameter at index 0 SEVERE: Method, public java.lang.String com.homebulletin.resources.NoticeResources.uploadNotices(java.io.InputStream), annotated with POST of resource, class com.homebulletin.resources.NoticeResources, is not recognized as valid resource method. Jun 18, 2013 11:41:24 AM org.apache.catalina.core.ApplicationContext log
-
N Sharma almost 11 yearsI added them in the WEb-INF -> lib folder of the project
-
Juned Ahsan almost 11 years@Android Also make sure that the version of your jersey-multipart jar should be same as the version of jersey bundle jar
-
N Sharma almost 11 yearsjersey-bundle-1.8.jar and jersey-multipart-1.8.jar & mimepull-1.3.jar & jersey-server-1.8.jar but still getting exception.
-
N Sharma almost 11 yearsI put the jersey-bundle-1.14.jar & jersey-multipart-1.14.jar but in java source code I am getting error "import com.sun.jersey.multipart can not resolved"
-
N Sharma almost 11 years+1 thanks problem resolved it was problem of versions of jar files.
-
N Sharma almost 11 yearsHow can i save the photo on the server folder. Please share if you have any idea of this
-
Juned Ahsan almost 11 years@Android post a new question ;-)
-
Bhushan over 8 years+1 In my case the reason for error was, I was using
@FormParam
in method which was listening to@GET
method. -
jsh6303 over 8 yearsWhat if I am not using MAVEN?
-
Juned Ahsan over 8 years@JiajuShen you will have to download all required jars manually. In my pre-maven days, i used google and the following website to find jars: findjar.com/index.x
-
Bankin over 8 yearsI lost couple of hours digging everything and i was this annotation.. Thank you!
-
luk2302 about 7 yearsAnd what is your proposed solution to the problem? In what way does this answer the question?
-
Andreea about 6 years@luk2302 I think he gave a suggestion about what may be wrong, I don't see what he could have explained more in this particular case.