Worklight 6.1并解析MTOM soap响应

时间:2014-05-05 16:23:41

标签: soap adapter ibm-mobilefirst mtom

我使用基于SOAP的服务请求创建了一个HTTP适配器。

工作正常,但响应不是'xml'格式。

例如我的肥皂请求如下

function getActions(username,password) {

var b64Auth = org.apache.commons.codec.binary.Base64.encodeBase64String(new java.lang.String(username+':'+password).getBytes());
var bAuth = "Basic " + b64Auth;

var request =  
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ws="http://ws.tririga.com">
<soap:Header/>
<soap:Body>
    <ws:getActionItems/>
</soap:Body>
</soap:Envelope>;

WL.Logger.debug("SOAP Request " + request);

var input = {
        method : 'post',
        returnedContentType : 'plain',
        path : '/tririga/ws/TririgaWS',
        headers: { Authorization: bAuth },
        body: {
             content: request.toString(),
             //contentType: 'application/soap+xml; charset=utf-8',
             contentType: 'text/xml; charset=utf-8',
            },
};

return WL.Server.invokeHttp(input);

}

在WL.server.invokeHTTP之后,来自后端的响应如下

{
"errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
  "Cache-Control": "no-cache=\"set-cookie, set-cookie2\"",
  "Content-Language": "en-US",
  "Content-Type": "multipart\/related; type=\"application\/xop+xml\"; boundary=\"uuid:db4e0265-c5be-460f-9115-04804f4b61f2\"; start=\"<root.message@cxf.apache.org>\"; start-info=\"application\/soap+xml\"",
  "Date": "Mon, 05 May 2014 14:02:49 GMT",
  "Expires": "Thu, 01 Dec 1994 16:00:00 GMT",
  "Set-Cookie": "JSESSIONID=0000dD8NqkZhfe2PngKJm-H5egF:-1; Path=\/; HttpOnly",
  "Transfer-Encoding": "chunked",
  "X-Powered-By": "Servlet\/3.0"
},
"responseTime": 173,
"statusCode": 200,
"statusReason": "OK",
"text": "\n--uuid:db4e0265-c5be-460f-9115-04804f4b61f2\nContent-Type: application\/xop+xml; charset=UTF-8; type=\"application\/soap+xml\";\nContent-Transfer-Encoding: binary\nContent-ID: <root.message@cxf.apache.org>\n\n<soap:Envelope xmlns:soap=\"http:\/\/www.w3.org\/2003\/05\/soap-envelope\"><soap:Body><ns1:getActionItemsResponse xmlns:ns1=\"http:\/\/ws.tririga.com\"><ns1:out><ns2:ActionItem xmlns:ns2=\"http:\/\/dto.ws.tririga.com\"><ns2:taskId>167023<\/ns2:taskId><ns2:workflowId>53990823<\/ns2:workflowId><\/ns2:ActionItem><ns2:ActionItem xmlns:ns2=\"http:\/\/dto.ws.tririga.com\"><ns2:taskId>167023<\/ns2:taskId><ns2:workflowId>53980223<\/ns2:workflowId><\/ns2:ActionItem><ns2:ActionItem xmlns:ns2=\"http:\/\/dto.ws.tririga.com\"><ns2:taskId>167023<\/ns2:taskId><ns2:workflowId>53848722<\/ns2:workflowId><\/ns2:ActionItem><ns2:ActionItem xmlns:ns2=\"http:\/\/dto.ws.tririga.com\"><ns2:taskId>167023<\/ns2:taskId><ns2:workflowId>53847639<\/ns2:workflowId><\/ns2:ActionItem><\/ns1:out><\/ns1:getActionItemsResponse><\/soap:Body><\/soap:Envelope>\n--uuid:db4e0265-c5be-460f-9115-04804f4b61f2--",
"totalTime": 176,
"warnings": [
]
}

解析“text”值的最佳方法是什么? xslt样式表? javascript?

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

您是否尝试将returnedContentType更改为XML?

另请参阅此类似问题:IBM Worklight HTTP Adapter SOAP response: XSL transformation failed

HTTP adapter training module,幻灯片20-21

答案 1 :(得分:0)

您的回复正文基本上是一个字符串。适配器无法自行解析它。但是,响应包含手动解析所需的所有内容,然后在适配器中对其进行操作。

Content-Type标头包含xml start的指示符(&#34; start&#34; prop)。您既可以使用它来指定xml的开头,也可以使用

中的任何内容
<soap:Envelope>...</soap:Envelope>

一旦你把你的xml作为字符串 - 你可以使用Java代码解析它并返回到适配器作为解析的JSON,你将能够操作或返回到客户端。