-
Jun 8th, 2011, 08:46 AM
#1
sftp:outbound-channel-adapter locks a file if exception occurs during writing
I think I found a bug in method sendFileToRemoteDirectory in class org.springframework.integration.file.remote.handle r.FileTransferringMessageHandler. The problem occurs when session.write fails and fileInputStream is not closed. The file is locked. This becomes a problem when you have strategy for error handing based on moving this file to error or delay folder using file:outbound-channel-adapter with delete-source-files="true". You can't do that because the file is locked. The solution is easy: put fileInputStream.close() in finally block. Here is my integration-context (if remote-directory in sftp:outbound-channel-adapter does not exist, my file is not moved to delay1 folder):
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-3.0.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schem...ration-2.0.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schem...n-file-2.0.xsd
http://www.springframework.org/schema/integration/sftp
http://www.springframework.org/schem...n-sftp-2.0.xsd
http://www.springframework.org/schem...gration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd">
<!-- input directory "input" -->
<int-file:inbound-channel-adapter
directory="${rootfolder}/input" channel="in_inputDirChannel">
<poller fixed-rate="1000"/>
</int-file:inbound-channel-adapter>
<header-enricher input-channel="in_inputDirChannel" output-channel="sftpChannel" >
<header name="SOURCE_BACKET" value="0"/>
</header-enricher>
<!-- output directory "delay1" -->
<channel id="out_delay1DirChannel"/>
<int-file:outbound-channel-adapter
directory="${rootfolder}/delay1"
channel="out_delay1DirChannel"
temporary-file-suffix=".tmp"
delete-source-files="true">
</int-file:outbound-channel-adapter>
<!-- SFTP -->
<channel id="sftpChannel">
<!--<interceptors>
<wire-tap channel="logger"/>
</interceptors>-->
</channel>
<header-enricher input-channel="sftpChannel" output-channel="sftpChannel_send">
<error-channel ref="sftpErrorChannel"/>
</header-enricher>
<publish-subscribe-channel id="sftpChannel_send"/>
<int-sftp:outbound-channel-adapter channel="sftpChannel_send" id="sftpOutboundAdapter"
session-factory="sftpSessionFactory"
charset="UTF-8"
temporary-file-suffix=".tmp"
remote-directory="/root/out11"
order="1"
remote-filename-generator-expression="payload.getName()"/>
<int-file:outbound-channel-adapter
directory="${rootfolder}/sent"
channel="sftpChannel_send"
temporary-file-suffix=".tmp"
order="2"
delete-source-files="true">
</int-file:outbound-channel-adapter>
<!-- Error Handling -->
<channel id="sftpErrorChannel">
<interceptors>
<wire-tap channel="logger"/>
</interceptors>
</channel>
<chain input-channel="sftpErrorChannel" >
<transformer expression="payload.getFailedMessage()"/>
<router ref="delayRouter" method="route">
<mapping value="1" channel="out_delay1DirChannel" />
<mapping value="2" channel="out_delay2DirChannel" />
<mapping value="3" channel="out_delay3DirChannel" />
<mapping value="error" channel="out_errorDirChannel" />
</router>
</chain>
<!-- Common -->
<logging-channel-adapter log-full-message="true" id="logger" level="ERROR"/>
<beans:bean id="sftpSessionFactory" class="org.springframework.integration.sftp.sessio n.DefaultSftpSessionFactory">
<beans:property name="host" value="someserver"/>
<beans:property name="port" value="22"/>
<beans:property name="user" value="bla"/>
<beans:property name="password" value="bla"/>
</beans:bean>
<int-stream:stderr-channel-adapter channel="errorChannel" append-newline="true" />
<beans:bean id="delayRouter"
class="si.src.vpisnik.middlelayer.core.async.impl. flow.DelayRouter">
<beans:property name="numberOfBackets" value="3"/>
</beans:bean>
</beans:beans>
-
Jun 8th, 2011, 09:03 AM
#2
Valid point and good catch. Could you please file a bug report here? https://jira.springsource.org/browse/INT
-
Jun 9th, 2011, 01:36 AM
#3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules