【问题标题】:Receive PDF file and forward it without altering it接收 PDF 文件并在不更改的情况下转发它
【发布时间】:2014-07-09 01:02:09
【问题描述】:

我需要公开一个网络服务,用户可以通过 POST 请求向我发送 PDF 文件。 我不想更改此文件。只需将其存储在云端的容器中即可。

这是我用来测试服务的 curl:

curl -X POST -H "Content-type: application/pdf"  'http://localhost:9302/billing/1/storeInvoice/user/0750102626/invoice/666' --data-binary /Users/manu/Desktop/toto.pdf

这是我的流程的 XML 代码:

<flow name="storebill">
    <http:inbound-endpoint exchange-pattern="request-response" host="${inbound.host}" port="9302" path="storeInvoice/" method="POST" contentType="application/pdf"/>
    <custom-transformer class="BuildFileNameFromRequestPath" />
    <http:outbound-endpoint exchange-pattern="request-response" host="myHost" port="80" path="#[flowVars['fileName']" contentType="application/pdf" method="PUT"/>
    <exception-strategy ref="genericExceptionStrategy" />
</flow>

该文件很好地存储在我的 openstack 容器中,但它的编码完全错误。 当我下载以前存储的文件时,我无法在笔记本电脑上阅读它。

PS:当我在 openstack 容器中通过 curl 上传本地 PDF 时,它的编码很好。

BuildFileNameFromRequestPath 转换器的代码:

public class BuildFileNameFromRequestPath extends AbstractMessageTransformer {

    public Object transformMessage(MuleMessage message, String outputEncoding) throws BusinessException {

        String request = message.getInboundProperty("http.request");
        StoreBillInfo result = getRestInfo(request);

        if (result != null) {
            message.setProperty(VariableNamesConstant.VAR_STOREBILLINFO, result, PropertyScope.INVOCATION);
        } else {
            throw new BusinessException(ErrorCode.ERR400);
        }

        try {
            System.out.println("length payload : " + message.getPayloadAsBytes().length);
            return message.getPayloadAsBytes();
        } catch (Exception e) {
            throw new BusinessException(ErrorCode.ERR400);
        }
    }
}

getRestInfo 只是一种从路径中提取一些信息以构造 pdf 文件名的方法。

【问题讨论】:

  • 你能展示一下BuildFileNameFromRequestPath里面的东西吗?
  • 好的,我把它放在原来的问题上......

标签: mule


【解决方案1】:

不要用message.getPayloadAsBytes() 混淆消息负载。您无缘无故地反序列化流,并且可能会弄乱编码。

不要使用自定义转换器,而是使用带有静态调用 getRestInfo 的 MEL 表达式的 set-variable 元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多