我们有点卡住,不知道如何在骡子邮件中发送附件。我们有一些代码可以添加出站附件,但Content-Disposition和Content-Type的值由mule自动生成,并且与服务器上的预期不匹配。我已经粘贴了我们正在生成的消息,即预期的消息(请注意内容类型和内容处置的差异)。
内容处理必须是有效载荷上的“内联”和data-file.xml部分的“附件”,而是mule生成Content-Disposition:form-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--
如果您对如何使其发挥作用有任何想法,请告诉我们。
谢谢和问候, 普里亚
答案 0 :(得分:0)
您可以尝试按如下方式在邮件上设置Content-Type:
<set-property propertyName="Content-Type" value="application/pdf" doc:name="Content-Type"/>
您可以替换&#39; application / pdf&#39;与您的期望值。这同样适用于您要修改的其他属性。
HTH
答案 1 :(得分:0)
我终于发现这是mule的限制 - 我们无法控制使用message.addOutboundAttachment()方法添加附件时设置内容处置值。
此解决方法是使用任何其他客户端框架或http客户端库实现您自己的http传输连接器或实现您的客户端。
答案 2 :(得分:0)
以下内容可以正常使用,并会在邮件中设置附件: -
<set-attachment value="#[message.payload]" contentType="application/pdf" attachmentName="#[message.inboundProperties['originalFilename']]" doc:name="Attachment" />
如果您使用文件入站端点,可以直接将#[message.inboundProperties['originalFilename']]
替换为文件名,也可以保持不变