Announcement Announcement Module
Collapse
No announcement yet.
ftp outbound gateway fails on files with spaces Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ftp outbound gateway fails on files with spaces

    I'm attempting to use the ftp outbound gateway to download files but get the following for files with spaces:

    Code:
    SimpleAsyncTaskExecutor-1 03/15 09:12:07 WARN  ryBean$MethodInvocationGateway  - failure occurred in gateway sendAndReceive
    org.springframework.integration.MessagingException: '78/1295213/0/476312ca9c653ffc6cc8fb6e1649dae6/ModComp PO # 1054.pdf' is not a file
    	at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(AbstractRemoteFileOutboundGateway.java:304)
    	at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.handleRequestMessage(AbstractRemoteFileOutboundGateway.java:203)
    	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:97)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:114)
    	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:101)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:61)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128)
    	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
    	at org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318)
    	at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239)
    	at org.springframework.integration.core.MessagingTemplate.convertSendAndReceive(MessagingTemplate.java:274)
    	at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:224)
    	at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:203)
    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:305)
    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:268)
    	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:259)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy10.getFile(Unknown Source)
    My gateway bean definition looks like this:

    Code:
    <int-ftp:outbound-gateway
                session-factory="ftpClientFactory"
                command="get"
                local-directory="${ftp.local.download.dir}"
                auto-create-local-directory="true"
                request-channel="toGet"
                command-options="-P"
                expression="payload.fullPath"/>
    How do I avoid the above exception?

  • #2
    further debug info

    After going back and debugging the SI code, I found that for files with spaces files.length is 0 in the following method on the AbstractRemoteFileOutboundGateway class:

    Code:
    protected File get(Session<F> session, String remoteFilePath, String remoteFilename)
    			throws IOException {
    		F[] files = session.list(remoteFilePath);
    		if (files.length != 1 || isDirectory(files[0]) || isLink(files[0])) {
    			throw new MessagingException(remoteFilePath + " is not a file");
    		}
    		File localFile = new File(this.localDirectory, remoteFilename);
    		if (!localFile.exists()) {
    			String tempFileName = localFile.getAbsolutePath() + this.temporaryFileSuffix;
    			File tempFile = new File(tempFileName);
    			FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
    			try {
    				session.read(remoteFilePath, fileOutputStream);
    			}
    			catch (Exception e) {
    				if (e instanceof RuntimeException){
    					throw (RuntimeException) e;
    				}
    				else {
    					throw new MessagingException("Failure occurred while copying from remote to local directory", e);
    				}
    			}
    			finally {
    				try {
    					fileOutputStream.close();
    				}
    				catch (Exception ignored2) {
    				}
    			}
    			if (!tempFile.renameTo(localFile)) {
    				throw new MessagingException("Failed to rename local file");
    			}
    			if (this.options.contains(OPTION_PRESERVE_TIMESTAMP)) {
    				localFile.setLastModified(getModified(files[0]));
    			}
    			return localFile;
    		}
    		else {
    			throw new MessagingException("Local file " + localFile + " already exists");
    		}
    	}

    Comment


    • #3
      I am going to look at https://jira.springsource.org/browse/INT-2476 in more details tomorrow but a quick look now says that if it is a bug its on the API we are using since list() call on FtpSession simply returns what was returned from the call to the underlying API.

      Shane, could you please confirm that the directory you are scanning in your environment has all files that contain spaces. I am trying to see how I can reproduce it.
      Also, could you let us know about your environment (OS, FTP Server etc.)

      Comment


      • #4
        Also, what is the value of 'payload.fullPath'? Does it have any spaces?

        Comment


        • #5
          Hi,

          Can you please double-check whether you are in fact just dealing with normal "spaces" or wether you're dealing with some sneaky UTF characters? (Encoding issue) I created a very basic test case on my local machine and I actually was able to retrieve files containing white spaces in their file-names incl. "ModComp PO # 1054.pdf".

          However, when I used files with special characters e.g.: "REA™£DME.txt", I observed the same error message you got:

          Code:
          2012-03-16 01:36:35,726 *WARN | main | o.s.i.g.GatewayProxyFactoryBean$MethodInvocationGateway | failure occurred in gateway sendAndReceive*
          org.springframework.integration.MessagingException: REA™£DME.txt is not a file
          However, this was just a quick test at 2am in the morning...need more investigation.

          On a side note - I created earlier: https://jira.springsource.org/browse/INT-2477

          Not sure if this might be related to the issue you're having, but I just wanted to mention it.

          Cheers,

          Gunnar

          Comment

          Working...
          X