我在soap body中的响应有效负载是空的.Below是在api manager中配置的自定义处理程序代码。我打印了正文,它显示为空。我的休息api应该返回数据列表。
public boolean handleResponse(MessageContext messageContext)
{
try {
RelayUtils.buildMessage(((Axis2MessageContext) messageContext).getAxis2MessageContext());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info("Response Body:"+messageContext.getEnvelope().getBody());
}
如果API的响应状态正常,它的工作正常,但在ACCEPT状态下,响应正文为空。
This is my logs after enabling the wire. Please help. Thanks in advance.
In Case of @ResponseStatus(value=HttpStatus.OK) wire log
=================================================================
"GET /customer/list HTTP/1.1[\r][\n]"
[2016-10-07 13:48:58,643] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2016-10-07 13:48:58,643] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Accept-Encoding: gzip, deflate, sdch, br[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Postman-Token: 780f0eac-254b-d93e-9801-93fe8bac79a6[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Accept: */*[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Cache-Control: no-cache[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Host: localhost:8088[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "Connection: Keep-Alive[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2016-10-07 13:48:58,644] DEBUG - wire HTTP-Sender I/O dispatcher-1 << "[\r][\n]"
[2016-10-07 13:48:58,646] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "HTTP/1.1 200 OK[\r][\n]"
[2016-10-07 13:48:58,646] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "Server: Apache-Coyote/1.1[\r][\n]"
[2016-10-07 13:48:58,646] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
[2016-10-07 13:48:58,646] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "Transfer-Encoding: chunked[\r][\n]"
[2016-10-07 13:48:58,646] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "Date: Fri, 07 Oct 2016 08:18:58 GMT[\r][\n]"
[2016-10-07 13:48:58,647] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "[\r][\n]"
[2016-10-07 13:48:58,647] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "5a[\r][\n]"
[2016-10-07 13:48:58,647] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "[{"id":"1","name":"abc"},{"id":"2","name":"bcd"},{"id":"3","name":"cde"}]"
[2016-10-07 13:48:58,652] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "[\r][\n]"
[2016-10-07 13:48:58,652] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "0[\r][\n]"
[2016-10-07 13:48:58,652] DEBUG - wire HTTP-Sender I/O dispatcher-1 >> "[\r][\n]"
[2016-10-07 13:48:58,700] INFO - MessageBuilderHandler Response body: `<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <jsonArray><?xml-multiple jsonElement?>
<jsonElement>
<id>1</id>
<name>abc</name>
</jsonElement>
<jsonElement><id>2</id>
<name>bcd</name>
</jsonElement>
<jsonElement>
<id>3</id>
<name>cde</name>
</jsonElement>
</jsonArray>
</soapenv:Body> `
[2016-10-07 13:48:58,868] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "HTTP/1.1 200 OK[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Access-Control-Allow-Origin: *[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Access-Control-Allow-Methods: GET[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Content-Type: application/json;charset=UTF-8[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Date: Fri, 07 Oct 2016 08:18:58 GMT[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Transfer-Encoding: chunked[\r][\n]"
[2016-10-07 13:48:58,869] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "Connection: keep-alive[\r][\n]"
[2016-10-07 13:48:58,870] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "[\r][\n]"
[2016-10-07 13:48:58,870] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "54[\r][\n]"
[2016-10-07 13:48:58,870] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "[
{"id":1,"name":"abc"},
{"id":2,"name":"bcd"},
{"id":3,"name":"cde"}
][\r][\n]"
[2016-10-07 13:48:58,870] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "0[\r][\n]"
[2016-10-07 13:48:58,870] DEBUG - wire HTTPS-Listener I/O dispatcher-2 << "[\r][\n]"
In Case of @ResponseStatus(value=HttpStatus.ACCEPTED) wire log
===================================================================
DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "GET /GetCustomerList/1.0.0/customer/list HTTP/1.1[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Host: localhost:8243[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Connection: keep-alive[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Authorization: Bearer 93cdc897-f75b-351e-ab4e-e4bd347bc742[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Cache-Control: no-cache[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Postman-Token: 6c341e45-3d95-10af-d3b8-1e1f25360d18[\r][\n]"
[2016-10-07 13:52:37,060] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Accept: */*[\r][\n]"
[2016-10-07 13:52:37,061] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Accept-Encoding: gzip, deflate, sdch, br[\r][\n]"
[2016-10-07 13:52:37,061] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2016-10-07 13:52:37,061] DEBUG - wire HTTPS-Listener I/O dispatcher-4 >> "[\r][\n]"
[2016-10-07 13:52:37,070] INFO - MessageBuilderHandler Reqest body:
<soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>
[2016-10-07 13:52:37,081] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "GET /customer/list HTTP/1.1[\r][\n]"
[2016-10-07 13:52:37,082] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Accept-Language: en-US,en;q=0.8[\r][\n]"
[2016-10-07 13:52:37,082] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Accept-Encoding: gzip, deflate, sdch, br[\r][\n]"
[2016-10-07 13:52:37,082] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Postman-Token: 6c341e45-3d95-10af-d3b8-1e1f25360d18[\r][\n]"
[2016-10-07 13:52:37,082] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Accept: */*[\r][\n]"
[2016-10-07 13:52:37,083] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Cache-Control: no-cache[\r][\n]"
[2016-10-07 13:52:37,083] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Host: localhost:8088[\r][\n]"
[2016-10-07 13:52:37,083] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "Connection: Keep-Alive[\r][\n]"
[2016-10-07 13:52:37,083] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2016-10-07 13:52:37,083] DEBUG - wire HTTP-Sender I/O dispatcher-2 << "[\r][\n]"
[2016-10-07 13:52:37,309] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "HTTP/1.1 202 Accepted[\r][\n]"
[2016-10-07 13:52:37,309] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "Server: Apache-Coyote/1.1[\r][\n]"
[2016-10-07 13:52:37,309] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "Content-Type: application/json;charset=UTF-8[\r][\n]"
[2016-10-07 13:52:37,310] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "Transfer-Encoding: chunked[\r][\n]"
[2016-10-07 13:52:37,310] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "Date: Fri, 07 Oct 2016 08:22:37 GMT[\r][\n]"
[2016-10-07 13:52:37,310] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "[\r][\n]"
[2016-10-07 13:52:37,311] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "5a[\r][\n]"
[2016-10-07 13:52:37,311] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "[{"id":"1","name":"abc"},{"id":"2","name":"bcd"},{"id":"3","name":"cde"}][\r][\n]"
[2016-10-07 13:52:37,312] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "0[\r][\n]"
[2016-10-07 13:52:37,312] DEBUG - wire HTTP-Sender I/O dispatcher-2 >> "[\r][\n]"
[2016-10-07 13:52:37,317] INFO - MessageBuilderHandler Response body:`<soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>`
[2016-10-07 13:52:37,320] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "HTTP/1.1 202 Accepted[\r][\n]"
[2016-10-07 13:52:37,321] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Access-Control-Allow-Headers: authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction[\r][\n]"
[2016-10-07 13:52:37,321] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Access-Control-Allow-Origin: *[\r][\n]"
[2016-10-07 13:52:37,321] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Access-Control-Allow-Methods: GET[\r][\n]"
[2016-10-07 13:52:37,321] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Content-Type: application/json;charset=UTF-8[\r][\n]"
[2016-10-07 13:52:37,321] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Date: Fri, 07 Oct 2016 08:22:37 GMT[\r][\n]"
[2016-10-07 13:52:37,322] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Transfer-Encoding: chunked[\r][\n]"
[2016-10-07 13:52:37,322] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "Connection: keep-alive[\r][\n]"
[2016-10-07 13:52:37,322] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "[\r][\n]"
[2016-10-07 13:52:37,322] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "0[\r][\n]"
[2016-10-07 13:52:37,322] DEBUG - wire HTTPS-Listener I/O dispatcher-4 << "[\r][\n]
答案 0 :(得分:0)
根据你的问题,你说当后端用202代码响应时响应体是空的,当后端响应代码是200时,你可以从上面的代码逻辑中访问后端响应。首先,当http代码为202时,你必须实际检查响应主体是否来自后端。为此你可以启用[1]中的有线日志,用于wso2 apimanager并检查后端响应。
[1] http://mytecheye.blogspot.com/2013/09/wso2-esb-all-about-wire-logs.html