Announcement Announcement Module
Collapse
No announcement yet.
Second transformer in chain not working? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Second transformer in chain not working?

    Hi,
    I am a newbie to Spring Integration and am trying to process files by sending them through a couple of transformers using Spring Integration 2.0.5. The scanner is a muli-threaded implementation which scans the source folder for a specific filename patterns. The first transformer is the file-to-string transformer which gets invoked as is apparent from the log messages that get printed out but the second POJO transformer never seems to get invoked.

    I tried the following approaches:
    1. wrapping the transformers within a chain with the first transformer implementing the MessageSource interface
    2. declaring the second POJO transformer as a service-activator
    3. removing the chain but feeding the output channel of the first transformer into the input of the second transformer
    All these failed.

    Please do let me know what needs to be done to get the file contents processed through the two transformers.
    Thank you.

    Here is my configuration file:

    HTML Code:
    	<beans:bean id="stringToDocumentTransformer" class="MyTransformer">
    		<beans:property name="sourceFolder" value="#[fileserver.input.path]"></beans:property>
    		<beans:property name="destinationFolder" value="#[fileserver.output.path]"></beans:property>
    	</beans:bean>
    
    	<channel id="filesInChannel">
    		<dispatcher task-executor="filesInExecutor" />
    	</channel>
    
    	<beans:bean id="directoryScanner"
    		class="custom.impl.DirectoryScanner">
    		<beans:property name="numberOfThreads" value="7" />
    		<beans:property name="queueSize" value="20" />
    	</beans:bean>
    
    	<beans:bean id="customTrigger"
    		class="org.springframework.scheduling.support.PeriodicTrigger">
    		<beans:constructor-arg value="10" />
    		<beans:property name="fixedRate" value="false"></beans:property>
    		<beans:property name="initialDelay" value="0" />
    	</beans:bean>
    	
            <file:inbound-channel-adapter channel="filesInChannel"
    		directory="#[fileserver.input.path]" scanner="directoryScanner"
    		filename-pattern="*.xml">
    		<poller trigger="customTrigger" />
    	</file:inbound-channel-adapter>
    
     	<beans:bean id="filesInExecutor"
    		class="ThreadPoolTaskExecutorWithCallerRuns">
    		<beans:property name="corePoolSize" value="20" />
    		<beans:property name="maxPoolSize" value="40" />
    		<beans:property name="queueCapacity" value="200" />
    	</beans:bean>
      	
     	<chain input-channel="filesInChannel" output-channel="nullChannel">
    		<file:file-to-string-transformer delete-files="false" charset="UTF-8"/>
    		<transformer ref="stringToDocumentTransformer" method="transform"/>	
    	</chain>
    and the code for my second transformer is

    Code:
    public class MyTransformer extends AbstractReplyProducingMessageHandler {
    	
    	private static final Logger log = LoggerFactory.getLogger(MyTransformer.class);	
    	private String sourceFolder;	
    	private String destinationFolder;
    
    	public MyTransformer() {
    		log.debug("MyTransformer constructor called");
    	}
    
    	public String transformString(String msg) {
    		log.debug("MyTransformer transformString called");
    		return msg;
    	}
    
    	public String getSourceFolder() {
    		return sourceFolder;
    	}
    
    	public void setSourceFolder(String sourceFolder) {
    		this.sourceFolder = sourceFolder;
    	}
    
    	public String getDestinationFolder() {
    		return destinationFolder;
    	}
    
    	public void setDestinationFolder(String destinationFolder) {
    		this.destinationFolder = destinationFolder;
    	}
    
    	public String transform(String message) {		
    		log.debug("MyTransformer transform called");
    		return message;
    	}
    
    	@Override
    	protected Object handleRequestMessage(Message<?> msg) {
    		return msg;
    	}
    }

  • #2
    Your second transformer is not a POJO since you extend AbstractReplyProducingMessageHandler. Try removing the extends clause and deleting the handleRequestMessage method.

    Comment


    • #3
      Just tried that now but still the second one does not seem to get invoked.

      Comment


      • #4
        You are basing this on log output? If so, are you positive that you have debug level logging set for that class?

        Comment


        • #5
          You nailed it right on the head, Mark! I did not have the log level set for this class which was in a different package.
          The chain is indeed working.
          Thank you very much.

          Comment


          • #6
            Glad to hear it. By the way, it seems that you could simplify your configuration a bit.

            One thing to consider is Spring's <task> namespace which would allow you to define the executor with a single element and its attributes.

            Another thing I noticed is that you have a "customTrigger" bean but it's basically the same as using a single 'fixed-rate' attribute on the poller. Is there a reason for that?

            Comment


            • #7
              Not really! I will certainly look into the "task" namespace and also make use of "fixed-rate" attribute to simplify the configuration and reduce the code base. Thanks much again.

              Comment

              Working...
              X