Solved

Accessing EJB Component from non j2ee application

Posted on 2004-09-29
6
341 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
ID: 12186288
0
 
LVL 7

Assisted Solution

by:damonf
damonf earned 66 total points
ID: 12190478
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
ID: 12295214
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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