13 Replies Latest reply on Sep 2, 2009 12:48 AM by tejones

    Seam Generated CRUD application and RESTeasy Integration

    tejones

      I have generated a CRUD web app, and am now trying to integrate RESTeasy. I have followed the blog here: http://in.relation.to/Bloggers/RESTSupportInLatestSeam21 (specifically the section on CRUD Framework Integration), but can't seem to get it to work. Has anyone had any success with this? Is there any other documentation available? The blog also mentioned the API for the integration has not been finalized which is a bit disconcerting. Any thoughts?


      TIA,
      Ted

        • 1. Re: Seam Generated CRUD application and RESTeasy Integration
          christian.bauer

          Have a look at /examples/tasks/ which is a simple CRUD app with a REST interface.

          • 2. Re: Seam Generated CRUD application and RESTeasy Integration
            tejones

            Thanks Christian. Based on the sample, it looks like I need to create resource objects that make use of the generated EntityHome objects in addition to adding the necessary framework and resteasy tags in the components.xml?

            • 3. Re: Seam Generated CRUD application and RESTeasy Integration
              christian.bauer

              I don't know what a resource object is, but if you mean actual Java classes with @Path then no, you don't have to write them if you map an entity class with <framework:resource-*>. Both the /examples/tasks and /examples/restbay show how that works, it's the same as in the blog article.


              Write an entity class, put @Entity on it. Add <framework:entity-home...> and <framework:resource-home...> to your components.xml, done.


              • 4. Re: Seam Generated CRUD application and RESTeasy Integration
                tejones

                Thanks Christian. Now I'm getting this: Could not find MessageBodyWriter for response object of type: java.util.RandomAccessSubList of media type: application/xml trying to get to my resource. Any ideas on what the issue may be?


                Thanks

                • 5. Re: Seam Generated CRUD application and RESTeasy Integration
                  jharting

                  Can you post your components.xml file?

                  • 6. Re: Seam Generated CRUD application and RESTeasy Integration
                    tejones
                    Hi Jozef,

                    The components.xml is as follows:

                    <?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:framework="http://jboss.com/products/seam/framework"
                                    xmlns:resteasy="http://jboss.com/products/seam/resteasy"
                                    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/framework http://jboss.com/products/seam/framework-2.1.xsd
                                     http://jboss.com/products/seam/resteasy http://jboss.com/products/seam/resteasy-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:entity-manager-factory name="entityManagerFactory"
                                          persistence-unit-name="books_demo"/>

                       <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                              entity-manager-factory="#{entityManagerFactory}"/>

                         <!-- <framework:entity-home name="authorHome"
                              entity-class="org.domain.booksdemo.entity.BooksVirtual.books.authors" auto-create="true" />

                         <framework:entity-query name="authorsQuery"
                              ejbql="select a from Authors a">
                         </framework:entity-query> -->
                         
                         <resteasy:resource-home path="/author" name="resourceAuthorHome"
                                            entity-home="#{authorsHome}" entity-id-class="java.lang.Long"
                                            media-types="application/xml application/json"/>

                         <resteasy:resource-query name="authorsResourceQuery"
                              entity-query="#{authorsQuery}" path="/author"
                              entity-class="org.domain.booksdemo.entity.BooksVirtual.books.authors"
                              media-types="application/html"/>

                         <resteasy:application resource-path-prefix="/teiid">
                         <!--      <resteasy:media-type-mappings>
                                   <key>xml</key>
                                   <value>application/xml</value>
                              </resteasy:media-type-mappings> -->
                         </resteasy:application>

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

                    Thanks,
                    Ted
                    • 7. Re: Seam Generated CRUD application and RESTeasy Integration
                      tejones
                      I was mucking with the media-types in the resource-query node. It is actually:

                      <resteasy:resource-query name="authorsResourceQuery"
                        entity-query="#{authorsQuery}" path="/author"
                        entity-class="org.domain.booksdemo.entity.BooksVirtual.books.authors"
                        media-types="application/xml application/json"/>

                      not  <resteasy:resource-query name="authorsResourceQuery"
                        entity-query="#{authorsQuery}" path="/author"
                        entity-class="org.domain.booksdemo.entity.BooksVirtual.books.authors"
                        media-types="application/html"/>
                      • 8. Re: Seam Generated CRUD application and RESTeasy Integration
                        jharting

                        Ted, I find the way you specified entity-class attribute quite confusing. Looks like you are trying to use it in similar way EL is often used however this will not work. The attribute is used to get type information only. You must use the full name of the class like org.domain.booksdemo.entity.Author without going any further.

                        • 9. Re: Seam Generated CRUD application and RESTeasy Integration
                          tejones

                          That is how the class was generated. I used the Generate SEAM Components option of JBoss Tools. It is the fully qualified name of the entity.

                          • 10. Re: Seam Generated CRUD application and RESTeasy Integration
                            tejones
                            Ok... got further. I was apparently missing some jars. Now I am getting the follwoing:

                            15:31:15,230 INFO  [STDOUT] Hibernate:
                                select
                                    authors0_.AUTHOR_ID as AUTHOR1_1_,
                                    authors0_.FIRSTNAME as FIRSTNAME1_,
                                    authors0_.LASTNAME as LASTNAME1_,
                                    authors0_.MIDDLEINIT as MIDDLEINIT1_
                                from
                                    Books.BooksVirtual.BOOKS.AUTHORS authors0_ limit ?
                            15:31:17,431 ERROR [STDERR] 32585 [http-127.0.0.1-8080-1] ERROR org.jboss.resteasy.core.SynchronousDispatcher - Failed executing GET /author
                            15:31:17,431 ERROR [STDERR] org.jboss.resteasy.spi.LoggableFailure: javax.xml.bind.MarshalException
                            - with linked exception:
                            [com.sun.istack.SAXException2: unable to marshal type "org.domain.booksdemo.entity.BooksVirtual.books.authors" as an element because it is missing an @XmlRootElement annotation]
                            • 11. Re: Seam Generated CRUD application and RESTeasy Integration
                              jharting

                              You will need to put @XmlRootElement on every entity you want to transfer.

                              • 12. Re: Seam Generated CRUD application and RESTeasy Integration
                                tejones
                                Thanks... I have tried that. Now getting:

                                HTTP Status 500 - javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: org.domain.abcbooks.entity.BooksVirtual.books.authors@1642565 -> org.domain.abcbooks.entity.BooksVirtual.books.books@1b79d4f -> org.domain.abcbooks.entity.BooksVirtual.books.authors@1642565]

                                I have tried a varied combination of annotations to resolve this per the many threads I have come across, but no luck yet. Do you know of a workaround for this Jozef?

                                Thanks!
                                • 13. Re: Seam Generated CRUD application and RESTeasy Integration
                                  tejones

                                  FYI - I was able to resolve the cycle by adding @XmlTransient to my getters for fields with a @ManyToOne relationship.