Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Topic: access remote session ejb on remote server

 
Yi Meng
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one session ejb deployed on serverA with jndi name: ejb/MySLSBRemoteHome

I have one web client deployed on serverB with the following DD segment:

Both are running weblogic 8.12

web.xml



<ejb-ref>
<ejb-ref-name>test/myejb</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>test.MySLSBHome</home>
<remote>test.MySLSBRemote</remote>
</ejb-ref>






weblogic.xml


<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>test/myejb</ejb-ref-name>
<jndi-name>ejb/MySLSBRemoteHome</jndi-name>
</ejb-reference-description>
</reference-descriptor>




index.jsp


Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://severA:7001");

Context initial = new InitialContext(prop);
Object objref = initial.lookup("java:comp/env/test/myejb");

MySLSBHome home =
(MySLSBHome)PortableRemoteObject.narrow(objref,
MySLSBHome.class);

MySLSBRemote bean = home.create();





Now the problem is that i get an exception:


javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundExcept
ion: Unable to resolve 'ejb/MySLSBRemoteHome' Resolved ejb; remaining name 'MySLSBRemoteHome'


But when i change the lookup to initial.lookup("ejb/MySLSBRemoteHome"); it will work. But i am supposed to use "java:comp/env/test/myejb", right?

Can anyone of you help me out? Thanks in advance
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yi,

Object objref = initial.lookup("java:comp/env/test/myejb");


would give you a jndi subcontext (i.e. object of javax.naming.Context type). Looks like a piece of code you've included does not contain the actual ejb home lookup.

As far as I understand "java:comp/env" subcontext is only used when performing lookups from within the enterprise bean (it is a special jndi context where Bean Provider can define constants [<env-entry>], resource managers [<resource-ref>], ejb references [<ejb-ref>] that a particular bean uses). Please correct me if I am wrong.
 
Yi Meng
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have declared ejb-ref in my web.xml, right?

And i should use the coded name as in ejb-ref-name "test/myejb" in my application, right?
 
Alex Sharkoff
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Woops...

I have looked at the web.xml extract again and realised that test/myejb does refer to the Enterprise Java Bean and not to the javax.naming.Context. I am sorry for the confusion.

I got mistaken because usually one would use a standard when defining an ejb reference name:
1) context starts with the lower case char
2) actual name starts with the upper case char.
Therefore, in our example ejb-ref-name would have test/MyEJB value.

Anyway, I have tried to replicate your problem using JBoss rather than weblogic (I just do not have weblogic ). It works like a dream - recommended lookup (using <ejb-ref-name> defined in web.xml) and a lookup that uses an actual jndi name both return a remote object.

Have you checked that your second application (the one on serverA) got deployed at the time of the lookup with the <ejb-ref-name>?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic