1 Reply Latest reply on Dec 6, 2013 4:34 AM by mgvanbochove

    Can't get Seam to Inject objects into a REST interface

    mstockbr

      I'm developing an application on JBoss7 with Seam 2.3. I've got a REST interface that I'm trying to inject a stateless object into. Unfortunately, despite trying to inject it, and several other things (entitymanager, logger, etc...) absolutely nothing is being injected.

      I've followed the instructions here:

      Chapter 25. Web Services

      For setting up restful web services. My code looks pretty much like the 25.4.2 example. Breaking during a method call to the interface reveals that all objects supposed to be handled by Seam are null (even those marked with create=true). So it appears that Seam is in fact not doing anything with annotated objects in the REST interface.

       

      Interface for the REST interface:

      @Local
      @Remote
      @Path("/dispatch")
      public interface DispatchDirectiveREST {
          
          @GET
          @Path("/example/dispatch-directive.rest")
          @Produces("application/xml")
          public DirectiveRequestType example();
          
          @POST
          @Path("/dispatch-directive.rest")
          @Consumes({"application/xml","application/json"})
          @Produces("text/plain")
          public String dispatch(DirectiveRequestType request
      

      );

       

      Implementation (head only) of the REST interface:

      @Scope(ScopeType.STATELESS)
      @Name("DispatchDirectiveRESTBean")
      public class DispatchDirectiveRESTBean implements DispatchDirectiveREST, Serializable {
          private static final long serialVersionUID = -2994172323883717503L;
          
          @In(create = true) private CreateDirectiveAsync createDirectiveAsync;
          @In(create = true) private CreateDirectiveAysncBean createDirectiveAsyncBean;
          @In private EntityManager entityManager;
          @Logger private Log logger;
      

       

      Application defining the REST junk:

      @ApplicationPath("/rest")
      public class RESTProvider extends Application {
          
          private final static Class<?>[] interfaces = new Class<?>[]{
              DispatchDirectiveRESTBean.class,
              DispatchDirectiveREST2.class
          };
          
          public Set<Class<?>> getClasses() {
              return new HashSet<Class<?>>(Arrays.asList(interfaces));
          }
      


      Interface defining the CreateDirectiveAsync object (what I actually want to inject):

      @Local
      public interface CreateDirectiveAsync extends IAsyncTask<DirectiveSeamEntity,Long>{
      
          @Override
          @Asynchronous
          public Long performTask(DirectiveSeamEntity input, @Expiration Date time);
      

       

      Implementation of the interface:

      @Scope(ScopeType.STATELESS)
      @Name("createDirectiveAsyncBean")
      public class CreateDirectiveAysncBean implements CreateDirectiveAsync {
      
          @Logger private Log log;
          @In private StatusMessages statusMessages;
          @In private EntityManager manager;
          
          @Override
          @Asynchronous
          public Long performTask(DirectiveSeamEntity input, @Expiration Date time) {
      

       

      Components.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.org/schema/seam/components"
                  xmlns:core="http://jboss.org/schema/seam/core"
                  xmlns:persistence="http://jboss.org/schema/seam/persistence"
                  xmlns:drools="http://jboss.org/schema/seam/drools"
                  xmlns:bpm="http://jboss.org/schema/seam/bpm"
                  xmlns:security="http://jboss.org/schema/seam/security"
                  xmlns:mail="http://jboss.org/schema/seam/mail"
                  xmlns:web="http://jboss.org/schema/seam/web"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:async="http://jboss.org/schema/seam/async"
                  xsi:schemaLocation=
                      "http://jboss.org/schema/seam/core http://jboss.org/schema/seam/core-2.3.xsd
                       http://jboss.org/schema/seam/persistence http://jboss.org/schema/seam/persistence-2.3.xsd
                       http://jboss.org/schema/seam/drools http://jboss.org/schema/seam/drools-2.3.xsd
                       http://jboss.org/schema/seam/bpm http://jboss.org/schema/seam/bpm-2.3.xsd
                       http://jboss.org/schema/seam/security http://jboss.org/schema/seam/security-2.3.xsd
                       http://jboss.org/schema/seam/mail http://jboss.org/schema/seam/mail-2.3.xsd
                       http://jboss.org/schema/seam/web http://jboss.org/schema/seam/web-2.3.xsd
                       http://jboss.org/schema/seam/components http://jboss.org/schema/seam/components-2.3.xsd
                       http://jboss.org/schema/seam/async http://jboss.org/schema/seam/async-2.3.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:/RnDServerEntityManagerFactory"/>
      
         <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>
      
         <!-- This is supposed to be the prefered way of setting up async. It doesn't work. -->
         <!-- The line following it fixes the issue. -->
         <!-- <async:timer-service-dispatcher/> -->
         <component class="org.jboss.seam.async.TimerServiceDispatcher" jndi-name="java:app/jboss-seam/TimerServiceDispatcher"/>
         
         <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>
      

       

      Web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app 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"
                  version="3.0">
        <display-name>RnDServer</display-name>
        <welcome-file-list>
          <welcome-file>index.html</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>
          <url-pattern>*.html</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>/rest/*</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>
      

       

      Any help would be appreciated! Thank you in advance for people who look at this!