Locate another EJB in 8.1.7 db

I created a couple session EJB's and deployed them to an Oracle 8i db. I can call both of them from a client, but I can't figure out how to use one ejb from the other. One bean has this code but it doen't work:
Context ic = new InitialContext( );
Client cl = (Client) ic.lookup("Client");
I just can't figure hot to reference another ejb. The "caller" ejb has a refernce in the deployment descriptor like:
<ejb-ref>
<description></description>
<ejb-ref-name>Client</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>ClientHome</home>
<remote>Client</remote>
<ejb-link>/com/nsc/docworks/Client</ejb-link>
</ejb-ref>
Any help is appreciated, thanks.

I figured it out, too simple.
Context ic = new InitialContext ( );
// get the home
ClientHome clh = (ClientHome)ic.lookup ("/test/Client");
// get the remote interface
Client cl = clh.create();
cl.setClientId(333);
cl.remove();
null

Similar Messages

  • EJB as a Client to another EJB in 6.0

    I have an EJB that calls another EJB. I understand that to call the first EJB from a java Client, I need to have the home and remote interface in the path of the Client. However, when the EJB locates the 2nd EJB through JNDI, I'm getting an exception that the 2nd EJB does not have access to the first EJBs interfaces. When I physically put the first EJBs home and remote interfaces in the /config/examples/serverclasses directory that is explicitly included in the CLASSPATH, the call to the second bean is successful. Why don't the EJBs have access to each others interaces?

    Because they either need to be in the same .jar or in the same .ear.
    Gene
    "Clay Barrow" <[email protected]> wrote in message news:3a7989fa$[email protected]..
    I have an EJB that calls another EJB. I understand that to call the first EJB from a java Client,I need to have the home and remote interface in the path of the Client. However, when the EJB
    locates the 2nd EJB through JNDI, I'm getting an exception that the 2nd EJB does not have access to
    the first EJBs interfaces. When I physically put the first EJBs home and remote interfaces in the
    /config/examples/serverclasses directory that is explicitly included in the CLASSPATH, the call to
    the second bean is successful. Why don't the EJBs have access to each others interaces?

  • How do I locate another cell phone with my iphone?

    how do I locate another cell phone with my iphone?

    you can't unless it's an AirPrint enabled printer or you purchase a 3rd party app like printopia.

  • How to call one EJB in another EJB?

    How to call one EJB in another EJB? Please explain with some example code.

    To refer a Ejb from another Ejb include <ejb-ref> element in ejb-jar.xml
    <session>
    <ejb-name>EjbA</ejb-name>
    <ejb-ref>
    <ejb-ref-name>EjbB</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>com.ejb.EjbBHome</home>
    <remote>com.ejb.EjbB</remote>
    </ejb-ref>
    </session>
    Include a <reference-descriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>EjbA</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>EjbB</ejb-ref-name>
    <jndi-name>com.ejb.EjbBHome</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    In EjbA Bean class refer to EjbB with
    a remote reference to EjbB.
    InitialContext initialContext=new InitialContext();
    EjbBHome EjbBHome=(EjbBHome)
    initialContext.lookup("com.ejb.EjbBHome");
    EjbB ejbB=EjbBHome.findByPrimaryKey(primarykey);

  • Calling EJB from another EJB

    I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
    the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
    practice ?? If not, do I need to get remote reference of the EJB2 every time I
    need to call EJB2 method??
    Thanks in advance.

    To refer a Ejb from another Ejb include <ejb-ref> in ejb-jar.xml
    <session>
    <ejb-name>Ejb1</ejb-name>
    <ejb-ref>
    <ejb-ref-name>Ejb2</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>com.ejb.Ejb2Home</home>
    <remote>com.ejb.Ejb2</remote>
    </ejb-ref>
    <session>
    Include a <reference-discriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>EjbSession</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>Ejb2</ejb-ref-name>
    <jndi-name>com.ejb.Ejb2Home</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    In Ejb1 bean class refer to Ejb2 method with a remote reference to Ejb2.
    InitialContext initialContext = new InitialContext();
    Ejb2Home ejb2Home = (Ejb2Home)initialContext.lookup("com.ejb.Ejb2Home");
    Ejb2 ejb2 = ejb2Home.findByPrimaryKey();
    Alex Pratt wrote:
    I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
    the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
    practice ?? If not, do I need to get remote reference of the EJB2 every time I
    need to call EJB2 method??
    Thanks in advance.

  • Use another ejb in MDB

    I've got an EJB that can be used in servlet and another ejb. but when I tried to use it in a MDB(message-driven bean), it can find the home, but it will fail if invoking
    the create method on the home.
    WHY????
    Any input would be appreciated.
    Thanks

    I've got an EJB that can be used in servlet and another ejb. but when I tried to use it in a MDB(message-driven bean), it can find the home, but it will fail if invoking
    the create method on the home.
    WHY????
    Any input would be appreciated.
    Thanks

  • Trouble in communicating with another EJB from an EJB

    I have created a stateless session bean, and inside this bean I have methods that calls methods in another stateless session bean (called myEJB, for example). When I run the code, it kept giving me the "noClassDefFoundError":
    java.rmi.RemoteException: Error in ejbCreate:; nested exception is:
         java.lang.NoClassDefFoundError: com.mybean.myEJBHome
    Someone suggested to me that this is because they aren't remote objects, so I created local interfaces for "myEJB". When I run the code again (by binding to the Local interface now), I got this error:
    javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: Unable to resolve
    'app/ejb/mybeans.jar#myEJB/local-home' Resolved: 'app/ejb/ Unresolved:'mybeans.jar#myEJB' ;
    remaining name 'mybeans.jar#myEJB/local-home']; Link Remaining Name:
    'java:app/ejb/mybeans.jar#myEJB/local-home'
    Any ideas??
    Thanks

    To refer a Ejb from another Ejb include <ejb-ref> in ejb-jar.xml
    <session>
    <ejb-name>EjbA</ejb-name>
    <ejb-ref>
    <ejb-ref-name>Ejb2</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>com.ejb.Ejb2Home</home>
    <remote>com.ejb.Ejb2</remote>
    </ejb-ref>
    <session>
    Include a <reference-discriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>EjbA</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>Ejb2</ejb-ref-name>
    <jndi-name>protocol://<Ejb2host>:<PortNumber>/com.ejb.Ejb2Home</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    Example <jndi-name>:http://localhost:7001/com.ejb.Ejb2Home
    In EjbA bean class refer to Ejb2 method with a reference to Ejb2 remote interface.
    InitialContext initialContext = new InitialContext();
    Ejb2Home ejb2Home = (Ejb2Home)initialContext.lookup("protocol://<Ejb2host>:<PortNumber>/com.ejb.Ejb2Home");

  • How do I reference an EJB inside anothe EJB ,both are on different hosts

    Hi,
    I want to reference an EJB on one host inside another EJB in another
    host. Even if i hardcode the url of the host on which the EJB is
    deployed , it gives me the error regarding the no such ejb found.
    I would appreciate your help.
    Thanks

    Robert,
    We've been trying to implement this type of multi-server setup for some
    time now. Our application consists of 260+ EJBs with a large team of
    developers actively working against it. The business logic in our
    application puts the EJBS in a highly interrelated situation. This
    degree of interrelation makes it necessary for each developer to deploy
    the entire application before any work can get done.
    Starting a weblogic server, on a Windows Workstation, with 260+ beans is
    very time consuming. But to get around this development bottle neck, we
    are attempting the same scenario described in this thread. We have
    recently upgraded from WL4.5.x to WL5.1 SP8. With WL5.1, we get the
    CommunicationException seen previously in this thread. But the Error
    message in WL5.1 is less descriptive. The 5.1 error message is missing:
    WL6.0 Error Text: "This error could indicate that a component was
    deployed on a cluster member but not other members of that cluster. Make
    sure that any component deployed on a server that is part of a cluster
    is also deployed on all other members"
    It is obvious that weblogic's clustering depends on classes being
    available to each server in the cluster, including the ejbc generated
    _WLStub classes.  To me, it seems wrong that a weblogic server can only
    use standard JNDI to lookup HomeInterfaces on other weblogic servers if
    the hidden _WLStub classes are available to both servers.  I say this
    because non-weblogic clients have JNDI lookup abilities without these
    requirements. This whole experience was frustrating because all along
    I knew that the solution was simply to take the hacker route and put the
    classes in the the client classpath. I guess I just want to know if
    this is bug? If not, I think it should be.
    Thanks for listening
    Steve Dodge
    Steve Dodge
    Realeum Inc.
    Robert Patrick wrote:
    Here is an example:
    On server1, I have a Bean called TellerBean that calls the AccountBean
    that lives on server2. To make this work, I need to deploy the
    TellerBean.jar file AND any/all AccountBean Stub classes (any file in the
    deployed version of the AccountBean.jar file matching the pattern
    AccountBean*Stub.class) on server1. Server2 only needs to deploy the
    AccountBean.jar file
    Hope this helps,
    Robert
    kamps wrote:
    Thanks.
    I did include the files using import and they are alsso packaged
    into the jar file .
    I have done this , TradeCheck is the ejb i am trying to reference
    in Trader EJB.
    I package them into the jar file as follows:-
    @REM Compile EJB classes into the build directory (jar preparation)
    javac -d build TradeCheck.java TradeCheckHome.java Trader.java
    TraderHome.java TraderBean.java TradeResult.java
    @REM Make a EJB jar file, including XML deployment descriptors
    cd build
    jar cv0f std_ejb20_basic_statelessSession2.jar META-INF examples
    images
    cd ..
    @REM Run EJBC on jar file
    java -classpath
    %WL_HOME%/lib/weblogic_sp.jar;%WL_HOME%/lib/weblogic.jar weblogic.ejbc
    -compiler javac build\std_ejb20_basic_statelessSession2.jar
    %APPLICATIONS%\ejb20_basic_statelessSession2.jar
    It still gives the same error not finding the stub class.... Could
    you kindly elaborate on what needs to be done.
    I would appreciate your help.
    Thanks,
    Sunitha
    Robert Patrick <[email protected]> wrote:
    The problem is that the client that downloads the stubs
    at runtime cannot
    be another WebLogic Server. We do not support downloading
    classes into a
    running server so you will need to make sure that the
    stubs are
    "available" to the server that is acting as a client (e.g.,
    packaged in
    the EAR file) on the server acting as a client.
    kamps wrote:
    Thanks Mahendra. I am using WebLogic 6.0. Should I importthe package
    in the first ejb which references the 2nd ejb or evenin the client
    which references the first ejb.
    Thanks again,
    Sunitha
    "Mahendra Dhamdhere" <[email protected]> wrote:
    You are not getting the reference of stub.
    try this. In your client program, import the package
    in
    which ejb classes
    are present. As client downloads the stub from weblogic,
    you have to import
    the package where your stubs are present.
    which version of weblogic are you using?
    Mahendra
    kamps <[email protected]> wrote in message
    news:[email protected]...
    Thanks,
    I have 2 ejbs: one is TraderBean and a client RefClient.
    TraderBean in turn calls a method of another bean
    TradeCheckBean.
    I tried making the changes as suggested but I amgetting
    the following
    error on the client side.
    java examples.ejb20.basic.tatelessSession.RefClient"t3://localhost:7001"
    javax.naming.CommunicationException. Root exceptionis
    java.rmi.UnmarshalException:
    failed to unmarshal class java.lang.Object; nested
    exception
    is:
    java.lang.ClassNotFoundException:examples.ejb20.basic.statelessSession.Trade
    CheckBeanHomeImpl_WLStub: This error could indicatethat a component
    was deployed on
    a cluster member but not other members of that
    cluster.
    Make
    sure that any componen
    t deployed on a server that is part of a cluster
    is
    also deployed
    on all other member
    s of that cluster
    java.lang.ClassNotFoundException:examples.ejb20.basic.statelessSession.TradeCheckBea
    nHomeImpl_WLStub: This error could indicate that
    a
    component was
    deployed on a clus
    ter member but not other members of that cluster.
    Make
    sure that
    any component deploy
    ed on a server that is part of a cluster is also
    deployed
    on all
    other members of tha
    t cluster
    <<no stack trace available>>
    I would appreciate any help.
    Thanks,
    kamps
    "Mahendra Dhamdhere" <[email protected]> wrote:
    you need to get initialcontext of that server.
    Context ctx = null;
    Hashtable ht = new Hashtable();
    ht.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
    try
    ctx = new InitialContext(ht); // Use
    the
    context
    in your program
    } catch (NamingException e)
    {    // a failure occurred  }
    finally {    try {ctx.close();}
    catch (Exception e)
    {      // a failure occurred    } }
    use url of that other server. After getting initialcontext,
    lookup for your
    ejb.
    Mahendra
    kampu S <[email protected]> wrote in message
    news:[email protected]...
    Hi,
    I want to reference an EJB on one host inside
    another
    EJB in another
    host. Even if i hardcode the url of the host on
    which
    the EJB is
    deployed , it gives me the error regarding the
    no
    such
    ejb found.
    I would appreciate your help.
    Thanks

  • EJB lookup from another EJB server

    Hi people,
    I have two application servers on two different computers. One
    of them contains an EJB, which I need to access from another EJB
    server. I know that I can achieve this using RMI, but will then
    security and transaction contexts be propagated to the called
    EJB?
    Sincerely,
    Sergei Batiuk.

    Here is the solution posted on another forum:
    [email protected] Dec 8, 6:03 am show options
    Newsgroups: ibm.software.websphere.studio
    From: [email protected]
    Date: 8 Dec 2004 06:03:04 -0800
    Local: Wed, Dec 8 2004 6:03 am
    Subject: Re: EJB lookup on from one server to another does not work
    Eric,
    I dealt with this same problem trying to run 2 local servers (websphere
    test servers), using 2 separate WSAD 5.1.2 workspaces. Running on 1
    server I have an application that contains an EJB, and running on the
    other server is an application that uses an access bean to make a
    remote call to my EJB, running on my other server. I too repeately
    received the "NameNotFoundException" when trying to lookup my EJB home
    reference.
    What you have to do to get around this is to modify the server
    configuration of the application that contains the EJB that you are
    attempting to call remotely. You must open the the server.wsi file for
    the server that is running the EJB and go to the "Configuration" tab.
    You must check the "Enable administrative console". Once this is
    complete, start your server. When it is started, right click on the
    server, and select "run administrative console". In the admin console,
    select
    servers -> application servers -> <your server> -> end points ->
    bootstrap address. For "host" you must change "localhost" to either
    your ip address or computer name (ive only tried my ip, but your
    computer name should work too). When building your properties to get
    the initial context, make sure you use
    "env.put(Context.PROVIDER_URL, "corbaloc:iiop:<the ip or computer name
    listed as the bootstrap host of server running ejb>:<the port listed as
    the bootstrap port of server running ejb, which is 2809 in your case>
    Restart your server and things should work.

  • Can an EJB extend another EJB?

    Can an EJB extend another EJB?
    Are there any limitations?
    Thank you in advance, Kostas

    Refer
    http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=ejb-interest&F=&S=&P=31185

  • Error in calling an EJB from another EJB

    Hello All,
    I have a scenario where i need to call a method of an ejb from another ejb.
    Both the EJB's are in different DC's.
    EG: DC1 using DC2
    I have added the public part of DC2 in DC1.
    The following code is written in DC1 to access the EJB of DC2
          MyRemote l_remote;
           MyHome l_home;
           InitialContext l_ctx = new InitialContext();
    >>       l_home = (MyHome)l_ctx.lookup("JNDI Name");
           l_remote = (MyRemote)l_home.create();
    There is no error at build time and deploy time, but at run time "MyHome" class is not found.
    Even i am not able to access the helper class defined in the DC2 at runtime.
    Please help.
    Thanks in Advance

    First off, wrong forum section.
    Check if your JNDI name is correctly placed for the bean you're calling -- check j2ee-engine.xml for that. Check the EJB container if the ear file you deployed is there and updated.
    Try placing  "localejbs/JNDI name" on your lookup parameter.
    Regards,
    Jan

  • Error when One EJB calls anothe EJB

    Hi,
    I got the following error when I use one EJB call another EJB in OAS 4.0.8.1, the code is developed in JDeveloper 3.0/Win NT 4.0/SP5.
    Can anyone give me some ideas? or is there any samples in this case?
    Thanks a lot!
    Creating an initial context
    Looking for the EJB published as 'APP/APPEJB'
    Creating a new EJB instance
    Calling APPEJB methods...
    CORBA: org.omg.CORBA.BAD_OPERATION: ; nested exception is:
    org.omg.CORBA.BAD_OPERATION:
    java.rmi.ServerException: CORBA: org.omg.CORBA.BAD_OPERATION: ; nested exception is:
    org.omg.CORBA.BAD_OPERATION:
    at javax.rmi.oas.corba.CorbaRemoteExceptionHelperValue.OBVObjFrom(Compiled Code)
    at TwoEJB._stub_APPEJB.callEJBMapping(Compiled Code)
    at TwoEJB.TwoEJBClient.main(Compiled Code)
    null

    Home handle is an object that identifies an enterprise bean. A client may serialize the handle, and then later deserialize it to obtain a reference to the enterprise bean.
    The javax.ejb.HomeHandle is similar to javax.ejb.Handle. Just as the Handle is used to store and retrieve reference to EJB objects, the HomeHandle is used to store and retrieve remote references to EJB homes. HomeHandle can be stored and later used to access an EJB home remote refrence the same way that a Handle can be serialized and later used to access an EJB object's remoe reference.
    import java.io.*;
    import javax.ejb.EJBHome;
    import javax.ejb.HomeHandle;
    public class WorkingWithEJBHandles {
    public static void main( String[] args ) throws Exception {
    EJBHome aHome = null;
    // get hold of a home interface
    HomeHandle handle = aHome.getHomeHandle();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream( bos );
    oos.writeObject( handle );
    byte[] handleAsBytes = bos.toByteArray();
    // store in the database, on file. howwever you want
    FileInputStream fis = new FileInputStream( "fileobj" );
    ObjectInputStream ois = new ObjectInputStream( fis );
    HomeHandle theHandle = (HomeHandle) ois.readObject();
    // get back the EJBHome from the HomeHandle
    aHome = theHandle.getEJBHome();
    // the same kind of logic also holds for EJBHandles, as well as
    // HomeHandles
    Transfer Object is a Design pattern. Refer to Core J2EE Design Pattern.
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html
    Rgds,
    Seetesh

  • Can EJB method return another EJB?

    Hello,
    I am new to EJB technology. I am working with Sun Application Server bundled in Netbeans 4.1
    Is it po[b]ssible a method of a session bean to return another EJB which is instantiated with arguments depended on the method?
    If no, is there an alternative way?
    thank you in advance, Kostas

    Is it possible within the SessionBean method to
    call another Session Bean, create it using the
    local interface, pass some parameters using setter
    methods, then cast it from local interface to
    remote and send it to the user?I think it's not possible casing Local Interface into Remote Intrface, because they inherit from different classes.
    Remote interface extends EJBObject and Local interface extends EJBLocalObject
    Fil

  • How tom invoke an EJB from another EJB using the sun rmi protocl in Weblogi

    Hi,
    I am particularly new to EJB.
    My scenario is
    client invoking-->EJB-----invoking ----(Either a webService or an EJB)
    in WEBLOGIC
    Is it possible that a call from EJB to another EJB or WebService use Sun's RMI as underlying protocol instead of t3 or IIOP which are used in Weblogic ?
    Would be really a great help if you could provide me some sample on it on weblogic.

    Hi Stefan,
    You don't need to provide the InitialContextFactory for running a standalone client. The following should work just fine:
    Context initial = new InitialContext();
    System.out.println("Looking up ...");
    Object objref = initial.lookup(EJB);  //the lookup name should be a global JNDI name      //and not from the java:comp namespace
    System.out.println("Looked up EJB");The JNDI implementation looks for the jndi.properties file in your classpath. So make sure that you have the appserv-rt.jar from your <server_installation>/lib directory in your classpath.
    HTH,
    Sheetal

  • EJB calling another EJB - special considerations

    I am trying to call an EJB from another EJB in the same container. I am able to get hold of the home interface but get an error when I try to narrow and get the Bean.
    The error I get is a class cast exception. Cannot narrow ....
    I read in some place that we need to do soemthing special with the DD's to achieve this. Any answers. I can post more code examples or send you samples.
    Any help will be gr8tly appreciated.
    Vijay

    Hi,
    If ure able to get the Home then you must call the create method on the home to create the Bean and not narrow it again. I think you use narrowing to get the Home and not the bean.
    I hope this helps
    neo

Maybe you are looking for