简体   繁体   English

Spring-WS:肥皂故障未被识别为故障

[英]Spring-WS : Soap fault not identified as Fault

I am using Spring-WS, and I am getting a SOAP Fault with error code 500 when calling the web service via marshalSendAndReceive from the webServiceTemplate. 我正在使用Spring-WS,当通过webServiceTemplate中的marshalSendAndReceive调用Web服务时,我收到错误代码为500的SOAP Fault。 Unfortunately, the response is not being recognized as a SOAP fault (it is throwing a WebServiceTransportException). 不幸的是,响应没有被识别为SOAP错误(它抛出WebServiceTransportException)。 In theory, when there is an error response, WebServiceTemplate throws a WebServiceTransportException if the error code is different to 2xx, unless the http error is 500 and the content is a soap fault. 理论上,当存在错误响应时,如果错误代码与2xx不同,WebServiceTemplate将抛出WebServiceTransportException, 除非 http错误为500并且内容是soap错误。 Here is an example from the response I get: 以下是我得到的回复示例:

    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>"

Does anyone know why is it happening? 有谁知道为什么会这样? Is there a way to just treat it as the SOAP fault it is? 有没有办法将它视为SOAP故障?

WebServiceTemplatecheckConnectionForFault属性应该允许您解决此问题。

I digged a little bit into the hasFault method from AbstractHttpSenderConnection (the one that will be called to decide if the error is a soap fault or not), and I see the next code for that method: 我从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;
}

That means, that there has to be an http header with ContentType = xml, which the web service I am calling is not setting. 这意味着,必须有一个带有ContentType = xml的http标头,我正在调用的Web服务没有设置。 I have to research now how to set that header in the responses before the error is evaluated in the web service template. 我现在必须研究如何在Web服务模板中评估错误之前在响应中设置该标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM