You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Gerold Broser (JIRA)" <ji...@apache.org> on 2019/01/17 13:28:00 UTC

[jira] [Comment Edited] (CAMEL-13069) Display proper FTP reply message in case of transfer error

    [ https://issues.apache.org/jira/browse/CAMEL-13069?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16745031#comment-16745031 ] 

Gerold Broser edited comment on CAMEL-13069 at 1/17/19 1:27 PM:
----------------------------------------------------------------

[~dmvolod], I thought of adding the following to [the said catch block|https://github.com/apache/camel/blob/master/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java#L717]:
{code:java}
...
  catch (final IOException e) {
    int replyCode = client.getReplyCode();
    String replyString = client.getReplyString();

    // Using FutureTask that can time out since FTP.getReply() waits indefinitely if no secondary reply is supplied
    final FutureTask<Integer> Reply = new FutureTask<>(() -> {
      return client.getReply();
    });
    new Thread(Reply).start();
    try {
      replyCode = Reply.get(1, TimeUnit.SECONDS); // TimeoutException thrown here if no secondary reply is supplied 
      replyString += client.getReplyString();
    }
    catch (final TimeoutException te) {
      // nothing to do in case of timeout
    }

    throw new GenericFileOperationFailedException(replyCode, replyString, e.getMessage(), e);
  }
...
{code}
so that the already printed log message looks like:
{noformat}
2019-01-16 10:10:22,368 WARN file.remote.RemoteFileProducer – Writing file failed with: File operation failed: 125 Storing data set TEST.TRANSFER.FB80.TXT
451-Error: Name=CkResults (Write) RC=-13
451-System completion code and reason: B37-04
451-Data set is out of space.
451-Error (1013) closing the data set.
451 Transfer aborted due to file error.
 IOException caught while copying.. Code: 451
{noformat}
rather than just:
{noformat}
2019-01-16 10:10:22,368 WARN file.remote.RemoteFileProducer – Writing file failed with: File operation failed: 125 Storing data set TEST.TRANSFER.FB80.TXT
 IOException caught while copying.. Code: 125
{noformat}


was (Author: broser):
[~dmvolod], I thought of adding the following to [the said catch block|https://github.com/apache/camel/blob/master/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java#L717]:
{code:java}
...
  catch (final IOException e) {
    int replyCode = ftp.getReplyCode();
    String replyString = ftp.getReplyString();

    // Using FutureTask that can time out since FTP.getReply() waits indefinitely if no secondary reply is supplied
    final FutureTask<Integer> Reply = new FutureTask<>(() -> {
      return ftp.getReply();
    });
    new Thread(Reply).start();
    try {
      replyCode = Reply.get(1, TimeUnit.SECONDS); // TimeoutException thrown here if no secondary reply is supplied 
      replyString += ftp.getReplyString();
    }
    catch (final TimeoutException te) {
      // nothing to do in case of timeout
    }

    throw new GenericFileOperationFailedException(replyCode, replyString, e.getMessage(), e);
  }
...
{code}
so that the already printed log message looks like:
{noformat}
2019-01-16 10:10:22,368 WARN file.remote.RemoteFileProducer – Writing file failed with: File operation failed: 125 Storing data set TEST.TRANSFER.FB80.TXT
451-Error: Name=CkResults (Write) RC=-13
451-System completion code and reason: B37-04
451-Data set is out of space.
451-Error (1013) closing the data set.
451 Transfer aborted due to file error.
 IOException caught while copying.. Code: 451
{noformat}

rather than just:
{noformat}
2019-01-16 10:10:22,368 WARN file.remote.RemoteFileProducer – Writing file failed with: File operation failed: 125 Storing data set TEST.TRANSFER.FB80.TXT
 IOException caught while copying.. Code: 125
{noformat}

> Display proper FTP reply message in case of transfer error
> ----------------------------------------------------------
>
>                 Key: CAMEL-13069
>                 URL: https://issues.apache.org/jira/browse/CAMEL-13069
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-ftp
>    Affects Versions: 2.23.0
>         Environment: Any
>            Reporter: Gerold Broser
>            Priority: Major
>              Labels: FTP, FTP-Reply
>
> When trying to transfer a file to an FTP server on an IBM mainframe that's too large for the allocated data set there I get the following log message:
> {code:java}
> ...
> 2019-01-16 10:10:22,368 WARN file.remote.RemoteFileProducer – Writing file failed with: File operation failed: 125 Storing data set TEST.TRANSFER.FB80.TXT
>  IOException caught while copying.. Code: 125
> ...{code}
> This is confusing since according to RFC 959 [reply codes {{1yz}} are {{Positive Preliminary}} replies|https://tools.ietf.org/html/rfc959#page-37] with:
> {quote}[{{125 Data connection already open; transfer starting.}}|https://tools.ietf.org/html/rfc959#page-41]
> {quote}
> being more informational than exceptional.
> Performing the same transfer manually with FileZilla and Windows 7's command line ftp client results in:
> FileZilla:
> {code:java}
> ...
> Command:	STOR TRANSFER.FB80.TXT
> Response:	125 Storing data set TEST.TRANSFER.FB80.TXT
> Response:	451-Error: Name=CkResults (Write) RC=-13
> Response:	451-System completion code and reason: B37-04
> Response:	451-Data set is out of space.
> Response:	451-Error (1013) closing the data set.
> Response:	451 Transfer aborted due to file error.
> ...{code}
> ftp:
> {code:java}
> ftp> send TRANSFER.FB80.TXT
> ---> PORT 10,100,113,251,254,235
> 200 Port request OK.
> ---> STOR TRANSFER.FB80.TXT
> 125 Storing data set TEST.TRANSFER.FB80.TXT
> 451-Error: Name=CkResults (Write) RC=-13
> 451-System completion code and reason: B37-04
> 451-Data set is out of space.
> 451-Error (1013) closing the data set.
> 451 Transfer aborted due to file error.
> ...{code}
> To get the real cause we can use Apache Commons Net's [{{FTP.getReply()}}|https://commons.apache.org/proper/commons-net/javadocs/api-3.6/org/apache/commons/net/ftp/FTP.html#getReply()]:
> {quote}Fetches a reply from the FTP server and returns the integer reply code. After calling this method, the actual reply text can be accessed from either calling getReplyString or getReplyStrings . Only use this method if you are implementing your own FTP client *or if you need to fetch a secondary response from the FTP server*.
> {quote}
> in the {{catch (IOException e)}} block in [{{FtpOperations.doStoreFile()}}|https://github.com/apache/camel/blob/master/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java#L717] like:
> {code:java}
> ...
> catch (IOException e) {
>   final IOException primary = new IOException(client.getReplyString());
>   e = new IOException(e.getMessage(), primary);
>   client.getReply(); // get secondary reply
>   throw new GenericFileOperationFailedException(client.getReplyString(), e);
> }
> ...
> {code}
> which results in the following comprehensible stack trace in my test code:
> {code:java}
> org.apache.camel.component.file.GenericFileOperationFailedException: 451-Error: Name=CkResults (Write) RC=-13
> 451-System completion code and reason: B37-04
> 451-Data set is out of space.
> 451-Error (1013) closing the data set.
> 451 Transfer aborted due to file error.
>     at my.FTPTransferTest.testMF_FTP((FTPTransferTest.java:74))
>     ...
> Caused by: java.io.IOException: IOException caught while copying.
>     at my.FTPTransferTest.testMF_FTP(FTPTransferTest.java:70)
>     ... 24 more
> Caused by: java.io.IOException: 125 Storing data set TEST.TRANSFER.FB80.TXT
>     at my.FTPTransferTest.testMF_FTP(FTPTransferTest.java:69)
>     ... 24 more
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)