我已使用以下代码处理错误并将错误消息设置为响应
String envelopeError = "<soapenv:Error xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
+ " <Error_Message>" + errorMsg + "</Error_Message>\n"
+ " </soapenv:Error>";
OMElement myOMElement = null;
try {
myOMElement = AXIOMUtil.stringToOM(envelopeError);
SOAPEnvelope soapEnvelope = TransportUtils.createSOAPEnvelope(myOMElement);
messageContext.setEnvelope(soapEnvelope);
} catch (XMLStreamException | AxisFault e) {
log.error("Error occurred while handling failure: " + errorMsg, e);
}
但是,当我发送错误的请求时,只有POST调用才能获得json
格式的响应。 GET调用以文本形式获取响应。
我使用的示例命令如下:
POST命令:
curl -X POST \
https://ipaddress:8243/postcall \
-H 'Accept: application/json' \
-H 'Authorization: Bearer 83fe925f-f054-3c27-bd7c-b9228aea48a0' \
-H 'Content-Type: application/json' \
-d '{ .... }'
GET命令:
curl -k -X GET "https://ipaddress:8243/getcall"
-H 'Accept: application/json'
-H "Authorization: Bearer 0ca12e9b-490a-3ca5-bc01-d24703e6fb9b"
-H 'Content-Type: application/json'