为 spring ws 禁用输出转义
Disable output escaping for spring ws
我对 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>
很难发现区别,但诀窍是所有 &
都被替换为 &
这是一个问题,因为服务器端的解析器无法解析它,因为到 Reference is not allowed in prologue
错误。没有这种奇怪的转义,请求就可以正常工作。
所以我的问题是,有什么方法可以禁用这种额外的转义吗?
我终于解决了这个问题。问题是进入 transElement.addTextNode(innerEnvelope);
的输入已经被 StringEscapeUtils
转义并且 apache 试图再次转义它,是什么导致 &
重新转义为 &
我对 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>
很难发现区别,但诀窍是所有 &
都被替换为 &
这是一个问题,因为服务器端的解析器无法解析它,因为到 Reference is not allowed in prologue
错误。没有这种奇怪的转义,请求就可以正常工作。
所以我的问题是,有什么方法可以禁用这种额外的转义吗?
我终于解决了这个问题。问题是进入 transElement.addTextNode(innerEnvelope);
的输入已经被 StringEscapeUtils
转义并且 apache 试图再次转义它,是什么导致 &
重新转义为 &