1 2 Previous Next 24 Replies Latest reply on Dec 22, 2010 10:26 AM by keurvet

    Seam RESTEasy - not able ti implement

    rakesh.rakesh.yadav.dbydx.com

      Hi All,


      I am trying to use Seam RESTEasy as I need Restful websrvices.
      I am using Jboss-seam 2.1.2, Jboss 5, Eclipse ganymede(3.4).


      I followed the Seam Documentation and tried to Implement but didn't got any success.


      I have imported three libraries to my project's classpath from Jboss-Seam2.1.2/lib. (jboss-seam-resteasy, jaxrs-api, resteasy-jaxrs).


      created the following class



      @Path("/customer")
      
      public class MyCustomerResource {
          @GET
          @Path("/{customerId}")
          @ProduceMime("text/plain")
          public String getCustomer(@PathParam("customerId") int id) {
      
               return ...;
          }
      
      
      }



      After deploying the project I tried calling the webservice by Browser but it says The requested resource () is not available.(404). I am hitting the following URL:


      http://localhost:8080/Restful/seam/resource/rest/customer/123



      I am stuck now.
      Can anyone suggest me what I am missing here..




        • 1. Re: Seam RESTEasy - not able ti implement
          christian.bauer

          You most likely have not configured the Seam resource servlet in web.xml but you should anyway use Seam 2.2.x and look at /examples/restbay.

          • 2. Re: Seam RESTEasy - not able ti implement
            rakesh.rakesh.yadav.dbydx.com

            Hi Christian,


            Thanks for your Quick Response..


            I have created the Project using Eclipse. I found Seam resource Servlet configured in web.xml.




             <servlet>
                <servlet-name>Seam Resource Servlet</servlet-name>
                <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
              </servlet>
            
              <servlet-mapping>
                <servlet-name>Seam Resource Servlet</servlet-name>
                <url-pattern>/seam/resource/*</url-pattern>
              </servlet-mapping>




            Is there any Issue in Seam 2.1x for RESTEasy as you are suggesting for Seam2.2x..


            • 3. Re: Seam RESTEasy - not able ti implement
              rakesh.rakesh.yadav.dbydx.com

              Hi Christian,


              I have tried to use jboss-seam 2.2x as per your suggestion..


              but I am not able to port my aplicaiton from 2.1.2 to 2.2 as Eclipse does not allows to use above 2.1x.


              I renamed the jboss-seam2.2GA folder to jboss-seam2.1.2. Eclipse accepted it with a warning, but the Project is not deployed as it is giving Deployment Exception



              Deployment vfsfile:/E:/jboss-5.1.0.GA/server/default/deploy/rest22-ear.ear/ is in error due to the following reason(s): org.jboss.deployers.spi.DeploymentException: URL file:/E:/jboss-5.1.0.GA/server/default/tmp/5c4oc2j-f5a8nb-g1lwpw47-1-g1lwqag0-w/rest22-ear.ear/rest22.war/ deployment failed




              I have tried some other solutions for running RESTEasy with same seam2.1.2 but nothings is helping..


              can you suggest what should I do now...







               

              • 4. Re: Seam RESTEasy - not able ti implement
                lvdberg

                Hi Rakesh,


                Your included code misses the @Name annotation on the class definition. Maybe that is your problem?


                Seam 2.1.2 works great with RestEasy, don't try it with earlier releases (I mean pre 2.1.2) because the rest-services tend to fail spontaneously after multiple deploys. Basiscally  there is no need to use 2.2.0 (yet..)


                I've included one of my beans to compare:





                public interface ExportRest {
                
                     @GET
                     @Path("/")
                     @Produces("text/xml")
                     public TrafficIncidentOverview export();
                }
                
                


                The TrafficIncidentOverview is a JAXB-annotated class which provides the XML-root for a collection of Incidents:




                @XmlAccessorType(XmlAccessType.FIELD)
                @XmlRootElement(name = "TrafficIncidentOverview")
                public class TrafficIncidentOverview {
                
                    @XmlElement(required = true) 
                     protected List<TrafficIncident> incident = new ArrayList<TrafficIncident>();
                
                    @XmlTransient
                     public List<TrafficIncident> getOverview() {
                          return incident;
                     }
                
                     public void setOverview(List<TrafficIncident> overview) {
                          this.incident = overview;
                     }
                     
                }
                
                


                The request is the simple http://mydomain/MyApplication/seam/resource/rest/export and it streams out a collection of incidents with attributes in XML-format. That's it.



                @Name("exportHandler")
                @AutoCreate
                @Path("/export")
                public class ExportRestHandler implements ExportRest {
                
                     @Logger Log log;
                     @In EntityManager entityManager;
                
                     @Create
                     public void create() {
                          log.info("export-Handler created");
                     }
                     @Destroy
                     public void destroy() {
                          log.info("export-Handler destroyed");
                     }
                
                     @Transactional
                     @Override
                     public TrafficIncidentOverview export() {
                
                          List<TrafficIncident> list = entityManager.createQuery(
                                    "select distinct i from TrafficIncident i "
                                              + " left join fetch i.location.geoPoint l "
                                              + " where i.closureTimestamp is null").getResultList();
                
                          TrafficIncidentOverview view = new TrafficIncidentOverview();
                          view.setOverview(list);
                          return view;
                     }
                
                }




                Hopefully you get it working, because it an amazing tool which saves you a lot of time.


                Success !


                Leo



                • 5. Re: Seam RESTEasy - not able ti implement
                  rakesh.rakesh.yadav.dbydx.com

                  Hi Leo van den Berg,


                  Thanks for your suggestion.


                  I have worked upon your suggestion but still no success.
                  Here is my code.




                  public interface MyCustomerResource 
                  {
                      @GET
                      @Path("/{customerId}")
                      @Produces("text/xml")
                      public String getCustomer(@PathParam("customerId") int id);
                  }





                  @Path("/customer")
                  @Name("customerResource")
                  public class MyCustomerResourceBean implements MyCustomerResource {
                     
                      public String getCustomer(int id) {
                           return "hello";
                      }
                  }



                  But after hitting the URL on Browser http://localhost:8080/Restful/seam/resource/rest/customer/123


                  The response I am getting on Browser is:



                  Could not find resource for relative : /customer/1 of full path: http://localhost:8080/Restful/seam/resource/restv1/customer/1




                  Here I think the server is not able to find Resources


                  Browser is recognizing the path till  /seam/resource/rest but it is not recognizing the Resource name (Customer).


                  Please suggest what may be the Cause..



                  I have not done any XML configurations in web.xml/component.xml.
                  Please let me know if I have to do any .


                  Also if you can specify which Jars are to be included in Project/lib as I have included these three : jboss-seam-resteasy, jaxrs-api, resteasy-jaxrs.





                  Thanks


                  Rakesh






                  • 6. Re: Seam RESTEasy - not able ti implement
                    lvdberg

                    Hi Rakesh,


                    The jars are ok so it should work, what surprises me is that you have a response with an url stating that it can't find the resouce with restv1 in the string. This looks as there is a setting in your components.xml whic causes that.


                    So you can:
                    (1) check if the resource is available under http://localhost:8080/Restful/seam/resource/restv1/customer/1 : notice the change to restv1 and
                    (2) see if the following exists in components.xml:



                    <resteasy:application resource-path-prefix="/restv1" />



                    Nothing to worry, because adding a version number is great for maintenance!






                    • 7. Re: Seam RESTEasy - not able ti implement
                      rakesh.rakesh.yadav.dbydx.com

                      Hi Leo van den Berg,


                      yes I have the entry in my component.xml as I tried it as an option, if it would work.





                      I have tried with http://localhost:8080/Restful/seam/resource/restv1/customer/1. But it gives me the same error.


                      I have tried with default(rest) version and version change(restv1) but none of them works.


                      Please suggest..


                      Thanks


                      Rakesh

                      • 8. Re: Seam RESTEasy - not able ti implement
                        lvdberg

                        Hi Rakesh,


                        Nice puzzle you have...


                        The only thing I see different is the @Produces annotation where you say that it will be text/xml, but you are actually sending text/plain.


                        Try if it reaches the method with some additional debugging. So create a second method with no parameters and a signature of /test (or whatever other name.


                        Add the following simple code to the bean:




                        import org.jboss.seam.annotations.Logger;
                        import org.jboss.seam.log.Log;
                        
                        @Logger Log log;
                        
                        @Create
                        public void create(){
                        log.info("Bean created");
                        }
                        @Destroy
                        public void destroy(){
                        log.info("Bean destroyed");
                        }
                        




                        Now you're able to see if something is happening. When you hit the browser, the bean should be created and it gives you the create message. After that if will give you the reply from the test-method and after that the destroy method.


                        So basically if you get create-message, an error and the destroy message, the bean is ok, but there is something wrong with you mapping.


                        Leo


                        • 9. Re: Seam RESTEasy - not able ti implement
                          lvdberg

                          And additionally, see if the deployed application name is the same as the one you're using in the URL. Just go to the root http://localhost:8080 and you should see and answer from your server. If you have an index-file (or whatever startup html file)  in the root of your application. http://localhost:8080/Restful should give an answer.


                          Leo 

                          • 10. Re: Seam RESTEasy - not able ti implement
                            rakesh.rakesh.yadav.dbydx.com

                            Hi Leo van den Berg,


                            I have changed the text/xml to text/plain.
                            I have also created a test method, but still no success.



                            @GET
                                @Path("/test")
                                @Produces("text/plain")
                                public String test()



                            Added the Logging you specified in the Bean.But the logs doesnot shows any thing after calling the methods on Browser, so it means the Bean is not called up.


                            My Application name is Restful and http://localhost:8080/Restful is working.



                            The Error message is Could not find resource for relative : /customer/123


                            so I think here the Resources are not created which should be created by RESTEasy by picking up the @PATH annotation.


                            please suggest..


                            Thanks


                            Rakesh


                            • 11. Re: Seam RESTEasy - not able ti implement
                              christian.bauer

                              Is there a reason why you do not tell us about or even look at the messages in the log? It's all there: registration of resources on startup, resolving resources during a request, and so on.

                              • 12. Re: Seam RESTEasy - not able ti implement
                                christian.bauer

                                Rakesh Yadav wrote on Nov 04, 2009 16:22:



                                public interface MyCustomerResource 
                                {
                                    @GET
                                    @Path("/{customerId}")
                                    @Produces("text/xml")
                                    public String getCustomer(@PathParam("customerId") int id);
                                }





                                @Path("/customer")
                                @Name("customerResource")
                                public class MyCustomerResourceBean implements MyCustomerResource {
                                   
                                    public String getCustomer(int id) {
                                         return "hello";
                                    }
                                }






                                This is wrong. @Path always goes on the interface, not the implementation class. Read the documentation! Use the log messages!

                                • 13. Re: Seam RESTEasy - not able ti implement
                                  rakesh.rakesh.yadav.dbydx.com

                                  Hi Christian,


                                  I have checked my logs in eclipse's console and Jboss server logs.
                                  These are all I got from there:




                                  17:37:00,604 INFO  [providers] Added built in provider DataSourceProvider
                                  17:37:00,620 INFO  [providers] Added built in provider DefaultTextPlain
                                  17:37:00,620 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.StringTextStar
                                  17:37:00,620 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.InputStreamProvider
                                  17:37:00,636 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.ByteArrayProvider
                                  17:37:00,636 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.FormUrlEncodedProvider
                                  17:37:00,636 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.FormUrlEncodedProvider
                                  17:37:00,651 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.StreamingOutputProvider
                                  17:37:00,729 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.IIOImageProvider
                                  





                                  Also I have tried with @Path annotation in Interface after your suggestion but it didn't work out.


                                  Please suggest..


                                  Thanks


                                  Rakesh





                                  • 14. Re: Seam RESTEasy - not able ti implement
                                    christian.bauer

                                    Enable DEBUG or even TRACE logging for the org.jboss.seam.resteasy category. Use Google first before asking how to do that.

                                    1 2 Previous Next