Announcement Announcement Module
No announcement yet.
Accessing local SLSBs: does local interface still extend EJBLocalObject? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing local SLSBs: does local interface still extend EJBLocalObject?


    Just reading the manual here, it describes the process of using a spring proxy to hide the jndi home lookup:

    17.1.2. Accessing local SLSBs

    Assume that we have a web controller that needs to use a local EJB. We’ll follow best practice and use the EJB Business Methods Interface pattern, so that the EJB’s local interface extends a non EJB-specific business methods interface. Let’s call this business methods interface MyComponent.

    public interface MyComponent {

    (One of the main reasons to the Business Methods Interface pattern is to ensure that synchronization between method signatures in local interface and bean implementation class is automatic. Another reason is that it later makes it much easier for us to switch to a POJO (plain java object) implementation of the service if it makes sense to do so) Of course we’ll also need to implement the local home interface and provide a bean implementation class that implements SessionBean and the MyComponent business methods interface. Now the only Java coding we’ll need to do to hook up our web tier controller to the EJB implementation is to expose a setter method of type MyComponent on the controller. This will save the reference as an instance variable in the controller:

    private MyComponent myComponent;

    public void setMyComponent(MyComponent myComponent) {
    this.myComponent = myComponent;

    We can subsequently use this instance variable in any business method in the controller. Now assuming we are obtaining our controller object out of a Spring ApplicationContext or BeanFactory, we can in the same context configure a LocalStatelessSessionProxyFactoryBean instance, which will be 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:

    <bean id="myComponent"
    class="org.springframework.ejb.access.LocalStatele ssSessionProxyFactoryBean">
    <property name="jndiName" value="myComponent"/>
    <property name="businessInterface" value="com.mycom.MyComponent"/>

    <bean id="myController" class="com.mycom.myController">
    <property name="myComponent" ref="myComponent"/>
    This may seem like a silly question (maybe I just don't understand the pattern) but is the local interface still created manually?

    If so, what should the local interface extend? 'MyComponent' or 'EJBLocalObject'? If it extends 'MyComponent' then where does the 'EJBLocalObject' fit in to the picture?

    Thanks in advance!


  • #2
    The local interface should extend both your (EJB unaware) business interface and EJBLocalObject.

    The first one defines the methods you actually publish and the latter one is required by EJB.



    • #3
      After learning things the spring way, I've seperated my business object and its business interface entirely from the EJB stuff. The XML files, EJB Home and EJB interface are now generated via xdoclet from annotations in the Bean class. To me its just plumbing.

      But after you generate all the source, you do end up with two versions of your interface: your business object interface (which you wrote) and the EJB one (which is derived from xdoclet tags). The client code which uses your object should only ever know about the business interface. The EJB interface is meerly an implementation detail. If you switched from EJB to Hessian/RMI/JMX or any other remoting package your client code wouldn't change, just the client proxy in the XML file.


      • #4
        Interesting. So are you using xdoclet to generate the 'plumbing' classes from tags declared in the ejb bean class?

        Can you clarify what you mean by xdoclet generating two interfaces?



        • #5
          EJBException and LocalStatelessSessionProxy?

          How are EJBExceptions thrown by the ejb container during invocation on a local slsb instance handled by LocalStatelessSessionProxyFactoryBean in the client ?


          • #6
            Originally posted by jim
            Interesting. So are you using xdoclet to generate the 'plumbing' classes from tags declared in the ejb bean class?

            Can you clarify what you mean by xdoclet generating two interfaces?
            An EJB needs two interfaces to access them: The Home interface and the bean interface. I generate these two interfaces using XDoclet. Check out this thread for more details. What you are responsible for writing is:
            - Your business (non-EJB) interface
            - Your business implementation
            - Your EJB implementation which delegates to your business implementation.