Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote lookup using @ejb annotation

Tags:

java

ejb

I have 2 servers instances of Jboss 5, each of which is deployed with two EAR's. Say Client.Ear and Server.Ear. Server Ear expose some ejb's. I want to inject this to ClientEar via annotation. Using JNDI lookup i did it fine and it works. But using annotation i always get javax.naming.NamingException. However when injecting session beans accross deployment artifacts the global JNDI name has to be used for injection and i used that also like @EJB(mappedName ="java:global/Server/component/ApplicationService!com.test.server.ApplicationServiceInterface")

But it seems like I am not providing the provider_url of the remote server to bound it to the client ear instance. How could i configure jndi properties, ie provider_url, initial context properites with the annotation @ EJB?

like image 600
JavaGeek Avatar asked May 13 '13 05:05

JavaGeek


People also ask

How does EJB lookup work?

The actual home lookup name is determined by the application's deployment descriptors. The enterprise bean (EJB) resides in an EJB container, which provides an interface between the bean and the application server on which it resides.

How do I access EJB from standalone application?

In your client code, instantiate the InitialContext: InitialContext ctx = new InitialContext(); It is not necessary to explicitly instantiate a naming context that points to the CosNaming service.

What is remote EJB?

javax.ejbDeclares the remote business interface(s) for a session bean. The Remote annotation is applied to the session bean class or remote business interface to designate a remote business interface of the bean.


3 Answers

I found a forum post that answers your question: https://community.jboss.org/thread/228789

In it he refers to https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance

And to accomplish the jndi lookup with the @EJB annotaion he uses

@EJB(lookup = "ejb:earname/modulename/BeanClass!fully.qualified.RemoteInterface")
private RemoteInterface bean;
like image 167
rodrigo.botti Avatar answered Oct 13 '22 00:10

rodrigo.botti


@EJB annotation can only be used if the applications are deployed in the same sever instance. @EJB annotation won't work if you are trying to make cross server instance call or remote server call. So, in your case, annotation injection won't work.

So, what are the solutions ?

Option 1) Use old style programmatic JNDI look up

Option 2) Create managed bean as per CDI (Context Dependency Injection) and configure all the JNDI properties there. And @inject the managed bean into your client.

like image 33
Ravi Trivedi Avatar answered Oct 12 '22 23:10

Ravi Trivedi


I know this little too late . Including this for further reference

You can use the portable look up String format EJBs use RMI over IIOP and has standard mapping EJB architecture to CORBA So you can lookup by server host and portnumber by

@EJB(lookup = "corbaname:iiop:example.com:3701#java:global/mycrud/mycrud-dss-ejb/InformeBean!com.myorg.ejb.InformeRemote")

References: https://docs.oracle.com/javase/8/docs/technotes/guides/idl/corba.html https://docs.oracle.com/javase/8/docs/technotes/guides/idl/INStutorial.html

like image 21
Sudhakar Avatar answered Oct 13 '22 00:10

Sudhakar