Results 1 to 3 of 3

Thread: Intercepting a pooled object

  1. #1

    Default Intercepting a pooled object

    Hi springers. I have a problem with the subject.
    So, I have a request processor bean:
    Code:
    <bean id="cifRequestProcessor" class="com.express.web.rc.cif.CifRequestProcessor" scope="prototype"/>
    this class extends the AbstractRequestProcessor class.

    Then I have pooled that bean as follow:
    Code:
    	<bean id="cifProcessorCommonPoolProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
    	    <property name="targetSource" ref="cifProcessorCommonTargetSource"/>
    	    <property name="proxyTargetClass" value="true"/>
    	</bean>
    	
    	<bean id="cifProcessorCommonTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
    	   <property name="maxSize" value="10"/>
    	   <property name="targetBeanName" value="cifRequestProcessor"/>
    	</bean>
    Then, we have a class ServiceProcessorFactory which contains Map with the different request processors, and this map is populated in the Spring context file:
    Code:
      <bean id="serviceProcessorFactory"
          class="com.express.web.rc.util.ServiceProcessorFactory">
        <property name="requestProcessors">
          <map>
    <entry key="CIF">
            	<ref bean="cifProcessorCommonPoolProxy"/>
            </entry>
    <!-- Here are other entries for athe processors -->
          </map>
        </property>
      </bean>
    As you can see I populate the map with the PoolProxy (not direct with the processor it self. And it works perfect in the code:
    Code:
    AbstractRequestProcessor processor =
                    (AbstractRequestProcessor) _requestProcessors.get(requestType);
    where _requestProcessors is the Map.

    Now, I desided to intercept the processor's processRequest and added the vollowing configuration to the spring context:
    Code:
    <bean id="cifAspect" class="com.spring.aspect.CifAspect"/>
          
        <aop:config>
        	<aop:pointcut id="cifProcessRequest" expression="execution(* com.express.web.rc.cif.CifRequestProcessor.processRequest(..))"/>
        	<aop:aspect ref="cifAspect">
        		<aop:before pointcut-ref="cifProcessRequest" method="validateBrBeforeCifProcessRequest"/>
        	</aop:aspect>
        </aop:config>
    and, when I run the application, in the line: AbstractRequestProcessor processor =
    (AbstractRequestProcessor) _requestProcessors.get(requestType);
    I have the exception:
    Code:
    ClassCastException: Cannot cast $Proxy9(id=209) to com.express..web.rc.AbstractRequestProcessor.
    So, before I added this adviser to the context it worked perfect. Why now I have this ClassCastException, and what to do to make it works?

    THANKS IN ADVANCE.

  2. #2
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by Yasson View Post
    when I run the application, in the line: AbstractRequestProcessor processor =
    (AbstractRequestProcessor) _requestProcessors.get(requestType);
    I have the exception:
    Code:
    ClassCastException: Cannot cast $Proxy9(id=209) to com.express..web.rc.AbstractRequestProcessor.
    You are using JDK dynamic proxies which works on interfaces, but your request processors are probably only extending AbstractRequestProcessor, but don't implement a RequestProcessor interface. You now have the two choices of either introducing this interface or switching to class-based CGLib proxies.

    Joerg
    This post can contain insufficient information.

  3. #3

    Default

    Quote Originally Posted by Jörg Heinicke View Post
    You are using JDK dynamic proxies which works on interfaces, but your request processors are probably only extending AbstractRequestProcessor, but don't implement a RequestProcessor interface. You now have the two choices of either introducing this interface or switching to class-based CGLib proxies.

    Joerg
    Hi Joerg. Thanks for reply.
    My AbstractRequestProcessor implements the RequestProcessor interface. But in old existing code, any XXXRequestProcessor class when it is retreived from the map is casted to the AbstractRequestProcessor, not to the RequestProcessor interface. So, I have to use
    Code:
    <property name="proxyTargetClass" value="true"/>
    when I proxy my CommonsPoolTargetSource. Otherwise, I'll have again ClassCastException when code casts the retreived object to AbstractRequestProcessor class instead of to RequestProcessor interface.

    Then, I tried to chage my aop:config tag in this way:
    Code:
    <aop:config proxy-target-class="false">
    but with no luck. As I understood in this case this tag tries to proxy other proxy and gives me the following exception:

    Code:
    WebModule[/mosAppWar]: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    	org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gcdRequestService' defined in ServletContext resource [/WEB-INF/SpringApplicationContext.xml]: Cannot create inner bean 'com.filogix.externallinks.services.RequestService#10ab78a' of type [com.filogix.externallinks.services.RequestService] while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.filogix.externallinks.services.RequestService#10ab78a' defined in ServletContext resource [/WEB-INF/SpringApplicationContext.xml]: Cannot resolve reference to bean 'bncGcdPayloadGenerator' while setting bean property 'payloadGenerator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bncGcdPayloadGenerator' defined in ServletContext resource [/WEB-INF/SpringApplicationContext.xml]: Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy0]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy0
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:213)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1193)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:961)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:507)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:246)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:166)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:345)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:689)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:358)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3255)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:3575)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:638)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:345)
    	at org.apache.catalina.startup.Embedded.start(Embedded.java:957)
    	at com.iplanet.ias.web.WebContainer.start(WebContainer.java:426)
    	at com.iplanet.ias.web.WebContainer.startInstance(WebContainer.java:514)
    	at com.iplanet.ias.server.J2EERunner.confPostInit(J2EERunner.java:170)
    Last edited by Yasson; Sep 18th, 2007 at 01:53 PM.

Posting Permissions

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