• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Why can't I invoke a ejb in Tomcat?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone:
I invoke a ejb in Tomcat(the ejb is in the weblogic in the same computer with tomcat).The jsp code is:
/////////////////first method//////////////////////
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
///////////////second method//////////////////
Hashtable ht=new Hashtable();
Context ctx=null;
ht.put(ctx.PROVIDER_URL, "t3://127.0.0.1:7001" ); // t3://127.0.0.1:7001
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext();
Hellohome home= (Hellohome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup ("HelloEJB"),Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
Is there any different?If I want to invoke the EJB which is in the weblogic.The Tomcat says:
//////////////////////////////////////////////
Name HelloEJB is not bound in this Context
But I bound it in the weblogic and I add the "
<ejb-ref>
<ejb-ref-name>HelloEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>lyoejb.Hellohome</home>
<remote>lyoejb.Hello</remote>
<ejb-link>Hello.jar#HelloEJB</ejb-link>
</ejb-ref>"
in the ejb-jar.xml. And I copy the j2ee.jar,wlclient.jar,Hello.jar to Tomcat/....web-inf/lib
How to setting the web.xml in the Tomcat? :roll:
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Tomcat forum.
bear
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use the Hashtable for creating the InitialContext...
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

But I find that the first code will be work property if I run the jsp in weblogic:
/////////////////first method//////////////////////
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());

But if the client is Tomcat the above code can't work.I must use the second code:
///////////////second method//////////////////
Hashtable ht=new Hashtable();
Context ctx=null;
ht.put(ctx.PROVIDER_URL, "t3://127.0.0.1:7001" ); // t3://127.0.0.1:7001
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext();
Hellohome home= (Hellohome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup ("HelloEJB"),Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
Does it because the jndi is in the weblogic so it needn't to use hashtable to place weblogic.jndi....in it? :roll:
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

But I find that the first code will be work property if I run the jsp in weblogic:
/////////////////first method//////////////////////
Context ctx=new InitialContext();
Object obj=ctx.lookup("ejb/Hello");
Hellohome home=(Hellohome)PortableRemoteObject.narrow(obj,Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());

But if the client is Tomcat the above code can't work.I must use the second code:
///////////////second method//////////////////
Hashtable ht=new Hashtable();
Context ctx=null;
ht.put(ctx.PROVIDER_URL, "t3://127.0.0.1:7001" ); // t3://127.0.0.1:7001
ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ctx = new InitialContext();
Hellohome home= (Hellohome) javax.rmi.PortableRemoteObject.narrow (ctx.lookup ("HelloEJB"),Hellohome.class);
Hello hello=home.create();
out.println(hello.getHello());
Does it because the jndi is in the weblogic so it needn't to use hashtable to place weblogic.jndi....in it? :roll:
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic