views:

470

answers:

2

Hello,

I am using Seam with JBoss AS. In my application I have a SLSB which is also declared as a seam component using the @Name annotation. I am trying to inject and use this SLSB in another seam component using the @In annotation.

My problem is that sometimes Seam injects the local interface (then the code runs fine) and sometimes seam injects the remote interface (then there is an error in execution of the code). I have tried doing all the things specified on this link: http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/configuration.html#config.integration.ejb.container

The SeamInterceptor is configured,
I have specified the jndi pattern in components.xml file ( < core:init debug="true" jndi-pattern="earName/#{ejbName}/local"/> ),
I have also tried using the @JndiName("earName/ejbName/local") annotation for every SLSB,
I have tried setting this property ( org.jboss.seam.core.init.jndiPattern=earName/#{ejbName}/local ) in the seam.properties file.
I have also tried putting the text below in web.xml file

<context-param>
    <param-name>org.jboss.seam.core.init.jndiPattern</param-name>
    <param-value>earName/#{ejbName}/local</param-value>
</context-param>  

Even after doing all the above mentioned things, the seam still injects the remote interface sometimes. Am I missing something here? Can anyone tell me how to resolve this issue and tell seam to always inject the local interface?

My components.xml file looks like:

<?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"&gt;
  <core:init debug="true" jndi-pattern="myEarName/#{ejbName}/local"/>
  <core:manager concurrent-request-timeout="500"
             conversation-timeout="120000"
             conversation-id-parameter="cid"
             parent-conversation-id-parameter="pid"/>
  <web:hot-deploy-filter url-pattern="*.seam"/>
  <persistence:managed-persistence-context name="entityManager" auto-create="true"
                  persistence-unit-jndi-name="@puJndiName@"/>
  <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>
  <component name="org.jboss.seam.core.init">
     <property name="jndiPattern">myEarName/#{ejbName}/local</property>
  </component>
</components>

And my EJB component looks like:


@Stateless
@Name("myEJBComponent")
@AutoCreate
public class MyEJBComponentImpl implements MyEJBComponentRemote, MyEJBComponentLocal {

    public void doSomething() {

    }

}


+4  A: 

I suppose the following one

 public interface MyStateless {

     void doSomething();         

 }

 /**
   * Be aware you CAN NOT USE @Local and @Remote at the same time
   */

 @Local
 public interface MyStatelessLocal extends MyStateless {}

 @Remote
 public interface MyStatelessRemote extends MyStateless {}

Your Stateless should looks like

 /**
   * Global JNDI address will be earName/MyStatelessImpl/local and earName/MyStatelessImpl/remote
   */
 @Stateless
 @Name("myStateless")
 public class MyStatelessImpl implements MyStatelessLocal, MyStatelessRemote {

     public void doSomething() {

     }

 }

Inside your Seam component

 @Name("otherSeamComponent")
 public class OtherSeamComponent {

     /**
       * Seam will lookup a Seam Component by field name - myStateless
       *
       * Notice i am using the local interface
       */
     private @In MyStatelessLocal myStateless;

 }
Arthur Ronald F D Garcia
Arthur, Thank you for the detailed response, but I am exactly doing the same thing you have mentioned, still I am facing the issue.
Harshad Vyawahare
@Harshad V So i need you show how your app looks like: */WEB-INF/components.xml*, your EJB component, See http://stackoverflow.com/questions/2453746/jboss-seam-enabling-debug-page-on-weblogic-10-3-2-11g/2459795#2459795 how your app should looks like. Which App server do you use ?
Arthur Ronald F D Garcia
@Arthur Ronald F D Garcia : I am using JBoss 5.1.0.GA App server. I checked the link you had provided, my app looks like the one specified on the link, except there is no lib folder in myapp-ejb.jar folder and the lib folder in myapp-war.war folder is inside the WEB-INF folder, i.e. myapp-war.war\WEB-INF\lib . I have edited my question above and added my components.xml and EJB component.
Harshad Vyawahare
very helpful, thanks
stacker
A: 

@Arthur Ronald F D Garcia : My bad, I ignored a small part of the answer you posted above.

In my application I had MyStatelessLocal and MyStatelessRemote interfaces, but did not have the MyStateless parent interface. I had added the abstract methods in both, local and remote interfaces, and they were not empty.

When I created a MyStateless parent interface, moved the abstract methods from the local and remote interface to the parent interface (so that the local and remote interfaces are empty), the error got resolved, and now my application is working fine!

Thank you very much for your help!

--Harshad Vyawahare.

Harshad Vyawahare