facebook

EJB’s(Gen with MyEclipse)/With Local Access Not Working.

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #247529 Reply

    saloni.priya
    Member

    Hi there i did generated a Stateless Session Bean(J2EE 1.3 Complaint) with Local Access named Test1Bean.When i ran xdoclet It generated Interfaces named 1.Test1Local 2.Test1LocalHome.

    Here is the code for Test1Bean.java

    package dcse.ejb;
    
    import java.rmi.RemoteException;
    
    import javax.ejb.EJBException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    
    /**
     * XDoclet-based session bean.  The class must be declared
     * public according to the EJB specification.
     *
     * To generate the EJB related files to this EJB:
     *        - Add Standard EJB module to XDoclet project properties
     *        - Customize XDoclet configuration for your appserver
     *        - Run XDoclet
     *
     * Below are the xdoclet-related tags needed for this EJB.
     * 
     * @ejb.bean name="Test1"
     *           display-name="Name for Test1"
     *           description="Description for Test1"
     *           jndi-name="ejb/Test1"
     *           type="Stateless"
     *           view-type="local"
     */
    public class Test1Bean implements SessionBean {
    
        /** The session context */
        private SessionContext context;
    
        public Test1Bean() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        public void ejbActivate() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
    
        }
    
        public void ejbPassivate() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
    
        }
    
        public void ejbRemove() throws EJBException, RemoteException {
            // TODO Auto-generated method stub
    
        }
    
        /**
         * Set the associated session context. The container calls this method 
         * after the instance creation.
         * 
         * The enterprise bean instance should store the reference to the context 
         * object in an instance variable.
         * 
         * This method is called with no transaction context. 
         * 
         * @throws EJBException Thrown if method fails due to system-level error.
         */
        public void setSessionContext(SessionContext newContext)
            throws EJBException {
            context = newContext;
        }
    
        /**
         * An example business method
         *
         * @ejb.interface-method view-type = "local"
         * 
         * @throws EJBException Thrown if method fails due to system-level error.
         */
        public void replaceWithRealBusinessMethod() throws EJBException {
            System.out.println("In the replaceWithRealBusinessMethod of Test1..");
        }
    
    }

    Here is the code for Test1Local.java

    /*
     * Generated by XDoclet - Do not edit!
     */
    package dcse.interfaces;
    
    /**
     * Local interface for Test1.
     * @xdoclet-generated at ${TODAY}
     * @copyright The XDoclet Team
     * @author XDoclet
     * @version ${version}
     */
    public interface Test1Local
       extends javax.ejb.EJBLocalObject
    {
       /**
        * An example business method
        * @throws EJBException Thrown if method fails due to system-level error.    */
       public void replaceWithRealBusinessMethod(  ) throws javax.ejb.EJBException;
    
    }

    Here is the code for Test1LocalHome.java

    /*
     * Generated by XDoclet - Do not edit!
     */
    package dcse.interfaces;
    
    /**
     * Local home interface for Test1.
     * @xdoclet-generated at ${TODAY}
     * @copyright The XDoclet Team
     * @author XDoclet
     * @version ${version}
     */
    public interface Test1LocalHome
       extends javax.ejb.EJBLocalHome
    {
       public static final String COMP_NAME="java:comp/env/ejb/Test1Local";
       public static final String JNDI_NAME="Test1Local";
    
       public dcse.interfaces.Test1Local create()
          throws javax.ejb.CreateException;
    
    }

    part of ejb-jar.xml

          <session >
             <description><![CDATA[Description for Test1]]></description>
             <display-name>Name for Test1</display-name>
    
             <ejb-name>Test1</ejb-name>
    
             <local-home>dcse.interfaces.Test1LocalHome</local-home>
             <local>dcse.interfaces.Test1Local</local>
             <ejb-class>dcse.ejb.Test1Bean</ejb-class>
             <session-type>Stateless</session-type>
             <transaction-type>Container</transaction-type>
    
          </session>

    Client Code to Access the EJB

            Context ctx = new InitialContext();
            Test1Local Test1Local = null;
            System.out.println("Before Getting the objref..");
            Object objref = ctx.lookup(Test1LocalHome.JNDI_NAME);
            System.out.println("objref... "+objref);
            Test1LocalHome Test1LocalHome = (Test1LocalHome) objref;
            System.out.println("TestLocalHome is ...."+Test1LocalHome);
            Test1Local = Test1LocalHome.create();
            System.out.println("TestLocal is ...."+Test1Local);
            Test1Local.replaceWithRealBusinessMethod();

    Its working fine When iam working with Remote Interfaces.But when it comes to Local Access iam unable to access the EJB.Few things i didn’t understood with MyEclipse/XDoclet Generation..

    1.When i generate remote access EJB’s its creates code in Home Interface like this

       public static final String COMP_NAME="java:comp/env/ejb/UserAccount";
       public static final String JNDI_NAME="ejb/UserAccount";
    
       public us.ny.state.otda.dcse.ejbmodule.useraccount.interfaces.UserAccount create()
          throws javax.ejb.CreateException,java.rmi.RemoteException;

    In case of Local Access EJBs it creates the following code

       public static final String COMP_NAME="java:comp/env/ejb/Test1Local";
       public static final String JNDI_NAME="Test1Local";
    
       public dcse.interfaces.Test1Local create()
          throws javax.ejb.CreateException;

    Is this difference in JNDI_NAME creating the problem???

    Please advice me ..Iam facing this problem since couple of days and our project is based in MyEclipse..

    Priya

    #247558 Reply

    saloni.priya
    Member

    No clue ???

    #247604 Reply

    Greg
    Member

    Hello Priya,

    Sorry for the delay. We have been pretty busy trying to get 4.1.1 out the door.

    Anyways, for your EJB problem. Try specifying a local-jndi-name in your xdoclet tags:

    local-jndi-name="ejb/Test1Local"

    So adding to your previous example, the xdoclet tags for your Test1Bean.java would look like the following:

     * @ejb.bean name="Test1"
     *           display-name="Name for Test1"
     *           description="Description for Test1"
     *           jndi-name="ejb/Test1"
     *           type="Stateless"
     *           view-type="local" 
     *           local-jndi-name="ejb/Test1Local"

    After making this change, re-run XDoclet and then your JNDI_NAME should contain a value that you can use for local connections. Hope this helps.

    #247619 Reply

    saloni.priya
    Member

    Hello Greg Thanks For your reply,

    Anyways, for your EJB problem. Try specifying a local-jndi-name in your xdoclet tags:

    local-jndi-name=”ejb/Test1Local”

    Where exactly i need to add this line of code??

    Priya

    #247621 Reply

    saloni.priya
    Member

    Ok i need to add it to Test1Bean.java.

    #247625 Reply

    saloni.priya
    Member

    Iam still getting the following problem with the new changes

    javax.naming.NameNotFoundException: Context: WKLGK332/nodes/WKLGK332/servers/server1, name: ejb/Test1Local: First component in name Test1Local not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]

    Priya

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: EJB’s(Gen with MyEclipse)/With Local Access Not Working.

You must be logged in to post in the forum log in