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

Thread: file:outbound-channel-adapter + ChannelInterceptorAdapter

  1. #1

    Default 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  )] - org.springframework.integration.file.FileWritingMessageHandler@d38976 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 'org.springframework.integration.file.FileWritingMessageHandler@d38976' 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. #2
    Join Date
    Aug 2006
    Posts
    129

    Default

    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"/>

  3. #3

    Default

    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"/>

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    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

  5. #5
    Join Date
    Aug 2006
    Posts
    129

    Default

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

  6. #6

    Default

    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 ?

  7. #7
    Join Date
    Aug 2006
    Posts
    129

    Default

    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 ?

  8. #8

    Default

    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

  9. #9
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

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

  10. #10
    Join Date
    Aug 2006
    Posts
    129

    Default

    he wants the generated file name,
    Code:
    AbstractReplyProducingMessageHandler(156 )] - handler 'org.springframework.integration.file.FileWritingMessageHandler@d38976' 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

Posting Permissions

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