7 Replies Latest reply on Apr 2, 2013 10:14 PM by paulf70

    How to use resteasy on jboss as 7?

    baecks

      I created a web application in eclipse and included the following code into my web.xml:

       

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

       

       

      <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">

      </web-app>

      The I created a simple POJO, to handle requests:

       

      //@ApplicationPath( "api" )

      @Path("tutorial")

      public class RestRequest1 {

                @GET

                @Path("helloworld")

                public String helloworld() {

                          return "Hello World!";

                }

      }

      When deploying this to AS7, the resteasy doesn't seem to be activated and pick up the code. No matter what URL I try (from the eclipse built-in browser), I get a page not found error (http://<context>/tutorial/helloworld - http://<context>/api/tutorial/helloworld - http://<context>/api/helloworld). Nothing works!

       

      Does anybody know how to make resteasy work on AS 7 (should be part of AS 7 and ready for use I read)?

       

      Thanks,

      Sven.

        • 1. Re: How to use resteasy on jboss as 7?
          swd847

          You need to use one of the 3 options here:

           

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

           

          The ApplicationPath annotation you have commented out in your POJO will not work, as it is on a resource class, not an application class.

          • 2. Re: How to use resteasy on jboss as 7?
            baecks

            Hi Stuart,

             

            Thanks for your answer. I tried the options mentioned in the link you sent, but still it's not fully working. When e.g. I change my web.xml into:

             

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

             

             

            <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>org.test.resttest.RestRequest1</servlet-name>

               <url-pattern>/hello/*</url-pattern>

            </servlet-mapping>

            </web-app>

             

            And my POJO code is:

             

            package org.test.resttest;

             

             

            import javax.ws.rs.ApplicationPath;

            import javax.ws.rs.GET;

            import javax.ws.rs.Path;

            import javax.ws.rs.core.Application;

             

             

            //@ApplicationPath( "api" )

            //@Path("api")

            public class RestRequest1 extends Application{

                 @GET

                 @Path("helloworld")

                 public String helloworld() {

                      return "Hello World!";

                 }

            }

             

             

            I get the folloing error for a get on "http://localhost:8080/RestTest1/hello/helloworld":

             

            HTTP Status 404 - Could not find resource for relative : /helloworld of full path: http://localhost:8080/RestTest1/hello/helloworld

             

            Would you have any idea?

             

            Thanks,

            Sven.

            • 3. Re: How to use resteasy on jboss as 7?
              smtrax

              Did you found a solution? 

               

              I have  the same problem.

               

              Here sais how to configure on JBoss M4 and Higher:

              http://docs.jboss.org/resteasy/docs/2.3-beta-1/userguide/html_single/index.html#d0e219

               

               

              On JBoss 6.0 Final works fine, but on JBoss 7.0.0 Final does not!

               

              HTTP Status 404 - Could not find resource for relative

               

               

              Does someone have idea, how to fix this?

              • 4. Re: How to use resteasy on jboss as 7?
                smtrax

                I found out how to do it:

                 

                1.) You have to extends javax.ws.rs.core.Application:

                    

                @Path("/library")

                public class Test extends Application {

                 

                    @GET

                    @Path("/books")

                    public String getBooks() { ... }

                   

                }

                 

                2.)  annotate it with @ApplicationPath or add a servlet-mapping in web.xml

                1 of 1 people found this helpful
                • 5. Re: How to use resteasy on jboss as 7?
                  smtrax

                  Another way to use RestEasy:

                   

                  Without javax.ws.rs.Application....only properties in web.xml

                   

                  <servlet>    

                       <servlet-name>Resteasy</servlet-name>

                       <servlet-class>

                              org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher

                       </servlet-class>

                       <init-param>

                              <param-name>resteasy.servlet.mapping.prefix</param-name>

                              <param-value>/rest</param-value>

                        </init-param>

                        <init-param>

                              <param-name>resteasy.resources</param-name>

                              <param-value>

                                  si.xxxx.sdp.rest.RestSmsService,

                                  si.xxxx.sdp.rest.RestMailService    

                              </param-value>

                          </init-param>

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

                  </servlet>

                   

                  <servlet-mapping>

                          <servlet-name>Resteasy</servlet-name>

                          <url-pattern>/rest/*</url-pattern>

                  </servlet-mapping>

                  1 of 1 people found this helpful
                  • 6. Re: How to use resteasy on jboss as 7?
                    prinzm

                    Should this solution work for JBoss AS 7.1 CR1?

                    Neither the ApplicationPath nor the Path annotation is working for me. I also tried the servlet entry in the web.xml, but without success.

                    I am always getting the same error message: HTTP Status 404 - Could not find resource for relative :...

                    • 7. Re: How to use resteasy on jboss as 7?
                      paulf70

                      I'm having the same issue with 7.1 - REST service doesn't seem to deploy using the ApplicationPath annotation method.  URL returns a 404.  No error on the deploy or the fetch.  Does someone have a working example for 7.1?