【发布时间】: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