作为我的worklight项目的一部分,我们正在调用一个Web服务,该服务将图像文件作为MTOM附件发送。有没有办法解析图像内容并转换为JSON对象?下面是我的适配器中的一段代码,我配置了服务调用:
var input = {
method : 'post',
returnedContentType : 'plain',
path: '/contentaccess-ws/ContentAccessDocument_1',
body : {
content: retrieveDocumentRequest.toString(),
contentType : 'application/soap+xml; charset=utf-8'
}
};
以下是回复:
--MIMEBoundary_89c65bb62e242e7ee812d596799431326111505dc1baf518
Content-Type: application/xop+xml; charset=utf-8;
type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID: <0.99c65bb62e242e7ee812d596799431326111505dc1baf518@apache.org>
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body><c:retrieveDocumentResponse xmlns:a="http://docs.oasis.open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:b="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:c="http://nationwide.com/schemas/Communication/iaa7_1/Content/DocumentManagement_1">
<c:Document><c:Attachments type="Content">
<c:Attachment><c:Name>Photo.jpg</c:Name>
<c:MimeType>image/jpeg</c:MimeType><c:Size>147623</c:Size>
<c:DataContent><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:a9c65bb62e242e7ee812d596799431326111505dc1baf518@apache.org"/></c:DataContent>
</c:Attachment></c:Attachments>
<c:Properties><c:Property><c:Name>Id</c:Name><c:Value>{D0C04F-0000-C511-983F-4BD2AB945534}</c:Value></c:Property><c:Property><c:Name>F_PAGES</c:Name><c:Value></c:Value></c:Property></c:Properties>
</c:Document><c:Status>Successful</c:Status>
</c:retrieveDocumentResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundary_89c65bb62e242e7ee812d596799431326111505dc1baf518
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <a9c65bb62e242e7ee812d596799431326111505dc1baf518@apache.org>
????_JFIF___HH??(ExifMM*__?i___??8Photoshop 3.08BIM__8BIM_%_?_?ُ?_? ???B~
___?_?__"______??_________________
_???_____________}_______!1A__Qa_"q_2???_#B??_R??$3br?
___%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz?????????????????????????????? ?????????????????????????????????????????????____________________
_???______________w______!1__AQ_aq_"2?__B???? #3R?_br?
_$4?%? ____&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz????????????????????????????????? ?????????????????????????????????????????C______ __ - -=---- =M=====M]MMMMMM]]]]]]]]pppppp?????????????????C____%#%@##@? hUh????????????????????????????????????????????????????_^??
我尝试将“returnedContentType”作为“JSON”但没有用(服务会引发错误)。
任何指针都表示赞赏!
答案 0 :(得分:1)
适配器不会为您执行此操作。
您需要做的是从适配器获取响应,并使用能够将图像附件解码为真实图像的框架。
通常不使用MOTM。而是将base64编码为字符串,然后将字符串解码回图像。