向骡子邮件添加附件



我们有点卡住了,不知道如何在骡子消息中发送附件。我们有一些添加出站附件的代码,但"内容处置"和"内容类型"的值是由 mule 自动生成的,与服务器上的预期不匹配。我已经粘贴了我们正在生成的消息,即预期的消息(请注意内容类型和内容处置的差异)。

内容处置必须在有效负载上"内联",在数据文件.xml部分"附件",但 mule 生成 Content-Disposition:form-data; name="payload" 和 Content-Disposition:form-data; name="data-file.xml"这是我们用来生成附件的代码片段:

ByteArrayDataSource ds = new org.mule.message.ds.ByteArrayDataSource((byte[])docInput.getDataSet(),ATTACHMENT_FILE_NAME,"application/pdf");DataHandler dh = new javax.activation.DataHandler(ds);msg.addOutboundAttachment(ATTACHMENT_FILE_NAME, dh);

生成的消息By_mule

POST /Operations/GenerateDocument HTTP/1.1
X-MULE_ENDPOINT: http://bxl-rs-d1-vm:42420/Operations/GenerateDocument
X-MULE_CORRELATION_SEQUENCE: -1
X-MULE_ENCODING: UTF-8
X-MULE_ROOT_MESSAGE_ID: be11dc40-a0af-11e4-89da-080027001cc8
Client-Authorization: YyoAjWLrpsySg7Euxf9zs3S/ujAPjFuRkT7di6/Dk9o=
Content-Type: multipart/mixed; boundary=" WeqbofBr94jK6QxpiWP36xMWse3bxwG21uQZed6”
Date: Tue, 20 Jan 2015 14:22:20 GMT
X-MULE_CORRELATION_GROUP_SIZE: -1
Accept: application/xml
X-MULE_SESSION: rO0ABXNyACNvcmcubXVsZS5zZXNzaW9uLkRlZmF1bHRNdWxlU2Vzc2lvbi7rdtEW7GGKAwAFWgAFdmFsaWRMAA1mbG93Q29uc3RydWN0dAAmTG9yZy9tdWxlL2FwaS9jb25zdHJ1Y3QvRmxvd0NvbnN0cnVjdDtMAAJpZHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wACnByb3BlcnRpZXN0AA9MamF2YS91dGlsL01hcDtMAA9zZWN1cml0eUNvbnRleHR0ACdMb3JnL211bGUvYXBpL3NlY3VyaXR5L1NlY3VyaXR5Q29udGV4dDt4cAFwdAAkYmUxMjc4ODAtYTBhZi0xMWU0LTg5ZGEtMDgwMDI3MDAxY2M4c3IAJWphdmEudXRpbC5Db2xsZWN0aW9ucyRTeW5jaHJvbml6ZWRNYXAbc/kJS0s5ewMAAkwAAW1xAH4AA0wABW11dGV4dAASTGphdmEvbGFuZy9PYmplY3Q7eHBzcgAkb3JnLm11bGUudXRpbC5DYXNlSW5zZW5zaXRpdmVIYXNoTWFwndHZ72dFzgADAAB4cHcMP0AAAAAAABAAAAABdAAMT3BlcmF0aW9uVmFydAAQZ2VuZXJhdGVEb2N1bWVudHhxAH4ACXhweA==
User-Agent: Jakarta Commons-HttpClient/3.1
Host: bxl-rs-d1-vm:42420
Content-Length: 16645
--WeqbofBr94jK6QxpiWP36xMWse3bxwG21uQZed6
Content-Disposition: form-data; name="payload"
Content-Type: application/octet-stream; charset=ISO-8859-1
Content-Transfer-Encoding: binary
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns12:GenerateDocumentRequest xmlns:ns2="http://www.sodexo.com/CRM-Integration-Push" xmlns:ns3="http://www.sodexo.com/CRM-Integration-Update" xmlns:ns4="http://www.sodexo.com/CRM-Integration-PushFeedback" xmlns:ns5="http://www.sodexo.be/schemas/organization-api/1.0" xmlns:ns6="http://www.sodexo.be/schemas/organization-api/Phoenix-Organization-Update" xmlns:ns7="http://www.sodexo.com/CRM-Integration-UpdateFeedback" xmlns:ns8="http://www.sodexo.com/CRM-Address-Management" xmlns:ns9="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-addressRequest" xmlns:ns10="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-resultType" xmlns:ns11="http://www.sodexo.com/CRM-Document-Management" xmlns:ns12="http://schemas.datacontract.org/2004/07/Compro.Services.Contracts.DataContracts" xmlns:ns13="http://schemas.datacontract.org/2004/07/System" xmlns:ns14="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-addressSearchRequest" xmlns:ns15="http://www.sodexo.com/CRM-Integration-Base" xmlns:ns16="http://www.sodexo.be/schemas/organization-api/Phoenix-OrganizationServices-Base" xmlns:ns17="http://www.sodexo.be/schemas/organization-api/Phoenix-Organization-UpdateFeedback" xmlns:ns18="http://net.sxpbelux.eurodb.services/eurodbServiceSchema-searchAddressResultType"><ns12:AttachmentFiles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/><ns12:BusinessContext>ServiceVoucher</ns12:BusinessContext><ns12:BusinessReference>Work_Voucher_Assigned</ns12:BusinessReference><ns12:CommunicationKey>CommunicationKey</ns12:CommunicationKey><ns12:DataFile>data-file.xml</ns12:DataFile><ns12:FileFormat>DOCX</ns12:FileFormat></ns12:GenerateDocumentRequest>
--WeqbofBr94jK6QxpiWP36xMWse3bxwG21uQZed6
Content-Disposition: form-data; name="data-file.xml"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:DocumentData xmlns:ns2="http://www.sodexo.com/CRM-Integration-Template">
    <Contacts>
        <Contact>
            <email>email@abc.com</email>
            <firstName>firstName</firstName> ....

Message_expected_by_server

POST http://besvc-hq1000057:42420/Operations/GenerateDocumentWithAttachment/ HTTP/1.1
Date: Wed, 26 Nov 2014 13:31:24 GMT
Accept: application/xml
X-Compro-Username: ASI
Client-Authorization: S/rumqB+P0jfzY54eSeAGrKeMCfy7RYizno5A8D0ulI=
Content-Type: multipart/mixed; boundary="d1261136-19f2-463e-ac7e-e8925c807c7d"
Host: besvc-hq1000057:42420
Content-Length: 26128
Expect: 100-continue
Connection: Keep-Alive
--d1261136-19f2-463e-ac7e-e8925c807c7d
Content-Type: application/xml; charset=utf-8
Content-Disposition: inline
[... some xml data ...]
--d1261136-19f2-463e-ac7e-e8925c807c7d
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename=order_created_badcom_data.xml
[... some xml content ...]
--d1261136-19f2-463e-ac7e-e8925c807c7d
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: attachment; filename=a.docx
[... some binary content ...]
--d1261136-19f2-463e-ac7e-e8925c807c7d
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: attachment; filename=a2.docx
[... some binary content ...]
--d1261136-19f2-463e-ac7e-e8925c807c7d--

如果您对如何使其工作有任何想法,请告诉我们。

感谢和问候,普里亚

您可以尝试在消息上设置内容类型,如下所示:

<set-property propertyName="Content-Type" value="application/pdf" doc:name="Content-Type"/>

您可以将"应用程序/pdf"替换为所需的值。这同样适用于要修改的其他属性。

我终于发现这是骡子的限制 - 在使用 message.addOutboundAttachment() 方法添加附件时,我们无法控制设置内容处置值。

解决此问题的方法是实现自己的 http 传输连接器,或使用任何 rest 客户端框架或 http 客户端库实现客户端。

以下内容

将正常工作,并将设置消息附件:-

<set-attachment value="#[message.payload]" contentType="application/pdf" attachmentName="#[message.inboundProperties['originalFilename']]" doc:name="Attachment" />

可以直接将#[message.inboundProperties['originalFilename']]替换为文件名,或者在使用文件入站终端节点时可以保持不变

相关内容

  • 没有找到相关文章

最新更新