1 2 Previous Next 24 Replies Latest reply on Dec 22, 2010 10:26 AM by keurvet Go to original post
      • 15. Re: Seam RESTEasy - not able ti implement
        rakesh.rakesh.yadav.dbydx.com

        Hi Christian,


        I really appreciate your suggestions.


        I am stuck here for two days and I have googled a lot and tried many suggestion from there but I think there is something really silly going on, which I am not able to Identify.


        Also I have checked whole logs for seameasy, nothing else found there.


        I cannot debug here as the URL is not even getting called(404 Error).


        Is there any Alternative which I can try as I am getting exhausted with SeamEasy.


        Thanks


        Rakesh

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

          Hi Rakesh,


          I can understand your frustration, it can sometimes be overwhelming!


          As mentioned before. The trick is in testing thoroughly what you're doing. As far I can see, your bean should work.Because I can't see what you have installed and configured it is difficult to give more advice! It's really working for me, So I  would suggest the following:


          - Be sure you have the correct libs; if you're not 100% : download the whole seam 2.1.2 package and get the jars from the lib sub-directory.
          - Create an new project and add  ONLY your specific RestEasy bean (and interface)
          - check if the web.xml is configured as needed (filter and the resource servlet)






          <filter>
               <filter-name>Seam Filter</filter-name>
               <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
               </filter>
               <filter-mapping>
                    <filter-name>Seam Filter</filter-name>
                    <url-pattern>*.faces</url-pattern> 
               </filter-mapping>
          
               <listener>
                    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
               </listener>
          
               <servlet>
                    <servlet-name>Seam Resource Servlet</servlet-name>
                    <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
               </servlet>
          
               <servlet-mapping>
                    <servlet-name>Faces Servlet</servlet-name>
                    <url-pattern>*.faces</url-pattern>
               </servlet-mapping>
          
               <servlet-mapping>
                    <servlet-name>Seam Resource Servlet</servlet-name>
                    <url-pattern>/seam/resource/*</url-pattern>
               </servlet-mapping>
          
          
          
          // Be aware that I am using a url-pattern of *.faces, yours may be different fi *.seam or something.
          




          - check your components.xml
          - check if there is a seam.properties file at the root of your classpath (may be empty)
          - remove ALL other applications (EARS, WARS etc.)
          - put the debug level for logging in the config-file of jboss to TRACE for the specific category


          In my JBOSS configuration (5.1) under the default/conf directory you will find a file jboss-log4j.xml and add the following category:




          <category name="org.jboss.seam">
                <priority value="DEBUG"/>
          </category>
          



          Be aware that you will get VERY MUCH detailed log info now !!



          - Try again and see if only this simple bean will work.




          Keep trying, it's worth the effort.




          Leo

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

            Hi Leo van den Berg,


            Thanks for your response !





            • I downloaded fresh seam2.1.2




            • Deleted all old projects from Eclipse and Jboss/Default/deploy folder (ear/war).




            • Created a new Seam Web Project named seamTest in eclipse using Jboss-tools plugin.






            • Copied my Interface and Bean in the seamTest-ejb.




            • Copied three jars files from Seam 2.1.2/libs to seamTest/web component/web-INF/lib (jboss-seam-resteasy, jaxrs-api, resteasy-jaxrs).




            • Enabled debug logs in jboss-log4j.xml.



            I tried these two URLs for both methods defined:


            http://localhost:8080/seamTest/seam/resource/rest/customer/test


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


            Result was same : Http 404, Could not find resource for relative : /customer/123



            • Didn't get anything from logs.





            I then removed my Interface and Bean from seamTest-ejb to seamTest/src, here also result was same.




            Here is my Code :


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





            @Name("customerResource")
            public class MyCustomerResourceBean implements MyCustomerResource {
               
                public String getCustomer(int id) {
                     System.out.println("*******getCustomerService called");
                     return "hello";
                }
                
                public String test() {
                     System.out.println("*******test Service called");
                      return "Test Success";
                 }
            
            
                @Logger Log log;
            
                @Create
                public void create(){
                log.info("Bean created");
                }
                @Destroy
                public void destroy(){
                log.info("Bean destroyed");
                }
                 
            }






            web.xml


            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
              <display-name>seamTest</display-name>
              <welcome-file-list>
                <welcome-file>index.html</welcome-file>
                <welcome-file>index.htm</welcome-file>
                <welcome-file>index.jsp</welcome-file>
                <welcome-file>default.html</welcome-file>
                <welcome-file>default.htm</welcome-file>
                <welcome-file>default.jsp</welcome-file>
              </welcome-file-list>
              <servlet>
                <servlet-name>Faces Servlet</servlet-name>
                <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                <load-on-startup>1</load-on-startup>
              </servlet>
              <servlet-mapping>
                <servlet-name>Faces Servlet</servlet-name>
                <url-pattern>*.seam</url-pattern>
              </servlet-mapping>
              <context-param>
                <param-name>org.richfaces.SKIN</param-name>
                <param-value>blueSky</param-value>
              </context-param>
              <listener>
                <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
              </listener>
              <filter>
                <filter-name>Seam Filter</filter-name>
                <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
              </filter>
              <filter-mapping>
                <filter-name>Seam Filter</filter-name>
                <url-pattern>/*</url-pattern>
              </filter-mapping>
              <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>
              <context-param>
                <param-name>facelets.DEVELOPMENT</param-name>
                <param-value>true</param-value>
              </context-param>
              <context-param>
                <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                <param-value>.xhtml</param-value>
              </context-param>
              <security-constraint>
                <display-name>Restrict raw XHTML Documents</display-name>
                <web-resource-collection>
                  <web-resource-name>XHTML</web-resource-name>
                  <url-pattern>*.xhtml</url-pattern>
                </web-resource-collection>
                <auth-constraint/>
              </security-constraint>
            </web-app>





            Component.xml


            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
                        xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:drools="http://jboss.com/products/seam/drools"
                        xmlns:bpm="http://jboss.com/products/seam/bpm"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:mail="http://jboss.com/products/seam/mail"
                        xmlns:web="http://jboss.com/products/seam/web"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation=
                            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                             http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd
                             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
            
               <core:init debug="true" jndi-pattern="@jndiPattern@"/>
            
               <core:manager concurrent-request-timeout="500"
                             conversation-timeout="120000"
                             conversation-id-parameter="cid"
                             parent-conversation-id-parameter="pid"/>
            
               <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
               <web:hot-deploy-filter url-pattern="*.seam"/>
            
               <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                  persistence-unit-jndi-name="java:/seamTestEntityManagerFactory"/>
            
               <drools:rule-base name="securityRules">
                  <drools:rule-files>
                     <value>/security.drl</value>
                  </drools:rule-files>
               </drools:rule-base>
            
               <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
            
               <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
            
               <event type="org.jboss.seam.security.notLoggedIn">
                  <action execute="#{redirect.captureCurrentView}"/>
               </event>
               <event type="org.jboss.seam.security.loginSuccessful">
                  <action execute="#{redirect.returnToCapturedView}"/>
               </event>
            
               <mail:mail-session host="localhost" port="25"/>
            
               <!-- For use with jBPM pageflow or process management -->
               <!--
               <bpm:jbpm>
                  <bpm:process-definitions></bpm:process-definitions>
                  <bpm:pageflow-definitions></bpm:pageflow-definitions>
               </bpm:jbpm>
               -->
            
            </components>
            



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

              Hi Rakesh,


              are you sing Seam-Gen to build the project ?


              Leo

              • 19. Re: Seam RESTEasy - not able ti implement
                lvdberg
                Hi Rakesh,

                I ask this bvecause I normally develop with a combination of MAVEN and JBOSS-TOOLS. My rest-easy beans should be in the ejb directory because they ARE DEPLOYED AS NORMAL poj, hence they should be in that specific directory. Having a ejb- dir, means that you're developing an EAR project while a simple rest-easy should be in a WAR-file (if you're not using EJB3 I mean.) And as an EAR, you should have your bean included in the classes dir of the WAR-part of the EAR (I know it sounds complex, but look up the directory structure of seam-projects in the documentation)

                To be absolutely sure, check the EAR or deployed dir under the deploy directory and check the structure. You should have the rest-beans somewhere in a package. If you have a META-INF dir or WEB_INF dir, the seam.properties file should be at the root (META_INF) or in the clases sub-dir in case of the WEB_INF. If it is a compresed file (with the extension ear or war) use an unzipper to look into the file (7-Zip recognizes all formats)

                It is really, really important that you understand the structure of java enterprise applications. Try some example applications of the SEAM-distro and build them and see what it produces and compare them with you own projest.

                Leo


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

                  Hi Leo,


                  I have installed JBoss-Tools Plugin in Eclipse, using it I have created a Seam EAR project as I have to use EJB 3.0.


                  There are 4 projects created by the wizard seamTest, seamTest-ear, seamTest-ejb and seamTest-test.



                  • First I created the rest-beans in ejb folder ie. seamTest-ejb/ejbmodule, with my other ejbs.



                  After deploy I found class file of rest-beans(Interface and Bean) in  Jboss/server/default/deploy/seamTest-ear.ear/seamTest-ejb.jar



                  • The rest url was not called up this way so I deleted the rest-beans from seamTest-ejb/ejbmodule and pasted them to seamTest/src



                  After deploy I found the class file of rest-beans in ../seamTest-ear.ear/seamTest.war/WEB-INF/classes


                  Rest URLs were not called up this way either.


                  The seam.properties is present in ../seamTest-ear.ear/seamTest-ejb.jar, also Meta-INF is there.




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

                    Hi Rakesh,


                    Try to take small steps first. You definitely have a configuration problem and - although being a great tool - SeamTools (or Seam-gen) does make things very transparent; all configuration is done automatically, so one different step and things get difficult.


                    I understand nor that you need to use restEasy in combination with EJB's which makes it just a bit more complex, especially testing the application. JBoss-tools doesn't have boilerplate code to kick-start web-services....


                    Just take the first important hurdle and make the RestEasy service work. So my advice is not to complicate stuff at the very beginning and start implementing it as a simple Web-application which just prints a Hello World string. And at the moment you have that working you add the less problematic stuff. Do NOT cut and paste code between projects, as you state because Eclipse needs to clean the target directory and rebuild the classes to be effective.


                    This basically means a tiny project with one RestBean which injects the Logger and prints, no other fancy stuff at all. Add a simple seam-jsf  page to see if seam works as expected. Some simple code with a


                     <h:outputText value"#{someTest EL} ">



                    to see if it works.


                    Now for the server part. I am presuming that you're using JBOSS, and because of your choice for EJB, it is possibly JBOSS 5.x.
                    Download a clean version of the Appserver !


                    Triple check your cionfiguration, the simplest is seeing if it returns the home page after ebntering http//localhost:8080/ After that try your application with http://localhost:8080/WhateverIsYourApplicationName/test.seam


                    Set the log level as adviced before. At the moment you deploy the application check the log and see if the (rest) component is recognized/loaded.


                    Test the rest app.


                    If that doesn't work either, you probably have chosen the wrong job ;-)


                    I had some problems, but again , try to understand the fundamentals. I don't know if you've worked with EJB, JSF/Facelets and webservices before, but i estimate that you need to have between a half-year and a year experience in these areas before diving into Seam.



                    Keep me informed !


                    Leo


                       

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

                      Hi Leo,


                      I am working with seam/ejb/webservices for last 3 months, so you are more or less correct that I need some more experience on these stuffs.


                      In past three months I worked on a small Seam project(EAR), the Project is almost finished with all modules done using JSF, JPA(hibernate) and EJB3.0.


                      Now I have to add the Rest Web Services to the project. I have Implemented SOAP with seam, it worked like a charm after reading the same seam official reference document, but my strict requirement is Restful now..


                      I have tried a WAR project now with fresh Jboss 5.x. with just my resource bean and no EJB.


                      http://localhost:8080/projectname is working with default page shown, but the Rest URL is giving same error Could not find resource for relative . There is something really silly going on that is not caught by me.


                      Now, I am thinking on Option to implement my own Http servlet, handle the specific URLs request with my servlet and return response.


                      In logs(Debug enabled) I just found these entries relevent on startup.




                      15:19:45,927 INFO  [providers] Added built in provider DataSourceProvider
                      15:19:45,942 INFO  [providers] Added built in provider DefaultTextPlain
                      15:19:45,942 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.StringTextStar
                      15:19:45,942 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.InputStreamProvider
                      15:19:45,958 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.ByteArrayProvider
                      15:19:45,958 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.FormUrlEncodedProvider
                      15:19:45,958 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.FormUrlEncodedProvider
                      15:19:45,958 INFO  [providers] Added built in provider org.jboss.resteasy.plugins.providers.StreamingOutputProvider
                      15:19:45,958 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlSeeAlsoProvider
                      15:19:45,989 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlRootElementProvider
                      15:19:46,005 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.JAXBElementProvider
                      15:19:46,005 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlTypeProvider
                      15:19:46,005 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.CollectionProvider
                      15:19:46,020 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.json.JsonCollectionProvider
                      15:19:46,020 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.MapProvider
                      15:19:46,020 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.json.JsonMapProvider
                      15:19:46,036 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.XmlJAXBContextFinder
                      15:19:46,895 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.atom.AtomFeedProvider
                      15:19:46,910 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.atom.AtomEntryProvider
                      15:19:46,910 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.IIOImageProvider
                      15:19:46,926 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.json.JsonJAXBContextFinder
                      15:19:46,941 INFO  [providers] Adding built in provider org.jboss.resteasy.plugins.providers.jaxb.fastinfoset.FastinfoSetJAXBContextFinder






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

                        Hi Rakesh,


                        I know, sometimes very frustrating. I think the Servlet is a good idea, but more from the viewpoint of seeing of everything works fine. What still surprises me is that not even the bean is created. Which normally happens when you accees the URL without getting to the right path (only /customer)


                        There is really something wrong with your configuration which hinders the access to the bean. I am not using Eclipse-baaed deploys, and use a pre-configured JBOSS server to get rid of the lib-problems.


                        As stated I really like the JBOSS-tools, but at the moment you need to do something which is Wizardized, things don't work as expected.


                        Success,


                        Leo



                        • 24. Re: Seam RESTEasy - not able ti implement
                          keurvet

                          Hi, this discussion is old, so I think that you have found a solution for your problem (I hope so ! :) ). Just for those as I who encounter the same problem, I found the solution from this discussion : http://seamframework.org/Community/ProblemWithRESTeasy . The way we dispatch the jars between the ear and the war archives is very sensitive. Hope it helps.

                          1 2 Previous Next