How do I tell Seam to enter the local EJB interface (SLSB) and not the remote EJB interface (SLSB)?
I am using Seam with JBoss AS. In my application, I have an SLSB that is also declared as a seam component using the @Name annotation. I am trying to implement and use this SLSB in another seam component using @In annotation.
My problem is that sometimes Seam enters the local interface (then the code works fine) and sometimes the seam enters the remote interface (then there is an error while executing the code). I tried doing everything in this link: http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/configuration.html#config.integration.ejb.container
Setting up the SeamInterceptor,
I specified the jndi pattern in the components.xml file (<core: init debug = "true" jndi-pattern = "earName / # {ejbName} / local" / ">),
I also tried using the @JndiName annotation (" earName / ejbName / local ") for each SLSB,
I tried to set this property (org.jboss.seam.core.init.jndiPattern = earName / # {ejbName} / local) in the seam.properties file.
I also tried to put the text below to 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 of the above things, the seam still enters the remote interface sometimes. Am I missing something? Can anyone tell me how to solve this problem and tell me that seam always inserts the local interface?
My components.xml file looks like this:
<?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="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 this:
@Stateless
@Name("myEJBComponent")
@AutoCreate
public class MyEJBComponentImpl implements MyEJBComponentRemote, MyEJBComponentLocal {
public void doSomething() {
}
}
a source to share
I believe the next
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 person should look 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;
}
a source to share
@Arthur Ronald FD Garcia: Bad, I ignored a small part of the answer you posted above.
In my application, I had the MyStatelessLocal and MyStatelessRemote interfaces, but I did not have the MyStateless parent interface. I added abstract methods on both local and remote interfaces and they weren't empty.
When I created the parent interface MyStateless, moved the abstract methods from the local and remote interface to the parent interface (so the local and remote interfaces are empty), the error was resolved and now my application works fine!
Thank you very much for your help!
- Harshad Vyavahare.
a source to share