Announcement Announcement Module
Collapse
No announcement yet.
Exception in service activator is causing premature ending of process Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception in service activator is causing premature ending of process

    I have a basic flow:
    gateway
    3x ftp outbound gateway (ls, get, rm)
    a service activator (unzip's each file downloaded)
    transformer (exception handling)

    as a test, I put 2 zip files on my ftp server, and a text file with a zip extension (to simulate a corrupt zip)

    without the "corrupt zip", my process behaves as expected, downloads each file, and puts them on a channel, which the service activator then unzips.
    however, if I return the "corrupt zip" to the ftp server, and name it so it gets downloaded first, when it gets unzip in the service activator, the exception is thrown, and (as I assume) "caught" by the transformer.
    I would then expect the remaining zip files to be downloaded, but they are not, I have to reexecute the gateway.

    here are my contexts

    default-context.xml
    Code:
    <channel id="exceptionChannel" />
    	
    	<transformer id="defaultExceptionTransformer" input-channel="exceptionChannel" output-channel="nullChannel">
    		<beans:bean class="com.fetcha.server.integration.DefaultExceptionTransformer" />
    	</transformer>
    ftp-context.xml
    Code:
    <channel id="inboundChannel">
    		<dispatcher task-executor="inboundChannelTaskExecutor"/>
    	</channel>
    	
    	<beans:bean id="inboundChannelTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    		<beans:property name="corePoolSize" value="2"/>
    		<beans:property name="daemon" value="false"/>	
    	</beans:bean>
    	
    	<gateway id="integrationGateway"
    		service-interface="com.foo.integration.IntegrationGateway"
    		default-request-channel="inboundChannel" />
    
    	<beans:bean id="ftpSessionFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    		<beans:property name="host" value="${ftp.inbound.host}" />
    		<beans:property name="port" value="${ftp.inbound.port}" />
    		<beans:property name="username" value="${ftp.inbound.user}" />
    		<beans:property name="password" value="${ftp.inbound.password}" />
    	</beans:bean>
    
    	<int-ftp:outbound-gateway id="gatewayLS"
    		cache-sessions="false" 
    		session-factory="ftpSessionFactory"
    		request-channel="inboundChannel" 
    		command="ls" 
    		command-options="" 
    		expression="'${ftp.inbound.remote.directory}'"
    		reply-channel="toSplitter" />
    
    	<channel id="toSplitter">
    		<interceptors>
    			<wire-tap channel="logger" />
    		</interceptors>
    	</channel>
    
    	<logging-channel-adapter id="logger"
    		log-full-message="true" level="DEBUG" />
    
    	<splitter id="splitter" input-channel="toSplitter"
    		output-channel="toGet" />
    
    	<int-ftp:outbound-gateway id="gatewayGET" filename-pattern="*.zip"
    		cache-sessions="false"
    		local-directory="${ftp.inbound.local.directory}"
    		session-factory="ftpSessionFactory" 
    		request-channel="toGet"
    		reply-channel="newFileChannel" 
    		command="get" 
    		command-options="-P"
    		expression="payload.remoteDirectory + '/' + payload.filename" />
    
    	<publish-subscribe-channel id="newFileChannel">
    		<interceptors>
    			<wire-tap channel="logger2"/>
    		</interceptors>
    	</publish-subscribe-channel>
    
    	<logging-channel-adapter id="logger2" log-full-message="true" />
    
    	<int-ftp:outbound-gateway id="gatewayRM"
    		session-factory="ftpSessionFactory" 
    		cache-sessions="false"
    		expression="headers['file_remoteDirectory'] + '/' + headers['file_remoteFile']"
    		request-channel="newFileChannel" 
    		command="rm" 
    		reply-channel="nullChannel"	/>
    unzip-context.xml
    Code:
    <chain input-channel="newFileChannel" output-channel="nullChannel">
       		<header-enricher>
       			<error-channel ref="exceptionChannel" />
       		</header-enricher>
       		<service-activator method="unzip" >
    			<beans:bean class="com.foo.Zip" />
    		</service-activator>
    	</chain>
    DefaultExceptionTransformer.java
    Code:
    public class DefaultExceptionTransformer {
    
    	public boolean transform(final Exception exception) {
    		System.out.println("Transforming exception: " + exception.getMessage());
    		return true;
    	}
    	
    }
    I basically want the FTPing to be completely decoupled from the unzipping.

    what am I doing wrong?

    Thanks in advance
    Shaine

  • #2
    as an update, I managed to "fix" my problem by amending my "newFileChannel" like so, essentially adding a tast-executor

    ftp-context.xml
    Code:
    <publish-subscribe-channel id="newFileChannel" task-executor="newFileChannelTaskExecutor">
    		<interceptors>
    			<wire-tap channel="logger2"/>
    		</interceptors>
    	</publish-subscribe-channel>
    	
    	<beans:bean id="newFileChannelTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    		<beans:property name="corePoolSize" value="2"/>
    		<beans:property name="daemon" value="false"/>	
    	</beans:bean>
    is my approach for this correct?

    Comment


    • #3
      Thinking about this more, it is probably even better if I use an file-inbound-channel adapter

      Comment

      Working...
      X