1 Reply Latest reply on Feb 6, 2012 5:35 AM by Andrea Leoncini

    problem using reasteasy

    Andrea Leoncini Newbie

      I created a very simple web application with a REST ws as described here

      https://docs.jboss.org/author/display/AS7/JAX-RS+Reference+Guide

       

      the web.xml is:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <web-app version="3.0" id="WebApp_ID"

              xmlns="http://java.sun.com/xml/ns/javaee"

              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

      </web-app>

       

      and the POJO is the typical library class as follow:

       

      package it.jboss.jbs.spikes;

       

      import javax.ws.rs.*;

      import javax.ws.rs.core.Application;

       

      @ApplicationPath("/library")

      public class Library extends Application{

       

          @GET

          public String getInfo() {

              return "This is a REST Library service";

          }

       

          @GET

          @Path("/books")

          public String getBooks() {

              return "This is a list of Books";

          }

       

          @GET

          @Path("/book/{isbn}")

          public String getBook(@PathParam("isbn") String id) {

              return "My first book with ISBN=" + id;

          }

       

      }

       

      the web app context path is jbs

       

      requesting a

       

      localhost:8080/jbs

       

      everything work fine but when I try to access the rest path

       

      http://localhost:8080/jbs/library

       

      I get an 404 ERROR - could not find resource...

       

      the strange behaviour is that when I request the REST path I see the following log in the console:

       

      15:19:29,757 INFO  [org.jboss.resteasy.spi.ResteasyDeployment] (http--127.0.0.1-8080-2) Deploying javax.ws.rs.core.Application: class it.jboss.jbs.spikes.Library

       

      which I expected to see at the deploy time of the war.

       

      I'm using jboss-as-7.1.0.CR1b release

      is anyone able to point me in what I'm doing wrong?

      thanks in advance

      andrea

        • 1. Re: problem using reasteasy
          Andrea Leoncini Newbie

          I was able to make it run using the alternative method as following:

           

          I've changed the library class whici is now

           

          package it.jboss.jbs.spikes;

           

          import javax.ws.rs.GET;

          import javax.ws.rs.Path;

          import javax.ws.rs.Produces;

           

          @Path("/lib")

          public class Library {

           

              @GET

              public String getInfo() {

                  return "Simple REST Service";

              }

           

              @GET

              @Path("/xml")

              @Produces({ "application/xml" })

              public String getHelloWorldXML() {

                  return "<xml><result>Hello World</result></xml>";

              }

           

          }

           

          and adding a servlet mapping to the web.xml

           

          <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

              <servlet-mapping>

                  <servlet-name>javax.ws.rs.core.Application</servlet-name>

                  <url-pattern>/rs/*</url-pattern>

              </servlet-mapping>

          </web-app>

           

          By the way I would like to understand what was wrong with the first method

          thanks

          andrea