RIP SunMicrosystem
RIP SunMicrosystem

Reputation: 426

Trying to Implement a simple Jersey Rest Project

I'm trying to implement a simple Jersey rest client

Message.class:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@Path("/message")
public class Message {

    @GET
    @Path("/postmsg/{regId}/{msg}")
    @Produces("text/plain")
    public Response sendMsg(@PathParam("regId") String regId,@PathParam("msg") String msg) {

        String output ="RegId: " + regId + ", Message: " + msg; 
        return Response.status(200).entity(output).build();

    }
}

Web.xml I've added jersey dependency in My web.xml as below.

<web-app>
  <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>jersey-servlet</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.sample.web.msg</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

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

Pom.xml: I've added jersey dependency in My web.xml as below.

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

And when I try to run this url on my browser:

http://localhost:8080/GCM/message/postmsg/regId/msg

All I get is *HTTP Status 404 - /GCM/message/postmsg/regId/msg *

Can someone please help, what is that I'm missing, thanks in advance. :)

Upvotes: 0

Views: 62

Answers (1)

soulcheck
soulcheck

Reputation: 36767

Your Jersey servlet is mapped to /rest/* but your url is begins with /GCM/*.

Either change the servlet mapping to:

<servlet-mapping>
    <servlet-name>jersey-servlet</servlet-name>
    <url-pattern>/GCM/*</url-pattern>
</servlet-mapping>

or access the following url:

http://localhost:8080/rest/message/postmsg/regId/msg

Upvotes: 1

Related Questions