-
1. Re: Remote ejb causes ClassCastException in object returned by lookup()
robert.geisler Sep 24, 2012 11:37 AM (in response to haukem)hi...
do you set
jndiEnv.put("jboss.naming.client.ejb.context", true);
??regards
robert
-
2. Re: Remote ejb causes ClassCastException in object returned by lookup()
haukem Sep 24, 2012 4:10 PM (in response to robert.geisler)Thanks for the hint.
I haven't set jboss.naming.client.ejb.context and I will try it out when I am back in the office.
-
3. Re: Remote ejb causes ClassCastException in object returned by lookup()
haukem Sep 28, 2012 11:17 AM (in response to haukem)Somehow the cast now works without setting jboss.naming.client.ejb.context. I moved some code and somehow something with the class loaders must have changed.
Hashtable<String, Object> p = new Hashtable<String, Object>();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
p.put(Context.PROVIDER_URL, "remote://10.100.1.231:4447/");
p.put(InitialContext.SECURITY_PRINCIPAL, "test");
p.put(InitialContext.SECURITY_CREDENTIALS, "123456");
// p.put("jboss.naming.client.ejb.context", true);
InitialContext c = new InitialContext(p);
Object lookupRes = c.lookup("Gov2OCSPCRLRelay/management3/RequestControllerBean!" + RequestControllerRemote.class.getName());
RequestControllerRemote vLookup = (RequestControllerRemote)lookupRes;
Now I am getting "EJBCLIENT000025: No EJB receiver available for handling" when calling a method on the remote ejb.
I read in 199457 that I have to add p.put("jboss.naming.client.ejb.context", true); to fix that.
When adding jboss.naming.client.ejb.context I get the following Exception in new InitialContext(p);:
2012-09-28 16:35:00,837 ERROR [RMIRelayConnector] Error obtaining relay RequestController: : javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Failed to setup EJB remote context]
at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:51)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:151)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at de.bos_bremen.gov2.core.certificatevalidator.worker.RMIRelayConnector.getRemoteEjbNormal(RMIRelayConnector.java:152)
at de.bos_bremen.gov2.core.certificatevalidator.worker.RMIRelayConnector.sendRequest(RMIRelayConnector.java:182)
....
Caused by: java.lang.RuntimeException: Failed to setup EJB remote context
at org.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:468)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:145)
... 90 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:448)
... 91 more
Caused by: java.lang.SecurityException: EJBCLIENT000021: EJB client context selector may not be changed
at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:186)
at org.jboss.naming.remote.client.ejb.RemoteNamingEjbClientContextSelector.setupSelector(RemoteNamingEjbClientContextSelector.java:28)
... 96 more
-
4. Re: Remote ejb causes ClassCastException in object returned by lookup()
emollient-mind Jul 23, 2013 4:48 AM (in response to haukem)the only problem I see is the jndi name has to follow the new format which is
ejb:app name/module name/ distinct name/ bean name!package prefixed remote interface
so if I have
an ear file named : EtassEnterprise
an ejb jar file named : EtassBeans
distinct name :
bean Name : CalculatorBean
remote interface : org.melsoft.beans.Calculator
then my lookup code should look like
public void ejbLookup() {
// setup 'base' jndi properties - no jboss-ejb-client.properties being picked up from classpath!
Hashtable jndiProps = new Hashtable();
jndiProps.put("java.naming.factory.initial", org.jboss.naming.remote.client.InitialContextFactory.class.getName());
jndiProps.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");
jndiProps.put("jboss.naming.client.ejb.context", true);
jndiProps.put(Context.SECURITY_PRINCIPAL, "abc");
jndiProps.put(Context.SECURITY_CREDENTIALS, "123");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
System.out.println("\n\nLooking up remote ejb via its jndi name");
String ejbJndiName = "ejb:EtassEnterprise/EtassBeans//CalculatorBean!org.melsoft.beans.Calculator";
Context ctx = null;
try {
ctx = new InitialContext(jndiProps);
Calculator ref = (Calculator)ctx.lookup(ejbJndiName);
System.out.println("...Successful");
// call your ejb methods
} catch (NamingException e) {
System.out.println("...Failed");
e.printStackTrace();
} finally {
if (ctx != null) {
try {
ctx.close();
System.out.println("...Context closed");
} catch (Exception e) {}
}
}
}
Hope this helps
-
5. Re: Remote ejb causes ClassCastException in object returned by lookup()
anto.rossi78 Mar 23, 2014 6:53 PM (in response to emollient-mind)Hi,
i have your identical problem ... have you a solution?
i spent 3 days reading any kind of tutorial without solution.
Tnx