Announcement Announcement Module
Collapse
No announcement yet.
Accessing a STATEFUL Session Bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing a STATEFUL Session Bean

    Hello everyone,

    I have been searching for examples on how to configure Spring to return the Remote interface for a STATEFUL Session Bean and have been unsuccessful. Its easy to do with a Stateless Session bean using the <jee:remote-slsb/> tag. Is there something similar to help with Stateful beans?

    Any examples would be excellent.

  • #2
    Afaik SFSB support is not provided to the same extend as SLSB support. Mostly because of the initialization and remove issues it entails.

    But you can have a look at the Jira issue I referred to in another post.

    I provided implementation classes there which include a SimpleRemoteStatefulSessionProxyFactoryBean. It is to be used the same as its stateless counterpart. The only difference is, that prior to using the returned bean and after finished using it the appropriate SfsbHelper-methods have to be invoked (class also contained in the sources).

    Hope that helps,
    Andreas

    Comment


    • #3
      That's what I'm doing with JBoss 4.x...
      Code:
      <bean
              id="parentEJB"
              abstract="true"
              lazy-init="true"
              class="&JndiObjectFactoryBean;">
              <property
                  name="jndiEnvironment"
                  ref="securedEnvironment" />
          </bean>
          <bean
              name="initSFSB"
              parent="parentEJB"
              scope="prototype">
              <property
                  name="jndiName"
                  value="${jndi.ejb.init}" />
          </bean>
      jndi.ejb.init=jspring/InitBean/remote

      Works like a charm.

      Cheers.

      Comment


      • #4
        Documentation/Example

        For Andreas - I have downloaded the zip file from the jira forum you mentioned. Is there anywhere that I can find further documentation on this. An example of using the SimpleRemoteStatefulSessionProxyFactoryBean would be very helpful.

        -- Bruce

        Comment


        • #5
          Hello Bruce,

          first, a general example of the concept is decribed in this post (maybe you already saw it, as I also posted a link to the thread to Jira).

          At the moment I have no example for SFSB at hand, but it is easily explained.

          The configuration of the SimpleRemoteStatefulSessionProxyFactoryBean is exactly as its stateless counterpart. The difference is in its usage. While you can use a stateless proxy directly after injection and do not care about it, you need to initialize the stateful proxy first and have to deinitialize it afterwards. This corresponds to the parameterized invocation of create() before and the required invocation of remove() after using an SFSB.

          If you, for example have a FooService (which is your business interface of the SFSB) your code might look like that:

          Code:
            public class Client {
                // gets injected via Spring as SimpleRemoteStatefulSessionProxyFactoryBean
                private FooService;
          
                // ...
          
                public void doSomething() {
          
                    // assuming that the SFSB's create method takes a String and an int/Integer parameter
                    SfsbHelper.initSfsbInstance(this.fooService, new Object[] {"Hello", new Integer(42)};
          
                    // invoke some method on the now initialized service
                    String result = this.fooService.bar(new Date());
          
                    // the service might be used further
          
                    // Not required to initialize/remove inside the same method but remove has to be called
                    SfsbHelper.removeSfsbInstance(this.fooService);
          
                    // fooService is still a valid proxy here, but to invoke methods on it,
                    // it has to be initialized again as shown above
                }
          }
          I hope that makes it a bit clearer. If not, just follow up on this post.
          And if you find this approach useful, feel free to vote for it on Jira

          Regards,
          Andreas

          Comment


          • #6
            Help with deployment problem -- and thanks

            Andreas, Thanks for the reply. I was unclear as to whether you could have the proxy injected into your class or had to do somehting else to get it, your post cleared that up. I have one other thing you could help me with. I took the source files you provided, compiled them and put them in a spring-extensions.jar file, which I included in my EAR file. I then configured my webApplicatoinContext.xml the same as for a statless sesson bean, but change the class to the stateful proxy. Everything went fine until I tried to access the bean (I have lazy-init = true), then I get the ClassNotFoundException listed below. Is there something else I should be doing?

            org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/statefulService1' defined in ServletContext resource [/WEB-INF/webapplicationcontext.xml]: Cannot resolve reference to bean 'statefulServiceController' while setting bean property 'serviceController'; nested exception is org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.springframework.ejb.access.SimpleRemoteStatefu lSessionProxyFactoryBean] for bean with name 'statefulServiceController' defined in ServletContext resource [/WEB-INF/webapplicationcontext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.ejb.access.SimpleRemoteStatefu lSessionProxyFactoryBean

            - Bruce

            Comment


            • #7
              I got past this error so don't bother to reply. -- Bruce

              Comment

              Working...
              X