Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Accessing EJB Component from non j2ee application

Posted on 2004-09-29
6
Medium Priority
?
366 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
3 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

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