Spring WS客户端处理HTML而不是SOAP Fault

时间:2014-07-21 21:02:33

标签: spring web-services soap spring-ws apache-commons-httpclient

我有一个调用许多不同Web服务的SOAP客户端。在某些情况下,有些人会发回带有HTTP错误状态代码而不是SOAP错误的HTML错误页面。我知道他们应该发送SOAP错误,但我希望能够处理这种情况。我希望能够访问HTML错误页面。现在,当我返回带有200状态代码的HTML错误页面时,抛出了SoapMessageCreationException,我抓住了它。带有HTTP错误状态代码的HTML错误页面抛出WebServiceTransportException。如何在此时访问响应中的HTML数据?我使用org.springframework.ws.transport.http.CommonsHttpMessageSender(Jakarta Commons HttpClient)作为消息发送者,使用Spring 2.0。

我希望代码能够使用默认的邮件发件人,否则,我只会检查邮件发件人的实例是否是CommonsHttpMessageSender。我现在不想升级到Spring-WS 3 / Apache HttpComponents,但如果有必要,我愿意接受它。如果我调用this.webserviceTemplate.getMessageSenders(),是否总是可以选择第一个([0])?

try {    
    this.webserviceTemplate.sendSourceAndReceiveToResult(source,
            new WebServiceMessageCallback() {
                @Override
                public void doWithMessage(WebServiceMessage message)
                        throws IOException, TransformerException {
                    if (LOG.isDebugEnabled()) {
                        // log the SOAP request
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        message.writeTo(out);
                        LOG.debug("SOAP Request Payload: " + new String(out.toByteArray()));
                    }

                    if (soapActionHttpHeader != null) {
                        ((SoapMessage)message).setSoapAction(soapActionHttpHeader);
                        LOG.debug("Setting SOAP Action HTTP header to: " + soapActionHttpHeader);
                    }
                    else
                        LOG.debug("SOAP Action HTTP not set in the configuration.");
                }
            }, result);
}
    catch (SoapMessageCreationException e) 
{//org.springframework.ws.transport.http.CommonsHttpMessageSender
        String errorMsg= "Error processing SOAP message";
        LOG.info(errorMsg);
        LOG.debug("Stack trace: ",e);
        throw new ServiceInvocationException(errorMsg);
    }
    catch (WebServiceTransportException e) {
        String errorMsg= "Error invoking SOAP service";
        LOG.info(errorMsg);
        LOG.debug("Stack trace: ",e);
        throw e;
    }
    catch (WebServiceIOException e) {
        throw new ServiceInvocationException(e);
    }

0 个答案:

没有答案