I am trying to invoke a stateless EJB, deployed on a remote server. I can invoke the bean from my local JBoss environment but when I change the remote.connection.default.host
to the remote machine's host, my client code does not work.
This is my jboss-ejb-client.properties
:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=SERVERIP/HOSTNAME
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=username
remote.connection.default.password=Password
And my client code looks like this:
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
String jndi = "jndi_name";
Context context = new InitialContext(properties);
obj = context.lookup(jndi);
Please help.
Thanks all. Jack.
When you call a server-side EJB from a client application, you must use a network protocol that involves an ORB, such as RMI over IIOP. However, calling out from the servlet to an external object that is in the same session as the servlet can be much simpler and faster than calling from a client.
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.
This answer may be late but I faced the same problem, none of the above answers helped me, to solve this problem, refer the following : http://blog.jonasbandi.net/2013/08/jboss-remote-ejb-invocation-unexpected.html
The code that works for me is as below:
Properties jndiProperties=new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080/");
//This property is important for remote resolving
jndiProperties.put("jboss.naming.client.ejb.context", true);
//This propert is not important for remote resolving
jndiProperties.put("org.jboss.ejb.client.scoped.context", "true");
Context context=new InitialContext(jndiProperties);
/*
java:global/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
java:app/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
java:module/GenericStateless!test.stateless.GenericStateless
java:jboss/exported/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
java:global/JEETest_Project/EJBTest_Project/GenericStateless
java:app/EJBTest_Project/GenericStateless
java:module/GenericStateless
*/
//None of the above names work for remote EJb resolution ONLY THIS WORKS -
//"/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless"
GenericStateless bean=(GenericStateless)context.lookup("/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless");
//GenericStateless bean=(GenericStateless)c.lookup("GenericStateless!test.stateless.GenericStateless");
System.out.println(bean.getInt());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With