无法在Spring Web Service的soap响应中正确显示命名空间

时间:2013-03-20 22:18:00

标签: java spring soap marshalling

我似乎无法从根目录中删除ns0。我做错了什么?

拦截

@Override
    public boolean handleFault(MessageContext messageContext, Object endpoint) {

        SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext.getResponse();
        SoapMessage soapMessage = (SoapMessage) messageContext.getResponse();

        try {
            SOAPMessage saajMessage = saajSoapMessage.getSaajMessage();
            saajMessage.getSOAPPart().getEnvelope().setPrefix("soapenv");
            saajMessage.getSOAPPart().getEnvelope().removeNamespaceDeclaration("SOAP-ENV");
            saajMessage.getSOAPPart().getEnvelope().addNamespaceDeclaration("ims", "http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p");
            saajMessage.getSOAPHeader().setPrefix("soapenv");
            saajMessage.getSOAPBody().setPrefix("soapenv");
            saajMessage.saveChanges();
        } catch (SOAPException e) {
            e.printStackTrace();
        }

正确

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ims="http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p0">

不正确

<soapenv:Envelope ns0:ims="ims" xmlns:ns0="http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

1 个答案:

答案 0 :(得分:0)

我通过更新订单来修复此问题

try {
            SOAPMessage saajMessage = saajSoapMessage.getSaajMessage();

            saajMessage.getSOAPPart().getEnvelope().removeNamespaceDeclaration("SOAP-ENV");
            saajMessage.getSOAPPart().getEnvelope().addNamespaceDeclaration("ims", "http://www.imsglobal.org/services/lis/cmsv1p0/wsdl11/sync/imscms_v1p");
            saajMessage.getSOAPPart().getEnvelope().setPrefix("soapenv");
            saajMessage.getSOAPHeader().setPrefix("soapenv");
            saajMessage.getSOAPBody().setPrefix("soapenv");
            saajMessage.saveChanges();
        } catch (SOAPException e) {
            e.printStackTrace();
        }