Announcement Announcement Module
Collapse
No announcement yet.
Looking for simple EJB remote client example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looking for simple EJB remote client example

    Hi,

    I'm new to spring and I am looking for an end to end example of how to perform a lookup on an existing remote EJB.

    Thanks

    J

  • #2
    18.2. Accessing EJBs

    Comment


    • #3
      I've gone over that document several time. There are a few things missing from it.
      1. How to enter a remote host and port
      2. How to get an instance to the EJB in your code (example code)
      3. How to specify a particular vendor, say Websphere or Weblogic
      4. An example of what kind of code needs to go into the interface of MyComponent
      5. How to make a call to an EJB method that requires parameters

      These may seem like simple enough requests that don't require to be documented, but someone who is completely new to Spring will have a hard time finding this info.

      Thanks

      J

      Comment


      • #4
        Originally posted by shampoo View Post
        I've gone over that document several time. There are a few things missing from it.
        1. How to enter a remote host and port
        2. How to get an instance to the EJB in your code (example code)
        3. How to specify a particular vendor, say Websphere or Weblogic
        4. An example of what kind of code needs to go into the interface of MyComponent
        5. How to make a call to an EJB method that requires parameters

        These may seem like simple enough requests that don't require to be documented, but someone who is completely new to Spring will have a hard time finding this info.

        Thanks

        J
        Spring doesn't introduce any magic to the EJB client. It just wraps boilerplate stuff - 18.2.1. Concepts
        To invoke a method on a local or remote stateless session bean, client code must normally perform a JNDI lookup to obtain the (local or remote) EJB Home object, then use a 'create' method call on that object to obtain the actual (local or remote) EJB object. One or more methods are then invoked on the EJB.

        To avoid repeated low-level code, many EJB applications use the Service Locator and Business Delegate patterns. These are better than spraying JNDI lookups throughout client code, but their usual implementations have significant disadvantages.
        ...
        The Spring approach is to allow the creation and use of proxy objects, normally configured inside a Spring container, which act as codeless business delegates. You do not need to write another Service Locator, another JNDI lookup, or duplicate methods in a hand-coded Business Delegate unless you are actually adding real value in such code.
        That's it. If you're able to call EJB method using 'pure' EJB, i.e. lookup the EJB home, create EJB proxy and call the method on it, you're able to do the same with the spring but hiding the common stuff via standard config elements. So, the question is - did you write the code for EJB manual lookup and call? As soon as you write the one, you may move the common stuff to the spring config and get the same result.

        Comment


        • #5
          Originally posted by denis.zhdanov View Post
          So, the question is - did you write the code for EJB manual lookup and call? As soon as you write the one, you may move the common stuff to the spring config and get the same result.
          I have working code whereby a client makes a call to an EJB. The EJB is remote. This works fine.

          What I don't have is an example of how to 'springify' this code.

          The documentation lists brief code snippets and general ideas. I need more hand holding then this.

          J

          Comment


          • #6
            Originally posted by shampoo View Post
            I have working code whereby a client makes a call to an EJB. The EJB is remote. This works fine.

            What I don't have is an example of how to 'springify' this code.

            The documentation lists brief code snippets and general ideas. I need more hand holding then this.

            J
            Documentation is quite clear about 'springified' EJB usage. 18.2.2. Accessing local SLSBs:
            we can ... configure a LocalStatelessSessionProxyFactoryBean instance, which will be the EJB proxy object. The configuration of the proxy, and setting of the myComponent property of the controller is done with a configuration entry such as:
            HTML Code:
            <bean id="myComponent"
                  class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
              <property name="jndiName" value="ejb/myBean"/>
              <property name="businessInterface" value="com.mycom.MyComponent"/>
            </bean>
            I.e. you can remove all the boilerplate code that performs EJB home lookup and creates EJB proxy and exploit LocalStatelessSessionProxyFactoryBean for that.

            About remote EJB proxy retrieval - 18.2.3. Accessing remote SLSBs:
            Accessing remote EJBs is essentially identical to accessing local EJBs, except that the SimpleRemoteStatelessSessionProxyFactoryBean or <jee:remote-slsb> configuration element is used. Of course, with or without Spring, remote invocation semantics apply; a call to a method on an object in another VM in another computer does sometimes have to be treated differently in terms of usage scenarios and failure handling.

            Comment


            • #7
              Thanks, but that really doesn't address any of my previous question. So let's deal with a concrete example.

              I have an EJB deployed on Websphere 6.1. I am able to create it from a client and make calls on it using IIOP.

              Here's my spring config for this entry:

              Code:
              bean id="clientServicesBean"
              	class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
              	<property name="jndiName">
              		<value>
              			ejb/com/xxx/service/command/ejb/ClientServicesEjbHome
              		</value>
              	</property>
              	<property name="businessInterface">
              		<value>com.xxx.service.command.ejb.ClientServicesEjb</value>
              	</property>
              	<property name="homeInterface">
              		<value>
              			com.xxx.service.command.ejb.ClientServicesEjbHome
              		</value>
              	</property>
              	<property name="jndiEnvironment">
              		<props>
              			<prop key="java.naming.factory.initial">
              				com.ibm.websphere.naming.WsnInitialContextFactory
              			</prop>
              			<prop key="java.naming.provider.url">
              				iiop://vclaba13.lab.xxx.com:2809
              			</prop>
              		</props>
              	</property>
              </bean>
              Here is the call to Spring to load the bean:

              Code:
              ApplicationContext applicationContext = new ClassPathXmlApplicationContext("WEB-INF/jndi.xml");
                      
                      clientServicesEjb = (ClientServicesEjb) applicationContext.getBean("clientServicesBean");
              Which results in the error:

              Code:
              com.sun.faces.lifecycle.InvokeApplicationPhase execute org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientServicesBean' defined in class path resource [WEB-INF/jndi.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Context: vclaba13Node01Cell/nodes/vclaba13Node01/servers/server1, name: 
              			ejb/com/xxx/service/command/ejb/ClientServicesEjbHome
              		: First component in name 
              			ejb/com/xxx/service/command/ejb/ClientServicesEjbHome
              		 not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
                                               javax.faces.el.EvaluationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientServicesBean' defined in class path resource [WEB-INF/jndi.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Context: vclaba13Node01Cell/nodes/vclaba13Node01/servers/server1, name: 
              			ejb/com/xxx/service/command/ejb/ClientServicesEjbHome
              		: First component in name 
              			ejb/com/xxx/service/command/ejb/ClientServicesEjbHome
              		 not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
              But that JNDI name exists. It's a copy paste from my code when I 'manually' fetched the bean.

              J

              Comment


              • #8
                You can try:

                <property name="jndiName" value="ejb/com/xxx/service/command/ejb/ClientServicesEjbHome"/>
                instead of the old form with elements.

                Comment


                • #9
                  Originally posted by shampoo View Post
                  ...
                  But that JNDI name exists. It's a copy paste from my code when I 'manually' fetched the bean.
                  J
                  There is no magic at the spring. It's not possible that manual approach works and spring-based approach with the same settings doesn't work. There must be a difference then.

                  Comment


                  • #10
                    Originally posted by dejanp View Post
                    You can try:



                    instead of the old form with elements.
                    That fixed it.

                    Thanks for all your help.

                    J

                    Comment


                    • #11
                      Originally posted by shampoo View Post
                      That fixed it.

                      Thanks for all your help.

                      J
                      'value' attribute provides the same semantic as <value> element, i.e. you can have the same working example via the following config switch:
                      HTML Code:
                      	<property name="jndiName">
                      		<value>ejb/com/xxx/service/command/ejb/ClientServicesEjbHome</value>
                      	</property>
                      The only problem is that your initial property definition contained new line and blank symbols.

                      Comment


                      • #12
                        Yes, xml formating is a dangerous thing. Bringing production systems totally offline by reformating a single xml file is not unheard of.

                        Comment


                        • #13
                          The world is a dangerous place at all

                          Comment

                          Working...
                          X