Home > Ask the SOA Experts > Questions & Answers > How can I access an EJB in WebSphere on one machine from a Java program on another?
Ask The SOA Expert: Questions & Answers
EMAIL THIS

How can I access an EJB in WebSphere on one machine from a Java program on another?

Jeff  Hanson EXPERT RESPONSE FROM: Jeff Hanson

Pose a Question
Other SOA Categories
Meet all SOA Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 01 June 2005
How can I access an EJB which exists in WebSphere (WAS Server) on one machine from a Java program on another machine in the same network?

>
EXPERT RESPONSE

You are describing the exact problem EJB was originally intended to solve. Up to and including EJB 2.x, with an EJB successfully deployed to the WAS, you simply perform a JNDI lookup of the EJB from a remote client and then make calls to the EJB as if it were running in the same VM. This requires you to know the EJB vendor's lookup URL, the JNDI name of the EJB, security credentials, etc. With EJB 3.0, all of the look-up information and functionality will be separated from the client code.

The following demonstrates a typical scenario for finding an EJB and calling a method on it:


java.util.Properties env = new java.util.Properties();

   env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,

           "com.anejbvendor.InitCtxFactory");

   env.put(javax.naming.Context.PROVIDER_URL,

           "ejb.server.jndi.url");

   java.security.Identity id = getIdentity();

   env.put(Context.SECURITY_PRINCIPAL, id);

   javax.naming.Context initial = new javax.naming.InitialContext(env);

   Object objref =

      (javax.naming.Context)initial.lookup("java:comp/env/ejb/MyEBJ");

   MyEJBHome home =

      (MyEJBHome)javax.rmi.PortableRemoteObject.narrow(objref,

                                                       MyEJBHome.class);

   MyEJB myEJB = home.create();

   myEJB.sayHello();


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
IBM Web services
JBoss, CA Wily moves target SOA performance management
IBM WebSphere grows to include better Business Event Processing
Quan on the Cloud part 2: IBM Autonomics director sees a service-oriented phenomenon
Quan on the Cloud part 1: IBM Autonomics director heralds user facing applications
From mainframes to iPhones and beyond: IBM preps mobile SOA connection
IBM rules SOA/BPM with ILOG buy – analysts
Web 2.0 at the old ballgame
SOA benefits outweigh risks – IBM exec
IBM's newest SOA framework tackles CRM
SOA is here to stay - IBM's LeBlanc

Java Web Services
Verizon uses BPEL app to cut down on code, check for fraud, and go green
Visual orchestration tool addresses event processing and SOA
Adobe Integrated Runtime (AIR) melds with ColdFusion - builds calendaring system for child services agency
Oracle re-brands BEA WebLogic as its strategic server for SOA
Ajax and Flex try to co-exist inside RIA development
BEA gives Oracle new Java platform, Eclipse tools
Where Ruby on Rails fits into SOA
Sun Java CAPS chugs down SOA open source track
JavaOne: JBoss on SOA middleware, Java EE and data services
Open source software requires governance, Burton warns

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Websphere MQ  (SearchSOA.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2001 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts