Skip to Content
author's profile photo Former Member
Former Member

Urgent! Callin EJB beans from a application

hey all,

I m new to java programming. My client requires me to call EJB beans from a application or from a EJB bean and want me to deploy onto a server. How do I do that? Is it that I can achieve this with RMI?? Or else can someone tell me how? And can someone send me the code? It will be really helpful to me if you send me the code in this short time I have.

Help me out..

Regards

Pavan..

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Jun 07, 2007 at 09:02 AM

    Hi There

    A Complete Example of Creating and Calling the EJBs is

    within the Help System of the NWDS Itself.Check That.

    Also Check this url on your server for More Examples,

    http://<Servername>:50100

    Click on J2ee Exapmles..

    These are Running Examples with Source Code !

    Regards

    Rajendra

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 07, 2007 at 11:50 AM

    hi

    good

    Q->Call an ejb bean from another ejb bean

    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);

    2->Achieve it with RMI

    Remember that your beans are running inside the container and that you can access them using the Home and Remote interfaces. This is in fact using RMI (Remote Method Invocation)... communication between the web-container and the EJB-container for example.

    This means that when accessing an EJB from a POJO, use the Home interface to retrieve an instance of that EJB.

    If you are communicating between two EJB's however (running in the same EJB container), you should use the LocalHome object to retrieve an instandce of that EJB. At that moment no RMI is used but just plain old class loading. This will result in quite an increase of speed.

    thanks

    mrutyun^

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 07, 2007 at 07:22 AM

    Hi PavanKrishna,

    You need to first deploy this EJB to the server use NWDS for it.

    After successful deployment, u need to use the JNDI name to look up the EJB and call it

    
    Properties prop = new Properties();
    
    		
    			try {
    						
    				prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl");
    				prop.put(Context.PROVIDER_URL,"suncss1.sicemadrid.com:50104");
    					
    				context = new InitialContext(prop);
    					
    				object = context.lookup("sap.com/SocketProxy/MICGOSendCancellationOB_PortTypeBean");// JNDI Name 
    					
    				mICGOSendCancellationOB_PortTypeHome = (MICGOSendCancellationOB_PortTypeHome)javax.rmi.PortableRemoteObject.narrow(object,MICGOSendCancellationOB_PortTypeHome.class);
    							
    				mICGOSendCancellationOB_PortType = mICGOSendCancellationOB_PortTypeHome.create();
    				
    				
    				/// on this object call the method.
    				
    				
    				
    			} catch (ClassCastException e) {
    				e.printStackTrace();
    				return null;
    			} catch (RemoteException e) {
    				
    				e.printStackTrace();
    				return null;
    			} catch (NamingException e) {
    				
    				e.printStackTrace();
    				return null;
    			} catch (CreateException e) {
    				
    				e.printStackTrace();
    				return null;
    			}
    		
    
    
    
    
    
    

    Also see some tutorials here.

    urlhttp://www.roseindia.net/software-tutorials/detail/6467">url>

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.