Question

I send a get request to this url: http://localhost:8180/GoogleMapsErp/EQUI/000001 I get this error:

 SEVERE: Servlet /GoogleMapsLoadingTest threw load() exception
  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:795)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1274)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1186)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1081)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5320)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)

This is the corrersponding method in my class:

@Path("/GoogleMapsErp")
public class MapErpService {

    @GET
@Path("/{objtype}/{objkey}")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getGeometry(@PathParam("objtype")String objtype,@PathParam("objkey") String objkey)
{
    ResultSet rs=db.queryValue(objkey, objtype);
    JSONObject res=null;
    try {
        if(rs.next())   
        {
            String wkt=rs.getString("AsText(Geometry)");
            res=db.convertToGeoJSON2(wkt);
            System.out.println(res);
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return res;
}

I can get the resource using a servlet but here it throws an 404 error.I have also created a method with PUT requests to the same uri.

I tried adding mimepull and jersey-multipart to the project's libraries but the error still persists:

 asm-3.1.jar               jersey-servlet-1.18.jar
 jersey-client-1.18.jar    json-simple-1.1.1.jar
 jersey-core-1.18.jar      jsr311-api-1.1.1.jar
 jersey-json-1.18.jar      mimepull-1.6.jar
 jersey-multipart-1.8.jar  mysql-connector-java-5.1.30-bin.jar
 jersey-server-1.18.jar

web.xml

 <servlet>
    <servlet-name>Jersey REST Services</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.hastha.maperp.webservice</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Services</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

These are some errors I get while the server is starting:

 com.sun.jersey.api.core.PackagesResourceConfig init
 INFO: Scanning for root resource and provider classes in the packages:
 com.hastha.maperp.webservice
 com.sun.jersey.api.core.ScanningResourceConfig logClasses
 INFO: Root resource classes found:
 class com.hastha.maperp.webservice.MapErpService
 com.sun.jersey.api.core.ScanningResourceConfig init
 INFO: No provider classes found.
 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
 INFO: Initiating Jersey application, version 'Jersey: 1.18 11/22/2013 01:21 AM'
 com.sun.jersey.spi.inject.Errors processErrorMessages
 SEVERE: The following errors and warnings have been detected with resource and/or  provider classes:
 SEVERE: Consuming media type conflict. The resource methods public   
 javax.ws.rs.core.Response    com.hastha.maperp.webservice.MapErpService.updateGeometry(java.lang.String,java.lang.String,org.json.simple.JSONObject) and public javax.ws.rs.core.Response com.hastha.maperp.webservice.MapErpService.createGeometry(java.lang.String,java.lang.String,org.json.simple.JSONObject) can consume the same media type
 org.apache.catalina.core.ApplicationContext log
 SEVERE: StandardWrapper.Throwable

UPDATE:

I am stumped by this,I have posted the entire web-service code here

Was it helpful?

Solution

Within the web.xml have you create the following Jersey servlet class path setting

<servlet>
    <servlet-name>Jersey</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>your rest service.package.path</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Jersey</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Then you have to call the REST service like

http://localhost:8180/rest/GoogleMapsErp/EQUI/000001

Also take a look at this beautiful stuff

Create RESTful web service in java(JAX-RS) using jersey

The syntax of the REST URL will be like as shown below enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top