views:

781

answers:

4

I am new to RESTful Services.

I am trying to deploy a simplest REST service using jersey, and JAX-RS, but i am getting this error,

HTTP ERROR: 404 NOT_FOUND RequestURI=/hosting/demo/example Powered by Jetty://

Where i think i have done everything right, below is the code i am using for it.

POM.XML (only pasting the part related to jersey)

<dependency>
    <!-- the implementation of JAX-RS -->
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.0.1</version>
</dependency>
<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.0.1</version>
</dependency>
<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.0.1</version>
        <scope>compile</scope>
</dependency>

WEB.XML

<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>mop.core.service.restservices</param-value>
        </init-param>
</servlet>
<servlet-mapping>
        <servlet-name>jersey</servlet-name>
        <url-pattern>/demo</url-pattern>
</servlet-mapping>

My Class having @GET

package mop.core.service.restservices;

import javax.swing.JOptionPane;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/example")
public class PricePointRestService {
    @GET
    @Produces("text/plain")
    public String getPricePoint(){
     JOptionPane.showMessageDialog(null, "GET CALLED");
     return "hello";
    }

       @POST
       @Produces("application/xml")
       @Consumes({"application/x-www-form-urlencoded", "multipart/form-data"})
       public String doPost(@FormParam("xml") String xml) {
           return "<xml></xml>";
       }
}

The url i hit is: http://localhost/hosting/demo/example

Please help, its very urgent, thanks in advance

A: 

Are you sure the "hosting" part of the url is correct? What is the web app deployed under? Can you hit any pages in the web app?

Try adding a jsp to the web-app and see if you can hit that.

Pablojim
Yes hosting part is correct, as i am working in an established project. All the app works fine, the problem i figured out was compatibility issue of ASM 2.2.3 and Jersey which requires ASm 3.1.
A: 

Change your url-pattern in your web.xml to:

<url-pattern>/demo/*</url-pattern>
Damo
A: 

Agree with Damo on:

<url-pattern>/demo/*</url-pattern>

Also add:

<load-on-startup>1</load-on-startup>

before:

</servlet>

I assume you're using Maven. Hibernate 3.2.4 runs fine on ASM 3.1 so you can ignore that dependency. This entry will work with Jersey.

   <dependency><!--  hibernate 3.2.4.ga -->
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.6.ga</version>
            <exclusions>
                    <exclusion>
                            <groupId>asm</groupId>
                            <artifactId>asm</artifactId>
                    </exclusion>
                    <exclusion>
                            <groupId>asm</groupId>
                            <artifactId>asm-attrs</artifactId>
                    </exclusion>              
                    <exclusion>
                            <groupId>cglib</groupId>
                            <artifactId>cglib</artifactId>
                    </exclusion>
            </exclusions>

    </dependency>
stevedbrown
A: 

The problem i figured out was compatibility issue of ASM 2.2.3 and Jersey which requires ASM 3.1. Hibernate depends upon ASm 2.2.3.

This bug is reported at http://opensource.atlassian.com/projects/hibernate/browse/EJB-358?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

I am trying to find out the work arounds for this, but those doesnt seem to work out, as cglib 2.2 and cglib-nodep also doesnt help.

javassist cannot be used through XML config file of hibernate, it requires hibernate.properties file, where the project i am working on used hibernate.cfg.xml.

Any Solution ?