SOAP namespace(命名空间) 错误生成到 body 里的解决方案

最近维护就项目出现个问题,在server上生成的  SOAP 的 namespace 生成到了 里面, 如下


        
            100
        


而本地却没有这个问题,xml如下:


        
            100
        
    


1. 试试加上这个这个 jar


         com.sun.xml.ws
          jaxws-rt
          2.2.6-6
 


2. 代码解决

SOAPMessage message = context.getMessage();

 SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();

SOAPBody body = envelope.getBody();

if(body.hasAttributes() &&
                        (body.hasAttribute("xmlns") || body.hasAttribute("xmlns:ns1") ||
                                body.hasAttribute("xmlns:ns2") || body.hasAttribute("xmlns:ns3"))){
                    
                    Iterator elements = body.getChildElements();
                    while(elements.hasNext()){
                        SOAPElement el = elements.next();
                        List prefixList = IteratorUtils.toList(body.getNamespacePrefixes());
                        
                        for(String prefix : prefixList){
                            el.addNamespaceDeclaration(prefix, body.getNamespaceURI(prefix));
                            body.removeNamespaceDeclaration(prefix);
                        }
                    }
                }

你可能感兴趣的:(遇到的各种问题)