Announcement Announcement Module
Collapse
No announcement yet.
PRoblem with ChannelInterceptor and autowiring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • PRoblem with ChannelInterceptor and autowiring

    Hallo all.
    I have this context file:

    Code:
    <int:gateway id="onlineMessageGateway" service-interface="it.alten.intesasanpaolo.contratto.online.gateway.OnlineMessageGateway" default-request-channel="onlineMessagePreProcessingChannel"/>
    		
    	<int:channel id="onlineMessagePreProcessingChannel" datatype="it.alten.intesasanpaolo.contratto.domain.event.OnlineEventMessage">
    		<int:interceptors>
    			<ref bean="onlineEventMessagePersisterInterceptor"/>
    			<ref bean="onlineEventMessageHeaderEnricher"/>
    		</int:interceptors>
    	</int:channel>
    	<bean id="onlineEventMessagePersisterInterceptor" class="it.alten.intesasanpaolo.contratto.online.interceptor.EventMessagePersisterInterceptor">
    		<property name="eventMessageHelper" ref="eventMessageHelper"></property>		
    	</bean>	
    	<bean id="onlineEventMessageHeaderEnricher" class="it.alten.intesasanpaolo.contratto.online.interceptor.EventMessageHeaderEnricherInterceptor"/>
    	
    	<bean id="eventMessageHelper" class="it.alten.intesasanpaolo.contratto.online.helper.OnlineEventMessageHelper"/>
    			
    	<int:chain input-channel="onlineMessagePreProcessingChannel">
    		<int:filter discard-channel="discardOnlineEventMessageChannel" ref="onlinePreProcessingFilter" />
    		<int:router ref="onlineMessageRouter" method="route" default-output-channel="ONLINE_NO_OPERATION"/>
    	</int:chain>
    
    	<bean id="onlineMessageRouter" class="it.alten.intesasanpaolo.contratto.online.router.OnlineMessageRouter"/>	
    	<bean id="onlinePreProcessingFilter" class="it.alten.intesasanpaolo.contratto.online.filter.PreProcessingFilter" />
    This is the onlineMessageHelper

    Code:
    public class OnlineEventMessageHelper {
    	private final static Logger logger = LoggerFactory.getLogger(OnlineEventMessageHelper.class);
    	
    	@Autowired
    	@Qualifier("eventMessageDao")
    	private GenericDao<EventMessage<?>, Long> eventMessageDao;
    And this the preProcessingFilter

    Code:
    public class PreProcessingFilter implements MessageSelector {
    	private final static Logger logger = LoggerFactory.getLogger(PreProcessingFilter.class);
    
    	@Autowired
    	@Qualifier("anagraficaParser")
    	private DomainStringParser<EventMessageAnagrafica> anagraficaParser;
    
    	@Autowired
    	@Qualifier("utentePilotaDao")
    	private UtentePilotaDao utentePilotaDao;
    I dunno why anything I define as autowiring in the OnlineEventMessageHelper (injected in the channel interceptor) is not initialized, while anything in the PreProcessingFilter is correctly initialized.

    At the beginning I configured the same logic in the channel interceptor, but nothing was injected via autowiring.

    Any idea?

    Kind regards
    Massimo

  • #2
    Ok, I see a lot of red flags in your configuration.

    For example:

    onlineEventMessageHeaderEnricher - tells me you are trying to enrich Message headers with channel interceptor instead of header-enricher

    onlineEventMessagePersisterInterceptor - tells me you are trying to persist some data via channel interceptor instead of using the appropriate component (there could be many and it all depend on your persistence requirements)
    etc...

    Channels Interceptor (although could be use as you are trying) were not designed and intended to be used for purposes other then logging/auditing. For everything else EIP defines a pattern while Spring Integration provides an implementation.

    So, instead of solving this immediate problem, could you please describe your use case so we could suggest the appropriate configuration.

    Comment


    • #3
      Oleg thanks in advance.

      So let's start from the beginning.
      The onlineEventMessageHeaderEnricher adds an instance of an object that has one boolean property to the header map: this instance is used as a flag to decide if that message needs to be forwarded to another subsystem.

      onlineEventMessagePersisterInterceptor - tells me you are trying to persist some data via channel interceptor instead of using the appropriate component (there could be many and it all depend on your persistence requirements)
      Exactly;

      So, instead of solving this immediate problem, could you please describe your use case so we could suggest the appropriate configuration.
      So here are the requirements:
      1. When I receive a message I need to persist it immediatly (let's call these DB DML MESSAGE_DB)
      2. I need to route the message to the correct chain routing based on the payload type
      3. In every chain the operations are 2: some modifies to a DB (let's call it APP_DB) and if all goes OK change the state to the message persisted at the beginning
      4. In every chain I need to decide if the message must be forwarded to another system; the decision is based on the message content
      5. Change the message state and save it.
      6. I need to handle some kind of exceptions:
        - application exceptions --> must rollback the APP_DB db updates of every chain but not the one for the message (MESSAGE_DB)
        - system exceptions (e.g. network problem with DB) --> must rollback the message and repost it to the jms queue.
      This is the application summary.
      I can provide the code and the integration graph for a chain to discuss if what I've done is correct or not.

      I need only some time to create and upload the pictures and the relative code.

      Thank's a lot for your time
      Kind regards

      Massimo Ugues
      Last edited by m.ugues; May 3rd, 2011, 10:04 AM.

      Comment


      • #4
        Ok, here I am.
        Here the picture that I talked about earlier.

        This is the preprocessing chain:
        http://www.flickr.com/photos/m4zi/57...ream/lightbox/

        http://www.flickr.com/photos/m4zi/57...ream/lightbox/

        So here are the requirements:
        When I receive a message I need to persist it immediatly (let's call these DB DML MESSAGE_DB)
        I accomplish this task through a Channel Interceptor
        >>EventMessagePersisterInterceptor extends ChannelInterceptorAdapter

        I need to route the message to the correct chain routing based on the payload type
        I accomplish this task through the component onlineMessageRouter

        In every chain the operations are 2: some modifies to a DB (let's call it APP_DB) and if all goes OK change the state to the message persisted at the beginning
        In every chain the operations are 2: some modifies to a DB (let's call it APP_DB) and if all goes OK change the state to the message persisted at the beginning
        http://www.flickr.com/photos/m4zi/57...ream/lightbox/

        http://www.flickr.com/photos/m4zi/57...ream/lightbox/

        The component that has to do these operations is the <int:service-activator ref="onlineVariazioneFilialeActivator" method="activate"/>

        I need to handle some kind of exceptions:
        - application exceptions --> must rollback the APP_DB db updates of every chain but not the one for the message (MESSAGE_DB)
        - system exceptions (e.g. network problem with DB) --> must rollback the message and repost it to the jms queue.
        How can I achieve this?

        I hope to have been claryfing about the use case.
        Kind regards
        Massimo

        Comment


        • #5
          Massimo

          Going back to you original configuration, do you have <context:annotation-config> as well ascomponent scanning enabled?

          Comment


          • #6
            Originally posted by oleg.zhurakousky View Post
            Massimo

            Going back to you original configuration, do you have <context:annotation-config> as well ascomponent scanning enabled?
            Yes
            <context:component-scan base-package="it.alten.intesasanpaolo.contratto" />
            <context:annotation-config />

            Comment


            • #7
              Are you sure that your GenericDao is in the above package? In fact you should see the exception based on your configuration if it can not find/resolve GenericDao.

              Comment

              Working...
              X