Solved

Accessing EJB Component from non j2ee application

Posted on 2004-09-29
6
336 Views
Last Modified: 2013-12-10
I am trying to access a stateless session bean on a remote Websphere server from a java application. This is not a servlet and does not run in a web container, it's a plain old java app. Here is the code that is giving me trouble:

Context initial = new InitialContext();            
Object o = initial.lookup("corbaname:iiop:wasdev3a:2810#ejb/com/xxxx/xxx/services/membersearch/ejb/MemberSearchServiceEjbBean");

I get this exception:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
      at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.java:44)
      at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:453)
      at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:492)
      at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at com.ibx.ecomm.mistool.Main2.main(Main2.java:54)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
      at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
      at org.omg.CosNaming._NamingContextStub.resolve(_NamingContextStub.java:251)
      at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:440)
      ... 4 more
Exception in thread "main"

Can anyone give me any pointers on invoking an ejb from a plain old java app. First solution that actually works wins the points.
Thanks.
0
Comment
Question by:amd2002a
6 Comments
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 68 total points
Comment Utility
0
 
LVL 7

Assisted Solution

by:damonf
damonf earned 66 total points
Comment Utility
Do you have the EJB client jar from that session bean?  Got to have that in your java app first.

Next, you need code like this to do the JNDI lookup:

             parms.put(Context.INITIAL_CONTEXT_FACTORY,
                   "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
             parms.put(Context.PROVIDER_URL, "iiop://hostserver:9999/"); //where 9999 is the iiop port
             Context ctx = new InitialContext(parms);
then do your lookup
0
 

Assisted Solution

by:aamir75
aamir75 earned 66 total points
Comment Utility
For your scenario you first have to install Pluggable Application Client. After that you have to run setupclient.bat file from command line. It will prepare environemnt (it will initialize the necessary environment variables pointing to the necessary jar files and directories). After that you can run your application by executing following command line:

%JAVA_HOME%/bin/java -Xbootclasspath/p:%WAS_BOOTCLASSPATH%
-classpath <classpath JARs>
-Djava.ext.dirs=%WAS_EXT_DIRS% -Djava.naming.provider.url=iiop://localhost
-Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
%SERVER_ROOT% %CLIENTSAS% <class containing main method>

you can see the variables like this %WAS_BOOTCLASSPATH%, these are the variables set by setupclient.bat.

You should get the initial context like this:

  Context ic = new InitialContext();
  String lookupString
            = "cell/nodes/localhost/servers/server1/ejb/dash/hr/services/EmployeeServiceHome";

For more info:

http://www-106.ibm.com/developerworks/websphere/library/techarticles/0409_bhogal/0409_bhogal.html

Good Luck!
Muhammad Aamir
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now