Java 使用SpringWS在soap请求中发送XmlData
我需要将Java 使用SpringWS在soap请求中发送XmlData,java,soap,spring-ws,Java,Soap,Spring Ws,我需要将CDATA中的XmlData发送到soap请求,该请求返回一个附件 使用org.springframework.oxm.jaxb.Jaxb2Marshaller作为封送器和解封器 Test]]>这是我想在soap请求中发送的内容,远程服务希望它以同样的方式发送 我已经创建了数据,但是当我使用webServiceTemplate.MarshallSendReceive(payloadRequest,SoapActionCallback) 不知何故,负载请求xmltags被编码并显示为 ![
CDATA
中的XmlData
发送到soap请求,该请求返回一个附件
使用org.springframework.oxm.jaxb.Jaxb2Marshaller
作为封送器和解封器
Test]]>
这是我想在soap请求中发送的内容,远程服务希望它以同样的方式发送
我已经创建了数据,但是当我使用webServiceTemplate.MarshallSendReceive(payloadRequest,SoapActionCallback)
不知何故,负载请求xmltags被编码并显示为
![CDATA[tagTest\tag
由于这种编码,远程服务无法处理请求并发送
org.springframework.ws.soap.client.SoapFaultClientException:对象引用未设置为对象的实例。
我如何解决这个问题?有什么建议吗
更新:是不是web.xml中spring mvc的defaultHtmlEscape作为上下文参数导致了这种行为?我在今天的工作中遇到了同样的问题,我们必须在从银行web服务公开的WSDL中定义的数据结构的字段文本上注入CDATA部分 要求引入一个CDATA节,将Unicode字符“+”转义到数字电话字段中。WSDL不可能因各种原因而更改 我们有同样的环境:
org.springframework.oxm.jaxb.Jaxb2Marshaller
webServiceTemplate.marshalSendAndReceive(payloadRequest, SoapActionCallback)
同样的失败结果
<![CDATA[<tag>+<\tag>
而不是
<[[CDATA[+]]>
此回调将从MarshalSendReceive调用
PayloadSoapResponse output = (PayloadSoapResponse ) getWebServiceTemplate()
.marshalSendAndReceive(input, callbackCDATANumTelefono);
结果是正确发送请求,CDATA部分有效且未转换为ascii字符
该解决方案的目标是使用JAXB技术在Spring基础设施上管理CDATA部分,而不是使用第三方库。
一般来说,回调方法的指令集非常可靠,可以在web服务soap的所有环境中注入。关键的方面是使用规范方法在更友好的DOMSource中转换SoapMessage以探索节点。也可以使用XPath引擎导航此DOMSource
祝你好运
am在使用spring ws生成SOAP web服务时,我遇到了这个问题。CDATA部分将始终被转义,如上所述 在我的例子中,解决方案(非常类似于Alessandro)是创建一个EndpointInterceptor,在这里我将所需的节点转换为HandlerResponse中的org.w3c.dom.CDATA节。 然后,您需要将此拦截器添加到实现中的拦截器列表中
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.server.EndpointInterceptor;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.w3c.dom.CDATASection;
import javax.xml.soap.Node;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import java.util.Iterator;
public class MyCdataInterceptor implements EndpointInterceptor {
@Override
public boolean handleRequest(MessageContext messageContext, Object o) throws Exception {
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {
WebServiceMessage response = messageContext.getResponse();
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response;
SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
Iterator it = body.getChildElements();
...
/* find node of interest */
Node interestingNode = (Node) blah.getNextSibling();
CDATASection cdat = soapPart.createCDATASection(interestingNode.getFirstChild().getNodeValue());
interestingNode.removeChild(interestingNode.getFirstChild());
interestingNode.appendChild(cdat);
return true;
}
@Override
public boolean handleFault(MessageContext messageContext, Object o) throws Exception {
return true;
}
@Override
public void afterCompletion(MessageContext messageContext, Object o, Exception e) throws Exception {
}
}
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.server.EndpointInterceptor;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.w3c.dom.CDATASection;
import javax.xml.soap.Node;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import java.util.Iterator;
public class MyCdataInterceptor implements EndpointInterceptor {
@Override
public boolean handleRequest(MessageContext messageContext, Object o) throws Exception {
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {
WebServiceMessage response = messageContext.getResponse();
SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response;
SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
Iterator it = body.getChildElements();
...
/* find node of interest */
Node interestingNode = (Node) blah.getNextSibling();
CDATASection cdat = soapPart.createCDATASection(interestingNode.getFirstChild().getNodeValue());
interestingNode.removeChild(interestingNode.getFirstChild());
interestingNode.appendChild(cdat);
return true;
}
@Override
public boolean handleFault(MessageContext messageContext, Object o) throws Exception {
return true;
}
@Override
public void afterCompletion(MessageContext messageContext, Object o, Exception e) throws Exception {
}
}