Carry Original File Name to FTP endpoint

泄露秘密 提交于 2021-02-08 06:24:14

问题


Using Mule Studio

Version: 3.5.0 Build Id: 201402101410

I have a very simple flow. I need to pick up a file from one ftp server and transfer it to another ftp server. When the file is written to the target, the filename looks like some kind of UUId rather than the original file name. How do I get the file name to carry through? I have tried #[header:originalFilename] but that throws an error so I assume that maybe it is only for file connectors. Here is my flow:

    <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" version="CE-3.4.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<context:property-placeholder location="environment.properties"/>
    <flow name="sli-ftpFlow1" doc:name="sli-ftpFlow1">
        <ftp:inbound-endpoint host="${local.ftp.host}" port="${local.ftp.port}" path="${local.ftp.path}" user="${local.ftp.user}" password="${local.ftp.pass}" responseTimeout="10000" doc:name="FTP" pollingFrequency="${local.ftp.pollingFreq}" binary="true" passive="false"/>
        <logger message="Transferring file:" level="INFO" doc:name="Logger"/>
        <ftp:outbound-endpoint host="${sli.ftp.host}" port="${sli.ftp.port}" path="${sli.ftp.path}" user="${sli.ftp.user}" password="${sli.ftp.pass}" responseTimeout="10000" doc:name="FTP" outputPattern="#[header:originalFilename]"/>
    </flow>
</mule>

Stack Trace:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'sli-ftp'                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2014-03-19 22:10:38,058 [[sli-ftp].sli-ftpFlow1.stage1.02] INFO  org.mule.api.processor.LoggerMessageProcessor - Transferring file:
2014-03-19 22:10:38,071 [[sli-ftp].connector.ftp.mule.default.dispatcher.01] INFO  org.mule.lifecycle.AbstractLifecycleManager - Initialising: 'connector.ftp.mule.default.dispatcher.1035665885'. Object is: FtpMessageDispatcher
2014-03-19 22:10:38,071 [[sli-ftp].connector.ftp.mule.default.dispatcher.01] INFO  org.mule.lifecycle.AbstractLifecycleManager - Starting: 'connector.ftp.mule.default.dispatcher.1035665885'. Object is: FtpMessageDispatcher
2014-03-19 22:10:38,078 [[sli-ftp].connector.ftp.mule.default.dispatcher.01] ERROR org.mule.exception.DefaultMessagingExceptionStrategy - 
********************************************************************************
Message               : Streaming failed. Could not get output stream. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=ftp://esbuser%40newpig.com:<password>@webuatint/SLI-Mock, connector=FtpConnector
{
  name=connector.ftp.mule.default
  lifecycle=start
  this=a40c648
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[ftp]
  serviceOverrides=<none>
}
,  name='endpoint.ftp.webuatint.21.SLI.Mock', mep=ONE_WAY, properties={outputPattern=#[header:originalFilename]}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: byte[]
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException)
  org.mule.expression.ExpressionUtils:239 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/RequiredValueException.html)
2. Streaming failed. Could not get output stream. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=ftp://esbuser%40newpig.com:<password>@webuatint/SLI-Mock, connector=FtpConnector
{
  name=connector.ftp.mule.default
  lifecycle=start
  this=a40c648
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[ftp]
  serviceOverrides=<none>
}
,  name='endpoint.ftp.webuatint.21.SLI.Mock', mep=ONE_WAY, properties={outputPattern=#[header:originalFilename]}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: byte[] (org.mule.api.transport.DispatchException)
  org.mule.transport.ftp.FtpConnector:602 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.expression.RequiredValueException: Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required.
    at org.mule.expression.ExpressionUtils.getPropertyInternal(ExpressionUtils.java:239)
    at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:67)
    at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:50)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

Stack Trace with #[header:originalFilename] in Logger:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'sli-ftp'                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2014-03-20 08:15:35,918 [[sli-ftp].sli-ftpFlow1.stage1.02] ERROR org.mule.exception.DefaultMessagingExceptionStrategy - 
********************************************************************************
Message               : Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException). Message payload is of type: byte[]
Code                  : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException)
  org.mule.expression.ExpressionUtils:239 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/RequiredValueException.html)
2. Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required. (org.mule.api.expression.RequiredValueException). Message payload is of type: byte[] (org.mule.api.MessagingException)
  org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.expression.RequiredValueException: Expression Evaluator "header" with expression "outbound:originalFilename" returned null but a value was required.
    at org.mule.expression.ExpressionUtils.getPropertyInternal(ExpressionUtils.java:239)
    at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:67)
    at org.mule.expression.ExpressionUtils.getPropertyWithScope(ExpressionUtils.java:50)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

回答1:


Use MEL: #[message.inboundProperties.originalFilename].

I think the scope is the issue.

This was changed in 3.4 -http://www.mulesoft.org/documentation/display/current/Mule+ESB+3.4.0+Release+Notes

Mule 3.4+ originalFilename is in the inbound scope. So use: #[message.inboundProperties.originalFilename]

Mule < 3.4 originalFilename is in the outbound scope. So use: #[message.outboundProperties.originalFilename]

Issue is documented here: https://www.mulesoft.org/jira/browse/MULE-6743



来源:https://stackoverflow.com/questions/22518098/carry-original-file-name-to-ftp-endpoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!