Announcement Announcement Module
Collapse
No announcement yet.
Why we need Home and Remote for EJB clients using JNDITempla Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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


      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.

      Comment


      • #4
        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

        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


        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.

        Comment


        • #5
          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

          Comment

          Working...
          X