春天-WS:SOAP错误不认定为故障(Spring-WS : Soap fault not iden

2019-10-23 14:18发布

我使用Spring-WS,并呼吁从webServiceTemplate通过marshalSendAndReceive Web服务时,我得到一个SOAP错误,错误代码500。 不幸的是,响应没有被识别为一个SOAP错误(它扔WebServiceTransportException)。 从理论上讲,当有错误响应,WebServiceTemplate抛出一个WebServiceTransportException如果错误码是2XX不同, 除非 HTTP错误是500和内容是肥皂故障。 下面是我得到的回应的例子:

    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错误它是什么?

Answer 1:

checkConnectionForFault物业WebServiceTemplate应该让你解决这个问题。



Answer 2:

我挖一点点到从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;
}

这意味着,必须有一个HTTP标头的ContentType = XML,这我调用Web服务未设置。 我现在研究如何设置头中的反应在Web服务模板被评为错误之前。



文章来源: Spring-WS : Soap fault not identified as Fault