Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Worklight 6.1和解析MTOM soap响应_Soap_Adapter_Ibm Mobilefirst_Mtom - Fatal编程技术网

Worklight 6.1和解析MTOM soap响应

Worklight 6.1和解析MTOM soap响应,soap,adapter,ibm-mobilefirst,mtom,Soap,Adapter,Ibm Mobilefirst,Mtom,我使用基于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 "

我使用基于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);
{
"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": [
]
}
函数getActions(用户名、密码){
var b64Auth=org.apache.commons.codec.binary.Base64.encodeBase64String(新的java.lang.String(username+':'+password.getBytes());
var bAuth=“Basic”+b64Auth;
var请求=
;
WL.Logger.debug(“SOAP请求”+请求);
变量输入={
方法:“post”,
returnedContentType:'plain',
路径:'/tririga/ws/TririgaWS',
标题:{授权:bAuth},
正文:{
内容:request.toString(),
//contentType:'应用程序/soap+xml;字符集=utf-8',
contentType:'text/xml;字符集=utf-8',
},
};
返回WL.Server.invokeHttp(输入);
}

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

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);
{
"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": [
]
}
{
“错误”:[
],
“信息”:[
],
“isSuccessful”:正确,
“负责人”:{
“缓存控制”:“无缓存=\”set-cookie,set-cookie2\“”,
“内容语言”:“en US”,
“内容类型”:“多部分\/相关;类型=\“应用程序\/xop+xml\”边界=\“uuid:db4e0265-c5be-460f-9115-04804f4b61f2\“开始=\”开始信息=“应用程序\/soap+xml\”,
“日期”:“2014年5月5日星期一14:02:49 GMT”,
“到期”:“1994年12月1日星期四格林威治标准时间16:00:00”,
“设置Cookie”:“JSESSIONID=0000dD8NqkZhfe2PngKJm-H5egF:-1;路径=\/;仅HttpOnly”,
“传输编码”:“分块”,
“X-Powered-By”:“Servlet\/3.0”
},
“响应时间”:173,
“状态代码”:200,
“状态原因”:“确定”,
“text”:“\n--uuid:db4e0265-c5be-460f-9115-04804f4b61f2\n内容类型:application\/xop+xml;charset=UTF-8;Type=\“application\/soap+xml\”;\n内容传输编码:二进制\n内容ID:\n\n167023539908231670235398022231670235487221670353847639\n--uuid:db4e0265-c5be-460f-9115-04804b61f2--”,
“总时间”:176,
“警告”:[
]
}
解析“文本”值的最佳方法是什么?xslt样式表?javascript


感谢您的帮助

您是否尝试将
returnedContentType
更改为XML

另见类似问题:


,幻灯片20-21

您的响应主体基本上是一个字符串。适配器将无法单独解析它。然而,响应包含手动解析它然后在适配器中操作它所需的一切

内容类型标题包含xml开始的指示符(“开始”属性)。您可以使用它来指定xml的开头,也可以只获取xml中的任何内容

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

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

如果将returnedContentType转换为“xml”,我会出现以下错误:“错误”:[“prolog中不允许内容],“无法从后端解析有效负载。”(过程:HttpRequest)“仅将returnedContentType设置为“普通”,不返回任何错误。