N Sharma
N Sharma

Reputation: 34497

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)

Upvotes: 24

Views: 59848

Answers (11)

Hasan Beheshti
Hasan Beheshti

Reputation: 3615

Sometimes you specified @FormDataParam instead @QueryParam in GET method, in my case that was the problem.

Upvotes: 0

big data nerd
big data nerd

Reputation: 508

There are multiple potential reasons therefore, just mentioning the most common ones

  • you are lacking some JAR files
  • you have multiple java methods with the same @Path annotation and the same HTTP methods (i.e. with different params or query params)
  • you have a web service method with an invalid response or request param type (i.e. a annotation class as parameter class or other weird stuff)

Upvotes: 1

Ajanthan
Ajanthan

Reputation: 308

I know it's to late. But updating it here for future references. Better check the jar versions. I had the same issue. I was using the 1.16 version of jersey core and server, but this one i added with 1.18. It gave the same error. But then I realized and changed to 1.16 then worked fine.

It doesn't work with different versions.

Upvotes: 0

Justinas Jakavonis
Justinas Jakavonis

Reputation: 8798

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.

Upvotes: 4

Yergalem
Yergalem

Reputation: 1763

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 */

Upvotes: 7

Abhi.P
Abhi.P

Reputation: 130

I had a similar problem as I missed out to add a "Consumes" annotation for my POST method. Hope it helps someone.

Upvotes: 0

Datageek
Datageek

Reputation: 26689

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.

Upvotes: 3

JiLiang
JiLiang

Reputation: 21

I met this problem because I did not have no parameter constructor in my class

@Path("/deviceconfigs")
public class DeviceConfigInterface extends ComInterfaceGen<DeviceConfigApi> {
    public DeviceConfigInterface(Class<DeviceConfigApi> type) {
        super(DeviceConfigApi.class);
    }
}.

When I used no parameter constructor, the problem is solved.

Upvotes: 0

124697
124697

Reputation: 21893

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

Upvotes: 14

user4336792
user4336792

Reputation: 21

Replace your web.xml with this code:

<servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>  org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Upvotes: 2

Juned Ahsan
Juned Ahsan

Reputation: 68715

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

Upvotes: 22

Related Questions