Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing EJB Component from non j2ee application

Posted on 2004-09-29
6
Medium Priority
?
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 272 total points
ID: 12186288
0
 
LVL 7

Assisted Solution

by:damonf
damonf earned 264 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 264 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 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