![](/img/trans.png)
[英]Is it possible to instruct Spring-WS to generate a WSDL containing wsdl:fault?
[英]Spring-WS : Soap fault not identified as Fault
我正在使用Spring-WS,當通過webServiceTemplate中的marshalSendAndReceive調用Web服務時,我收到錯誤代碼為500的SOAP Fault。 不幸的是,響應沒有被識別為SOAP錯誤(它拋出WebServiceTransportException)。 理論上,當存在錯誤響應時,如果錯誤代碼與2xx不同,WebServiceTemplate將拋出WebServiceTransportException, 除非 http錯誤為500並且內容是soap錯誤。 以下是我得到的回復示例:
HTTP/1.1 500 Internal Server Error[\r][\n]"
Content-Length: 887[\r][\n]"
Connection: keep-alive[\r][\n]"
2015-07-01 10:38:22,873 DEBUG [o.s.ws.client.core.WebServiceTemplate] Received error for request [SaajSoapMessage {http://www.example.com/schema/front}use]
2015-07-01 10:38:22,874 DEBUG [org.apache.http.wire] << "<?xml version="1.0" encoding="UTF-8"?>[\n]"
2015-07-01 10:38:22,874 DEBUG [org.apache.http.wire] << "[\n]"
2015-07-01 10:38:22,874 DEBUG [org.apache.http.wire] << "<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">[\n]"
2015-07-01 10:38:22,874 DEBUG [org.apache.http.wire] << " <SOAP-ENV:Body>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <SOAP-ENV:Fault>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <faultcode>SOAP-ENV:Server</faultcode>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <faultstring>Request service/operation version not supported</faultstring>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <faultactor>Server</faultactor>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <detail>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <ns0:serviceException xmlns:ns0="http://www.example.com/facade/interface/v1_1">[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <ns1:message xmlns:ns1="http://www.example.com/common/v1_3">InternalCode01</ns1:messageId>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " <ns1:text xmlns:ns1="http://www.example.com/common/v2_1">Request service/operation version not supported</ns1:text>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " </ns0:serviceException>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " </detail>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " </SOAP-ENV:Fault>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << " </SOAP-ENV:Body>[\n]"
2015-07-01 10:38:22,875 DEBUG [org.apache.http.wire] << "</SOAP-ENV:Envelope>"
有誰知道為什么會這樣? 有沒有辦法將它視為SOAP故障?
WebServiceTemplate
的checkConnectionForFault
屬性應該允許您解決此問題。
我從AbstractHttpSenderConnection(將被調用以確定錯誤是否是soap錯誤)中挖掘了一些hasFault方法,我看到該方法的下一個代碼:
/*
* Faults
*/
public final boolean hasFault() throws IOException {
return HttpTransportConstants.STATUS_INTERNAL_SERVER_ERROR == getResponseCode() && isXmlResponse();
}
/** Determine whether the response is a XML message. */
private boolean isXmlResponse() throws IOException {
Iterator<String> iterator = getResponseHeaders(HttpTransportConstants.HEADER_CONTENT_TYPE);
if (iterator.hasNext()) {
String contentType = iterator.next().toLowerCase();
return contentType.indexOf("xml") != -1;
}
return false;
}
這意味着,必須有一個帶有ContentType = xml的http標頭,我正在調用的Web服務沒有設置。 我現在必須研究如何在Web服務模板中評估錯誤之前在響應中設置該標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.