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
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
I've gone over that document several time. There are a few things missing from it.
- How to enter a remote host and port
- How to get an instance to the EJB in your code (example code)
- How to specify a particular vendor, say Websphere or Weblogic
- An example of what kind of code needs to go into the interface of MyComponent
- 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
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.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.
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:I.e. you can remove all the boilerplate code that performs EJB home lookup and creates EJB proxy and exploit LocalStatelessSessionProxyFactoryBean for that.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>
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.
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:
Here is the call to Spring to load the bean: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>
Which results in the error:Code:ApplicationContext applicationContext = new ClassPathXmlApplicationContext("WEB-INF/jndi.xml"); clientServicesEjb = (ClientServicesEjb) applicationContext.getBean("clientServicesBean");
But that JNDI name exists. It's a copy paste from my code when I 'manually' fetched the bean.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]
J
You can try:
instead of the old form with elements.<property name="jndiName" value="ejb/com/xxx/service/command/ejb/ClientServicesEjbHome"/>