Jboss 7.1 EJB remote-naming lookup (w/ jndi) and no application realm security
mr.elusiv Jun 20, 2013 8:19 AMHi, although I visit these forums from time to time, this is my first post.
We are currently migrating an app from Jboss 5 --> Jboss 7 and would like to avoid CDI until we have stabilized our current application.
What we do not want at this time:
- ejb-client.properties
- application security (as we are running other security layers and routing)
- ejb client api usage (we only want JNDI)
What I am trying to do:
- Dynamically make calls to various Jboss App servers via programmatically set properties
- Lookup a Stateful EJB on local OR remote server with a Pojo client application via Jndi and jboss-remote-naming (NOT ejb client API)
- Remove all application-realm security, by stripping out the application-realm from standalone.xml configuration
See this article if you are unsure: https://community.jboss.org/thread/213470
Note:
I do not have an ejb-client.xml in my app server.
I have managed to get this project working correctly using jboss-ejb-client.properties and EJB Naming previously.
Client Code (Pojo project with jboss 7 libraries):
private static final String DEFAULT_HOST ="1.2.3.4";
private static final String DEFAULT_REMOTING_PORT="4447";
private static final String DEFAULT_USER= "admin";
private static final String DEFAULT_PASSWORD= "password";
private static final String CONTEXT_PROVIDER_URL = "remote://" + DEFAULT_HOST + ":" + DEFAULT_REMOTING_PORT;
//THE CODE
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
prop.setProperty(Context.PROVIDER_URL, CONTEXT_PROVIDER_URL);
// prop.setProperty(Context.SECURITY_PRINCIPAL, DEFAULT_USER);
// prop.setProperty(Context.SECURITY_CREDENTIALS, DEFAULT_PASSWORD);
// prop.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
// prop.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");
Properties ejbProp = new Properties();
ejbProp.put("remote.connections", "default");
ejbProp.put("remote.connection.default.host",DEFAULT_HOST);
ejbProp.put("remote.connection.default.port",DEFAULT_REMOTING_PORT);
ejbProp.put("remote.connection.default.username", DEFAULT_USER);
ejbProp.put("remote.connection.default.password", DEFAULT_PASSWORD);
// ejbProp.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
ejbProp.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");
final PropertiesBasedEJBClientConfiguration configuration = new PropertiesBasedEJBClientConfiguration(ejbProp);
final ContextSelector <EJBClientContext> ejbClientContextSelector = new ConfigBasedEJBClientContextSelector(configuration);
EJBClientContext.setSelector(ejbClientContextSelector);
MyEJBInterface mei = null;
try{
Context context = new InitialContext(prop);
String lookupName = "MyEAR/MyEJB/MyInterface!co.org.MyInterfaceRemote";
ResponseObject responseObj;
responseObj = (MyInterfaceRemote) context.lookup(lookupName);
try{
responseObj = mei.doWork();
if (responseObj !=null){
System.out.println("responseObj Received");
}
else{
System.out.println("Null responseObj.");
}
}catch(OtherException oe){ // throw by
System.err.println("Other Exception occurred. ");
oe.printStackTrace();
}
}catch (NamingException ne){
ne.printStackTrace();
}
On the App server, I can see the started EJB services:
java:global/MyEAR/MyEJB/MyInterface!co.org.MyInterfaceLocal
java:app/MyEJB/MyInterface!co.org.MyInterfaceLocal
java:module/MyInterface!co.org.MyInterfaceLocal
java:global/MyEAR/MyEJB/MyInterface!co.org.MyInterfaceRemote
java:app/MyEJB/MyInterface!co.org.MyInterfaceRemote
java:module/MyInterface!co.org.MyInterfaceRemote
java:jboss/exported/MyEAR/MyEJB/MyInterface!co.org.MyInterfaceRemote
On my client Pojo the strack-trace is:
org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.2.GA
org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: Received server version 1 and marshalling strategies [river]
org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@48074a, receiver=Remoting connection EJB receiver [connection=Remoting connection <24bef5>,channel=jboss.ejb,nodename=somepersonallyidentifiableinfo]} on channel Channel ID e5261bed (outbound) of Remoting connection 00275b35 to /1.2.3.4:4447
org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleMessage
WARN: Unsupported message received with header 0xffffffff
javax.naming.NamingException: java.lang.IllegalStateException: No EJB client context is available [Root exception is java.lang.RuntimeException: java.lang.IllegalStateException: No EJB client context is available]
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:135)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:74)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:124)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:70)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: No EJB client context is available
at org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:91)
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:133)
... 7 more
Caused by: java.lang.IllegalStateException: No EJB client context is available
at org.jboss.ejb.client.EJBClientContext.requireCurrent(EJBClientContext.java:233)
at org.jboss.ejb.client.EJBClient.createSession(EJBClient.java:160)
at org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory.getReference(RemoteViewManagedReferenceFactory.java:89)
... 8 more
On my Jboss 7.1 app server I see the following error:
ERROR [org.jboss.remoting.remote.connection] (Remoting "somepersonallyidentifiableinfo" read-1) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host
INFO [org.jboss.as.naming] (Remoting "somepersonallyidentifiableinfo" task-4) JBAS011806: Channel end notification received, closing channel Channel ID 5d21f931 (inbound) of Remoting connection 01ab4788 to null
Note: node name is obviously not "somepersonallyidentifiableinfo", but has been set to my local computing device's name.
Concluding Questions:
Am I using the jboss remote naming lookup correctly in this case?
I expect from the errors that this is somehow related to the EJBClientContext, am I missing something in passing this to the initialContext?
Finally I would appreciate it if you do not simply paste other articles here with similar issues, as I have investigated for 10 working days online for solutions and am in need of a bit of guidance if possible.
Any help or direction here is appreciated - if you would like to see additional code or trace-level output, I will provide it.