Announcement Announcement Module
Collapse
No announcement yet.
Massively enabling an Advisor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Massively enabling an Advisor

    I have a bunch o' beans that are EJBs that are defined using a common parent that defines their "EJBness". Here's an example of Foo, with his parent:
    Code:
      <bean id="ejb" abstract='true' class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean" lazy-init="true">
        <property name="jndiTemplate" ref="self-jndi"/>
        <property name="refreshHomeOnConnectFailure" value="true"/>
      </bean>
    
      <bean id="Foo" parent="ejb" lazy-init="true">
        <property name="jndiName" value="FooHome/>
        <property name="businessInterface" value="com.enttek.Foo"/>
      </bean>
    Now, I have an advisor I wish to add to all of my EJBs. I know I can do this by redefining each Foo, but I really don't want to have to do that. Is there a practical way to add an advisor to an abstract bean definition based on a non-ProxyFactoryBean factoryBean?

    In some way, I think I'm asking for multiple inheritance in the XML.

    Thanks
    David

  • #2
    Fortunately SimpleRemoteStatelessSessionProxyFactoryBean is a subclass of an interceptor which does the same thing. Use ProxyFactoryBean as the bean class and add SimpleRemoteSlsbInvokerInterceptor as part of your interceptors.

    Comment


    • #3
      David,

      Please post the configuration if you get this to work. I am interested in something similar for the HttpInvoker, but could not get it to work. Here is my thread if there is any interest:

      http://forum.springframework.org/showthread.php?t=21775

      Jess

      Comment


      • #4
        Originally posted by wpoitras
        Fortunately SimpleRemoteStatelessSessionProxyFactoryBean is a subclass of an interceptor which does the same thing. Use ProxyFactoryBean as the bean class and add SimpleRemoteSlsbInvokerInterceptor as part of your interceptors.
        That will still force me to redefine all the "concrete" EJB beans specifying a target, and specifying the interface twice (once as the BusinessInterface, and once as a proxyInterface), will it not?

        David

        Comment


        • #5
          No. businessInterface is not a property of SimpleRemoteSlsbInvokerInterceptor. Its probably implied from the proxied interface.

          Comment


          • #6
            Is there an example anywhere that I can refer to?

            Comment


            • #7
              It would look something like this. Since the EJB invocation is the "real work" I've used it as the target instead of one of the interceptors.

              Code:
              <bean id="proxyTemplate" abstract="true" class="org.springframework.aop.framework.ProxyFactoryBean">
                <property name="interceptorNames">
                  <list>
                    <idref local="interceptor1"/>
                    <idref local="interceptor2"/>
                    <idref local="interceptor3"/>
                  </list>
                </property>
              </bean>
              
              <bean id="slsbTemplate" abstract="true" class="org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor">
                <property name="jndiEnvironment">
                  <props>
                    <!-- Here you put your JNDI connection properties -->
                    <entry key=""></entry>
                  </props>
                </property>
                <!-- Any other properties you may want to change from the defaults. i.e. lookupHomeOnstartup -->
              </bean>
              
              <!-- Your beans go here -->
              <bean id="myObject" parent="proxyTemplate>
                <property name="proxiedInterfaces" value="com.mycompany.MyManager"/>
                <property name="target">
                  <bean parent="slsbTemplate>
                    <property name="jndiName" value="ejb/MyObject"/>
                  </bean>
                </property>
              </bean>
              
              <!-- Definition of interceptor1, 2 and 3 should go here -->
              Another way (and thinking about it probably simpler) would be use a BeanNameAutoProxyCreator:

              Code:
                <bean id="ejb" abstract='true' class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean" lazy-init="true">
                  <property name="jndiTemplate" ref="self-jndi"/>
                  <property name="refreshHomeOnConnectFailure" value="true"/>
                </bean>
              
                <bean id="Foo" parent="ejb" lazy-init="true">
                  <property name="jndiName" value="FooHome/>
                  <property name="businessInterface" value="com.enttek.Foo"/>
                </bean>
              
                <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
                <property name="beanNames">
                  <!-- This can be either a list of exact names or wildcards or both
                  <idref local="Foo"/>
                  <value>myBean*</value>
                </property>
                <property name="interceptorNames">
                  <list>
                    <idref local="interceptor1"/>
                    <idref local="interceptor2"/>
                    <idref local="interceptor3"/>
                  </list>
                </property>
              </bean>

              Comment


              • #8
                The first option still requires me to rewrite all my bean definitions.

                The second one has potential, though I'm also concerned about "error-proneness". (i.e., beans being left out.)

                Comment


                • #9
                  About the only other alternative I can think of would be write a subclass of a ProxyFactory bean that accepts the properties of the SimpleRemoteSlsbInvokerInterceptor and constructs a SimpleRemoteSlsbInvokerInterceptor and sets it as the target.

                  Comment


                  • #10
                    Second configuration does not work

                    I came here just because I have the same configuration as you show here (2nd one) and it is not working. It's like I can't "advice" (or pointcut, I'm not very familiar with AOP terminology) a ProxyFactoryBean.

                    Is this a Bug or is it a known and accepted behaviour?

                    Thanks

                    Comment


                    • #11
                      First example

                      First example is returning the Interceptor instead of my interface when using context.getBean(), maybe I am doing something wrong, but I don't know.

                      If I get to anything I'll post it here.

                      Regards
                      AB

                      Comment


                      • #12
                        Fixed!

                        I finally ended with using the first of the options but instead of the org.springframework.ejb.access.SimpleRemoteSlsbInv okerInterceptor I used org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean. The bad thing is that I am repeating the service interface, since I am actually using two ProxyFactoryBeans. It would be nice if the SrssProxyFactoryBean could have an 'interceptorNames' field or similar.

                        Regards!
                        AB

                        Comment

                        Working...
                        X