2014-05-05 393 views
1

我使用基於SOAP的服務請求創建了一個HTTP適配器。Worklight 6.1並解析MTOM肥皂響應

工作正常,但響應不是'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=\"<[email protected]>\"; 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: <[email protected]>\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?

感謝您的幫助

回答

0

你的身體的反應基本上是一個字符串。適配器將無法自行解析它。但是,響應包含您需要手動解析的所有內容,然後在適配器內對其進行處理。

Content-Type標頭包含xml start(「start」prop)的指示符。您可以用它來指定XML的開始或只是採取的

<soap:Envelope>...</soap:Envelope> 

不管裏面一旦你有你的XML作爲字符串 - 您可以使用Java代碼分析它,並返回到適配器解析的JSON,你將能夠操縱或返回給客戶。