-
15. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
peterj Jul 11, 2006 1:01 PM (in response to j0ke)I copied your code, ran it, and finally figured out what was wrong. The annotation @Stateless(name="SimpleEJB") names the EJB, but it does not provide the JNDI name for the EJB. The JNDI name, by default, is "SimpleEJB/remote" (or "SimpleEJB/local").
So you can do one of two things.
Change your lookup code to read:SimpleEJB sessEJBTest = (SimpleEJB)context.lookup("SimpleEJB/remote");
Or add a JBoss-specific annotation to your bean class:@Stateless(name="SimpleEJB") @org.jboss.annotation.ejb.RemoteBinding(jndiBinding="SimpleEJB") public final class SimpleEJBBean implements SimpleEJB { ...
-
16. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
j0ke Jul 11, 2006 3:16 PM (in response to j0ke)hm .
org.jboss.annotation.ejb.RemoteBinding(jndiBinding="SimpleEJB")
in which jar is located this ? i cant find it on client/*.jars
btw i Try SimpleEJB/remote it says remote not bound.
i try somethink different i write this code :
and the output is:
XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
TopicConnectionFactory: org.jboss.naming.LinkRefPair
EventDispatcher: org.jboss.ws.eventing.mgmt.DispatcherDelegate
UserTransactionSessionFactory: $Proxy42
UIL2ConnectionFactory: javax.naming.LinkRef
UIL2XAConnectionFactory: javax.naming.LinkRef
QueueConnectionFactory: org.jboss.naming.LinkRefPair
topic: org.jnp.interfaces.NamingContext
queue: org.jnp.interfaces.NamingContext
SimpleEJBBean: org.jnp.interfaces.NamingContext
ConnectionFactory: org.jboss.mq.SpyConnectionFactory
UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
jmx: org.jnp.interfaces.NamingContext
UILXAConnectionFactory: javax.naming.LinkRef
UILConnectionFactory: javax.naming.LinkRef
so the EJB is deloyed.
then i try this client:
InitialContext ctx;
try {
ctx = new InitialContext();
ctx.addToEnvironment("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
ctx.addToEnvironment("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
ctx.addToEnvironment(Context.PROVIDER_URL, "jnp://localhost:1099");
SimpleEJB ejb=
(SimpleEJB)ctx.lookup("SimpleEJBBean"); // i try SimpleEJBBean becouse there is SimpleEJBBean in the list
System.out.println(simpleSession.sayHello("EJB3"));
} catch (NamingException e) {
e.printStackTrace();
}
but now my client says :
Exception in thread main
java.lang.ClassCastException: org.jnp.interfaces.NamingContext
at client.SimpleEJBClient.main(SimpleEJBClient.java:39)
Process exited with exit code 1.
line 39 is
SimpleSession simpleSession =
(SimpleSession)ctx.lookup("SimpleSessionBean"); -
17. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
j0ke Jul 11, 2006 3:17 PM (in response to j0ke)ops i missed the code for the listing it is
Context ctx = new InitialContext();
ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
ctx.addToEnvironment(Context.PROVIDER_URL,"jnp://localhost:1099");
NamingEnumeration it = ctx.list("");
Object obj;
while (it.hasMoreElements()) {
obj = it.nextElement();
System.out.println(obj);
} -
18. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
peterj Jul 11, 2006 3:38 PM (in response to j0ke)What annotation do you have on your interface. It should be:
import javax.ejb.Remote; @Remote public interface SimpleEJB { String sayHello(String name); }
Note that SessionEJB is of type NamingContext, so it is not the EJB (or its proxy), but rather is a directory, hence the reason for the ClassCastException. -
19. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
j0ke Jul 11, 2006 3:48 PM (in response to j0ke)yes my interfeis is
import javax.ejb.Remote;
import javax.ejb.Remote;
@Remote
public interface Pisnami {
btw this is new EJB
i think that ctx.lookup lookups for Enterprise Archive... i mean Name of the Enterprise Application
and it says ClassCastException becouse yes this is the name of delpoyment profile of "EAR" file not the EJB .. .
but why i cant get the EJB by name ?
how can i get it when it is on the ear
the code that you paste with jndiName="somethink" in which jar is loceted that annotation ? ( interfeis ) -
20. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
peterj Jul 11, 2006 3:57 PM (in response to j0ke)Did you try:
SimpleEJB sessEJBTest = (SimpleEJB)context.lookup("SimpleEJBBean/remote");
The RemoteBinding annotation is in client/jboss-annotations-ejb3.jar -
21. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
j0ke Jul 11, 2006 4:29 PM (in response to j0ke)hm
it works
the answer : DONT PUT EJB IN EAR.
i just make new EJB and put it at JAR and deploy the JAR
now it works
thanks peterJ
btw jndiBinding doesnt work i found the interface in some package of server/*.jar -
22. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
j0ke Jul 11, 2006 4:32 PM (in response to j0ke)"PeterJ" wrote:
Did you try:SimpleEJB sessEJBTest = (SimpleEJB)context.lookup("SimpleEJBBean/remote");
The RemoteBinding annotation is in client/jboss-annotations-ejb3.jar
yes this works if the JAR is not in EAR...
becouse then the JNDIName of the APplicaiton is present not the JNDIName of the EJB dont know why
10x 10x THANKSSS thanks a lot
if you come to Bulgaria call for bear :) -
23. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
j0ke Jul 11, 2006 4:57 PM (in response to j0ke)"J0Ke" wrote:
"PeterJ" wrote:
Did you try:SimpleEJB sessEJBTest = (SimpleEJB)context.lookup("SimpleEJBBean/remote");
The RemoteBinding annotation is in client/jboss-annotations-ejb3.jar
yes this works if the JAR is not in EAR...
becouse then the JNDIName of the APplicaiton is present not the JNDIName of the EJB dont know why
10x 10x THANKSSS thanks a lot
if you come to Bulgaria call for bear :)
btw the code is
SimpleEJB sessEJBTest = (SimpleEJB)context.lookup("SimpleEJB/remote");
not SimpleEJBBean/remote and yes it works :) -
24. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
puravjoshi Aug 18, 2006 10:00 AM (in response to j0ke)Hello All,
I am also facing the same error when look up EJB 3.0 Bean.
If any one found any clue then please reply.
Thankng you,
Purav Joshi -
25. Re: Remote Client to EJB 3.0 fail .. :( javax.naming.Communi
prps1234 May 15, 2008 2:04 PM (in response to j0ke)Check your context lookup code. If you have used run with a ipadress to start jboss then put the same ipaddess for java.naming.provider.url then you will not get this error.
Properties env = new Properties();
env.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
// I had to change localhost to the ipadress of the dev server.
// you might have to put it back to localhost if u want to test it on
// your local server
//env.setProperty("java.naming.provider.url", "localhost:1099");
env.setProperty("java.naming.provider.url", "Use your serverip address:1099");
env.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming");
ctx = new InitialContext(env);