Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors$ErrorMessagesException when using Jersey in Java

Tags:

java

rest

jersey

I am using Jersy to develeop REST webservices, this is my simple code:

@GET
@Path("/retrieveCustomerInformation/{jsonString}")
@Produces(MediaType.APPLICATION_JSON)
public String retrieveCustomerInformation(@PathParam("jsonString")JSONObject jsonObject) 
    throws Exception  {
      //Other codes here

    }

But when I ping the rest service url from browser, I am getting below exception:

javax.servlet.ServletException: Servlet.init() for servlet jersey-serlvet threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)

and the root cause is:

com.sun.jersey.spi.inject.Errors$ErrorMessagesException
com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)

Can someone guide me, what causes this error? I am finding difficult to understand this error message as it doesn't provide any useful information to debug.

This is my web.xml

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>
                 com.sun.jersey.spi.container.servlet.ServletContainer
            </servlet-class>
    <init-param>
         <param-name>com.sun.jersey.config.property.packages</param-name>
         <param-value>com.test/param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

I am using Jersey 1.8, JDK 1.7 and App is running on Tomcat 7.0. If required I can provide more information.

like image 706
Pradeep Simha Avatar asked Dec 14 '13 01:12

Pradeep Simha


2 Answers

Check for clashing @Path annotations. This will result with the same error. It's a weird error for communicating path issues, but you can easily test it by renaming the matching paths.

Example of cashing paths in the code below

Some class

@Path("/storage")
public class BookingRestService {

@GET
@Path("/bookings")
@Produces(value = MediaType.APPLICATION_XML)

and another class

@Path("/storage")
public class StorageRestService {

By renaming any of the @Path("/storage") the problem seizes to impair your work progress.

like image 52
Tomasz O. Avatar answered Oct 03 '22 07:10

Tomasz O.


Your question seems to be a duplicate and has probably been appropriately addressed. I too had the same issue some time ago. Click here to see the accepted answer that resolved it for me

And in case you're reluctant to follow the link, first of all, try adding jersey-multipart.jar and mimepull.jar to your project libraries... And if your project is a Maven project, add the following dependencies to your pom.xml. The mimepull dependency should ship along with it.

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

Remember to ensure that the version of jersey-multipart that you use, is the same as the version of jersey that you're using in the project.

Just in case the above solution doesn't resolve your issue, you may want to see here for more useful tips too. Cheers!

like image 22
SourceVisor Avatar answered Oct 03 '22 07:10

SourceVisor