6

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?

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
JavaGeek
  • 161
  • 1
  • 1
  • 6

3 Answers3

6

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;
rodrigo.botti
  • 268
  • 1
  • 4
  • 9
  • Note that the remote host, port and user info have to be defined via a properties file for this to work. Place a `jboss-ejb-client.properties` file under your root source folder. An example for such a file is here: https://github.com/akquinet/jbosscc-wildfly-examples/blob/master/ejb-remote-example/ejb-remote-example-ejb-client/src/main/resources/jboss-ejb-client.properties – gmazlami Sep 21 '17 at 10:51
1

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

Ravi Trivedi
  • 2,340
  • 2
  • 14
  • 20
  • Many application servers support the use of the `@EJB` annotation to target remote beans, including JBoss (as per rodrigo's answer), and Glassfish. – DavidS Sep 30 '15 at 22:21
  • But Rodrigo's answer doesn't show where to define the IP address of the server which is deploying the remote EJB. – Farah Dec 23 '15 at 19:00
  • @Farah: You define the IP address of the server via a properties file. In case of Jboss, you place a `jboss-ejb-client.properties` in your source root folder. For an example, see: https://github.com/akquinet/jbosscc-wildfly-examples/blob/master/ejb-remote-example/ejb-remote-example-ejb-client/src/main/resources/jboss-ejb-client.properties – gmazlami Sep 21 '17 at 10:50
1

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

Sudhakar
  • 4,823
  • 2
  • 35
  • 42
  • It's sounds perfectly but when I invoke the remote service I get no response and no error ever... The only way it worked was through lookup using Abstract Factory. – Henrique Fernandes Cipriano Dec 05 '17 at 00:31
  • With the example: `Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory"); props.setProperty("org.omg.CORBA.ORBInitialHost", "server.com"); props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); try { InitialContext ctx = new InitialContext(props); return (RemoteService) ctx.lookup("com.server.package.RemoteService"); } catch (NamingException e) { ...; }` – Henrique Fernandes Cipriano Dec 05 '17 at 00:37