Announcement Announcement Module
Collapse
No announcement yet.
file:outbound-channel-adapter + ChannelInterceptorAdapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • file:outbound-channel-adapter + ChannelInterceptorAdapter

    Hi all,

    I've defined a file:outbound-channel-adapter and enabling org.springframework.integration.file at DEBUG level I can get from log in the "sending reply Message" the full name of the generated file Payload=C:\products\...\unmatched_request_....xml:

    Code:
    04.mag.2012 12:02:13,182 - (LISTENER SERVICE) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [DEBUG ]-[AbstractMessageHandler             (67  )] - [email protected]38976 received message: [Payload=<test/>][Headers={timestamp=1336125733166, ...}]
    04.mag.2012 12:02:13,213 - (LISTENER SERVICE) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [DEBUG ]-[AbstractReplyProducingMessageHandler(156 )] - handler '[email protected]8976' sending reply Message: [Payload=C:\products\data\interfaces\unmatchedMessageType\unmatched_request_520191.1336125711635.0_04052012_120213.xml][Headers={timestamp=1336125733213, ...}]
    So I would like to get the same info using a channel-interceptor and avoiding to be forced to enable org.springframework.integration.file at DEBUG level.

    So my applicationContext.xml settings:

    Code:
        <int:channel id="unmatchedMessageTypeChannel"/>
    
        <int:channel-interceptor pattern="unmatchedMessageTypeChannel" order="-1">
          <beans:bean class="ch.integration.jms.interceptor.LoggingFileChannelInterceptor"/>
        </int:channel-interceptor>
    
        <file:outbound-channel-adapter id="unmatchedMessageTypeChannel" directory="file:${unmatchedMessageType.directory}"
           filename-generator-expression="'... + '.xml'"/>
    My interceptor class where I override preSend + postSend + postReceive:

    Code:
    public class LoggingFileChannelInterceptor extends ChannelInterceptorAdapter {
    ...
        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
    ...
            logger.info("#### [Channel={" + channelName + "}][ID={" + jmsMessageId + "}][Headers=" + headersStr + "][Payload={" + payload + "}][Count={" + sendCount.incrementAndGet() + "}]");
            return message;
        }
    
        @Override
        public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
            logger.info("#### - postSend - payload=" + message.getPayload().toString());
        }
    
        @Override
        public Message<?> postReceive(Message<?> message, MessageChannel channel) {
            logger.info("#### - postReceive - payload=" + message.getPayload().toString());
            return message;
        }
    But from logs I'm not able to get as above the full name of the generated file ...

    Code:
    04.mag.2012 12:02:13,182 - (LISTENER SERVICE) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [INFO  ]-[LoggingFileChannelInterceptor      (55  )] - #### [Channel={unmatchedMessageTypeChannel}][ID={ID_ 520191.1336125711635.0 }][Headers={timestamp=1336125733166, ...}]
    04.mag.2012 12:02:13,228 - (LISTENER SERVICE) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [INFO  ]-[LoggingFileChannelInterceptor      (61  )] - #### - postSend - payload=<test/>
    Any help ss greatly appreciated!!!

    Thanks and regards
    nuvola

  • #2
    Code:
    <int:channel id="unmatchedMessageTypeChannel">
       		<int:interceptors>
       			<int:wire-tap channel="logging-channel"/>
       		</int:interceptors>
       </int:channel>
       
       <int:channel id="logging-channel"/>
       
       <int:logging-channel-adapter channel="logging-channel" expression="payload"/>

    Comment


    • #3
      Tried as you mentioned trying also:

      1. Try1 as you suggested
      2. Try2 => level="INFO" at int:logging-channel-adapter level
      3. Try3 => as Try2 + at log4j.xml enabled at INFO org.springframework.integration.file
      <logger name="org.springframework.integration.file">
      <level value="INFO"/>
      </logger>

      but in all "3 tries" I don't see anything :-(

      Code:
          <int:channel id="unmatchedMessageTypeChannel">
            <int:interceptors>
              <int:wire-tap channel="logging-channel"/>
            </int:interceptors>
          </int:channel>
          <int:channel id="logging-channel"/>
          <int:logging-channel-adapter channel="logging-channel" expression="payload" level="INFO"/>

      Comment


      • #4
        This won't work:
        Code:
        <logger name="org.springframework.integration.file">
        <level value="INFO"/>
        </logger>
        since your interceptor is in 'ch.integration.jms.interceptor'. Fix your logging configuration

        Comment


        • #5
          you want the resulting file name logged, not from the source channel ?

          Comment


          • #6
            Sorry but I'm bit confused ...

            I removed my LoggingFileChannelInterceptor def:

            Code:
                <int:channel-interceptor pattern="unmatchedMessageTypeChannel" order="-1">
                  <beans:bean class="ch.integration.jms.interceptor.LoggingFileChannelInterceptor"/>
                </int:channel-interceptor>
            and added your hint

            Code:
                <int:channel id="unmatchedMessageTypeChannel">
                  <int:interceptors>
                    <int:wire-tap channel="logging-channel"/>
                  </int:interceptors>
                </int:channel>
                <int:channel id="logging-channel"/>
                <int:logging-channel-adapter channel="logging-channel" expression="payload" level="INFO"/>
            'your hint' doesn't reference my LoggingFileChannelInterceptor so I should not need to fix my logging configuration ...

            Or should I add 'your hint' WITHOUT removing my above LoggingFileChannelInterceptor def ?

            Comment


            • #7
              the logging-channel-adapter will log the message which was intecepted by the wire-tap,
              can you define another reply-channel onto the outbound-channel-adapter and wire-tap this channel ?

              Comment


              • #8
                Hi wims,

                may I ask you to provide please an example about reply-channel onto the outbound-channel-adapter ?

                I'm trying to understand how I should link channels "my unmatchedMessageTypeChannel (a file outbound-channel-adapter)", the wire-tap channel="logging-channel" and that "reply-channel"

                Thanks!
                nuvola

                Comment


                • #9
                  There is no reply-channel on the outbound adapter. Adapters are uni-directional. What are you trying to do?

                  Comment


                  • #10
                    he wants the generated file name,
                    Code:
                    AbstractReplyProducingMessageHandler(156 )] - handler '[email protected]8976' sending reply Message: [Payload=C:\products\data\interfaces\unmatchedMessageType\unmatched_request_520191.1336125711635.0_04052012_120213.xml][Headers={timestamp=1336125733213, ...}]
                    but not via log in debug mode

                    Comment


                    • #11
                      change it to a gateway :

                      Code:
                      <int-file:outbound-gateway directory="" request-channel="" reply-channel="generated-files" filename-generator=""/>
                         
                         <int:channel id="generated-files"/>
                         
                         <int:logging-channel-adapter channel="generated-files" expression="payload"/>

                      Comment


                      • #12
                        Removing my response since @wims.tijd has already replied with appropriate suggestion. Thanks!

                        Comment


                        • #13
                          As suggested by wims.tijd, it works!

                          Thanks a lot to you all.

                          Regards
                          nuvola

                          Comment

                          Working...
                          X