【问题标题】:Worklight 6.1 and parse MTOM soap responseWorklight 6.1 并解析 MTOM soap 响应
【发布时间】:2014-05-05 16:23:40
【问题描述】:

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

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

例如我的soap请求如下

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": [
]
}

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

感谢您的帮助

【问题讨论】:

    标签: soap adapter ibm-mobilefirst mtom


    【解决方案1】:

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

    另见类似问题:IBM Worklight HTTP Adapter SOAP response: XSL transformation failed

    HTTP adapter training module,幻灯片 20-21

    【讨论】:

    • 返回内容类型为 'xml',我有以下错误:“错误”:[“序言中不允许内容。”,“无法从后端解析有效负载(过程:HttpRequest)”仅将内容类型返回为 'plain' 不会返回错误。
    【解决方案2】:

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

    Content-Type 标头包含 xml start 的指示符(“start” prop)。您可以使用它来指定 xml 的开头,也可以只取

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

    一旦您将 xml 作为字符串 - 您可以使用 Java 代码对其进行解析,并将其作为解析后的 JSON 返回到适配器,您将能够对其进行操作或返回给客户端。

    【讨论】:

      猜你喜欢
      • 2013-08-11
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 2019-04-25
      • 2021-06-07
      相关资源
      最近更新 更多