Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Massively enabling an Advisor

  1. #1

    Default 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. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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.
    Bill

  3. #3
    Join Date
    Nov 2005
    Location
    Chicago
    Posts
    122

    Default

    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

  4. #4

    Default

    Quote 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

  5. #5
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

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

  6. #6

    Default

    Is there an example anywhere that I can refer to?

  7. #7
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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>
    Bill

  8. #8

    Default

    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.)

  9. #9
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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.
    Bill

  10. #10

    Default 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •