spring-ws
WebserviceTemplate
我已经创建了像这样的WebserviceMessage
public WebServiceMessage createWebServiceMessage(String innerEnvelope)
{
SOAPMessage soapMsg=null;
MessageFactory factory;
try
{
factory = MessageFactory.newInstance();
soapMsg = factory.createMessage();
SOAPPart part = soapMsg.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPBody body = envelope.getBody();
QName ejbName = new QName(EJB_VALUE,"lustraciaOsoby",EJB_PREFIX);
SOAPElement ejbElement =body.addBodyElement(ejbName);
ejbElement.addNamespaceDeclaration(SOAP_ENV_PREFIX, SOAP_ENV_VALUE);
ejbElement.setAttribute("soapenv:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/");
QName transName=new QName(TRANS_ELEMENT);
SOAPElement transElement = ejbElement.addChildElement(transName);
transElement.addNamespaceDeclaration(XSI_PREFIX, XSI_VALUE);
transElement.addNamespaceDeclaration(XSD_PREFIX, XSD_VALUE);
transElement.setAttribute("xsi:type", "xsd:string");
transElement.addTextNode(innerEnvelope);
soapMsg.saveChanges();
} catch (SOAPException e)
{
LOGGER.debug("Error while creating message",e);
}
return (WebServiceMessage)new SaajSoapMessage(soapMsg);
}
导致XML看起来像这样(这是对此Web服务的100%有效请求,使用标准HttpConnection
它返回了有效响应)
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/><SOAP-ENV:Body><ejb:lustraciaOsoby xmlns:ejb="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<transXmlEnc xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">
<TransEnv xmlns="http://schemas.mvsr.sk/clk/clk2/lustracia_osoby_in_transxml.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
cPageSize="50" cRecNoFrom="0">
<LOI><SI>2,3,5,8,19</SI><PR>Mrkvička</PR><PR_PARTIAL>false</PR_PARTIAL><PR_FUZZY>false</PR_FUZZY><ME>Ján</ME><ME_PARTIAL>false</ME_PARTIAL><ME_FUZZY>false</ME_FUZZY><LV_ANYNAME>false</LV_ANYNAME>
</LOI></TransEnv>
</transXmlEnc>
</ejb:lustraciaOsoby>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
仅仅是为了获取信息,转义部分的内容就像肥皂肥皂一样,在服务器端解析。
问题是,当我使用sendSourceAndReceiveToResult
执行此操作时,发送的最终SOAP
采用此格式
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ejb:lustraciaOsoby
xmlns:ejb="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<transXmlEnc xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:string">
&lt;TransEnv xmlns=&quot;http://schemas.mvsr.sk/clk/clk2/lustracia_osoby_in_transxml.xsd&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; cPageSize=&quot;50&quot; cRecNoFrom=&quot;0&quot;&gt;&lt;LOI&gt;&lt;SI&gt;2,3,5,8,19&lt;/SI&gt;&lt;PR&gt;Mrkvi&#269;ka&lt;/PR&gt;&lt;PR_PARTIAL&gt;false&lt;/PR_PARTIAL&gt;&lt;PR_FUZZY&gt;false&lt;/PR_FUZZY&gt;&lt;ME&gt;J&#225;n&lt;/ME&gt;&lt;ME_PARTIAL&gt;false&lt;/ME_PARTIAL&gt;&lt;ME_FUZZY&gt;false&lt;/ME_FUZZY&gt;&lt;LV_ANYNAME&gt;false&lt;/LV_ANYNAME&gt;&lt;/LOI&gt;&lt;/TransEnv&gt;
</transXmlEnc>
</ejb:lustraciaOsoby>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
很难发现差异,但诀窍是所有&
都被&
替换,这是一个问题,因为服务器端的解析器由于{而无法解析它{1}}错误。如果没有这种奇怪的逃脱,请求就可以了。
所以我的问题是,有没有办法禁用这个额外的转义?
答案 0 :(得分:0)
最后我能够解决这个问题。问题是来到transElement.addTextNode(innerEnvelope);
的输入已经被StringEscapeUtils
转义,并且apache试图再次逃脱它,导致&
重新绑定到&
的原因