Results 1 to 5 of 5

Thread: Why we need Home and Remote for EJB clients using JNDITempla

  1. #1
    Join Date
    Dec 2004
    Posts
    22

    Default Why we need Home and Remote for EJB clients using JNDITempla

    Hi

    I am using JNDI template to look up EJB.
    My ejb-jar.xml is as follows

    <session >
    <description><![CDATA[Description for Customer]]></description>
    <display-name>Name for Customer</display-name>

    <ejb-name>Customer</ejb-name>

    <home>com.sf.ejb.CustomerHome</home>
    <remote>com.sf.ejb.Customer</remote>
    <ejb-class>com.sf.ejb.CustomerBean</ejb-class>
    <session-type>Stateless</session-type>
    <transaction-type>Container</transaction-type>

    <env-entry>
    <env-entry-name>ejb/BeanFactoryPath</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value><![CDATA[/spring-config-server.xml]]></env-entry-value>
    </env-entry>

    </session>


    CustomerBean implements ICustomer which is the business logic interface.

    I am using JNDI template with SimpleRemoteStatelessSessionProxyFactoryBean.

    In my client I see no trace of Home and Remote interface.

    Only the ICustomer is used cast the lookedup bean.


    If i delete the Home and Remote interfaces from classpath, i get an exception.

    Can someone explain , how the Home and remote interfaces work woth Proxy and Jndi template.

    My Client config.xml

    <beans>
    <bean id="jndiTemplate"
    class="org.springframework.jndi.JndiTemplate">
    <constructor-arg>
    <props>
    <prop key="java.naming.factory.initial">org.jnp.interfac es.NamingContextFactory</prop>
    <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
    <prop key="java.naming.factory.url.pkgs">org.jboss.namin g:org.jnp.interfaces</prop>
    </props>
    </constructor-arg>
    </bean>

    <bean id="customerEjb"
    class="org.springframework.ejb.access.SimpleRemote StatelessSessionProxyFactoryBean">
    <property name="jndiTemplate"><ref bean="jndiTemplate"/></property>
    <property name="jndiName">
    <value>ejb/Customer</value>
    </property>
    <property name="businessInterface">
    <value>com.sf.intf.ICustomer</value>
    </property>
    </bean>



    </beans>



    My Client Code

    ClassPathXmlApplicationContext appContext =
    new ClassPathXmlApplicationContext(
    new String[] {"spring-config-client.xml"});

    BeanFactory factory = (BeanFactory) appContext;


    //ejb test

    // Try 1
    try{
    ICustomer customer1=(ICustomer)factory.getBean("customerEjb" );
    System.out.println(customer1.getCustomer(6));
    ICustomer customer2=(ICustomer)factory.getBean("customerEjb" );
    if(customer1==customer2)
    System.out.println("Singleton");
    else
    System.out.println("Non Singleton");
    System.out.println(customer2.getCustomer(10));

    }catch(Exception e)
    {
    e.printStackTrace();
    }


    Thanks
    Kevin

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    I am using JNDI template with SimpleRemoteStatelessSessionProxyFactoryBean.

    In my client I see no trace of Home and Remote interface.

    Only the ICustomer is used cast the lookedup bean.
    What you're describing is Spring's success in abstracting away the client side of the clunky EJB contract. However, the remote and home interfaces are still required: Spring is using them under the covers, just as you would if you had to write the JNDI lookup, EJB home.create call yourself. What Spring is doing behind the scenes is a JNDI lookup for the home, then calling the create() method on the home and enabling you to work with that.

    The requirement for home and remote interfaces does not relate to Spring, but is part of the EJB contract.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Dec 2004
    Posts
    22

    Default

    Hi Rod,

    Thanks for anwsering my queries.

    BTW , i throughly impressed with the capabulities of Spring.

    Hats off to you and others on creating a superlative framework.

    Kevin


    Quote Originally Posted by Rod Johnson
    I am using JNDI template with SimpleRemoteStatelessSessionProxyFactoryBean.

    In my client I see no trace of Home and Remote interface.

    Only the ICustomer is used cast the lookedup bean.
    What you're describing is Spring's success in abstracting away the client side of the clunky EJB contract. However, the remote and home interfaces are still required: Spring is using them under the covers, just as you would if you had to write the JNDI lookup, EJB home.create call yourself. What Spring is doing behind the scenes is a JNDI lookup for the home, then calling the create() method on the home and enabling you to work with that.

    The requirement for home and remote interfaces does not relate to Spring, but is part of the EJB contract.

  4. #4
    Join Date
    Dec 2004
    Posts
    22

    Default

    Just another question.

    How does JNDITemplate/SimpleRemoteStatelessSessionProxyFactoryBean know what is the name of the Home and the remote interface , my client configuration xml does not map the names other than the deployed ejb name.

    Thanks
    Navin

    Quote Originally Posted by kevin_405
    Hi Rod,

    Thanks for anwsering my queries.

    BTW , i throughly impressed with the capabulities of Spring.

    Hats off to you and others on creating a superlative framework.

    Kevin


    Quote Originally Posted by Rod Johnson
    I am using JNDI template with SimpleRemoteStatelessSessionProxyFactoryBean.

    In my client I see no trace of Home and Remote interface.

    Only the ICustomer is used cast the lookedup bean.
    What you're describing is Spring's success in abstracting away the client side of the clunky EJB contract. However, the remote and home interfaces are still required: Spring is using them under the covers, just as you would if you had to write the JNDI lookup, EJB home.create call yourself. What Spring is doing behind the scenes is a JNDI lookup for the home, then calling the create() method on the home and enabling you to work with that.

    The requirement for home and remote interfaces does not relate to Spring, but is part of the EJB contract.

  5. #5
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by kevin_405
    How does JNDITemplate/SimpleRemoteStatelessSessionProxyFactoryBean know what is the name of the Home and the remote interface , my client configuration xml does not map the names other than the deployed ejb name.
    Simple: It does not know. :wink:

    In the specified JNDI location Spring expects an instance of EJBHome which it uses to create the session bean, invoking the create()-method via reflection.
    The type Spring uses for its proxy is declared as businessInterface property in your factory bean. The methods of this proxy are also mapped to the created session bean using reflection.
    So using reflection allows Spring to be not aware of the concrete home-interface type or remote-interface type.

    Regards,
    Andreas

Similar Threads

  1. Replies: 8
    Last Post: Aug 13th, 2007, 12:00 PM
  2. Replies: 3
    Last Post: Sep 22nd, 2005, 10:14 AM
  3. home and remote interfaces
    By djeang in forum EJB
    Replies: 1
    Last Post: Dec 19th, 2004, 11:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •