SAAJ SOAP 操作中的转义字符
我们有一段代码在 SAAJ SOAP 消息中创建 XML 消息:
OdysseyMessageXML.addTextNode("<Message
MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
);
当消息完成时,它看起来像这样:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tyl="http://www.tylertech.com/"><SOAP-ENV:Header/>
<SOAP-ENV:Body><tyl:OdysseyMsgExecution><tyl:OdysseyMessageXML><Message
MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'><CaseNumber>T-4-CV-2011-004617</CaseNumber>
</Message></tyl:OdysseyMessageXML>
<tyl:siteKey>NMODYSSEYMETRO</tyl:siteKey>
</tyl:OdysseyMsgExecution></SOAP-ENV:Body></SOAP-ENV:Envelope>
请注意,FindCaseByCaseNumber 和 NodeID 周围的 ' 标记不会被转义。我需要做什么才能得到这样的结果:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tyl="http://www.tylertech.com/">
<soapenv:Header/>
<soapenv:Body>
<tyl:OdysseyMsgExecution>
<tyl:odysseyMessageXML><Message
MessageType="FindCaseByCaseNumber" NodeID="1"
ReferenceNumber="1" UserID="1" Source="
APIMessage">
<CaseNumber>T-4-CV-2011-004617</CaseNumber>
</Message></tyl:odysseyMessageXML>
<tyl:siteKey> NMODYSSEYMETRO </tyl:siteKey>
</tyl:OdysseyMsgExecution>
</soapenv:Body>
</soapenv:Envelope>
使用 FindCaseByCaseNumber 周围的 "
任何人都可以告诉我我们做错了什么?我们已经在代码的 addTextNode 部分 ''' 和 """ 中进行了尝试,但在获取引号转义。
谢谢! Leslie
编辑:
在我们创建消息的代码部分:
OdysseyMessageXML.addTextNode("<Message
MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
);
我们需要它(请参阅每个值周围的双引号):
OdysseyMessageXML.addTextNode("<Message
MessageType="FindCaseByCaseNumber" NodeID="1" ReferenceNumber="1"
UserID="1"
Source="APIMessage"><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
);
不幸的是,这不是有效的 java 代码。通过在 FindCaseByCaseNumber 处放置另一个 " ,它会结束字符串。我们尝试放置 2 个和 3 个双引号,以便在最终消息中转义单个双引号。
更新: 看来接受我们请求的 API 是区分大小写的,我们使用的是大写 O 而不是小写 o,这最终是问题所在,而不是字符转义!
We have this bit of code creating an XML Message within a SAAJ SOAP message:
OdysseyMessageXML.addTextNode("<Message
MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
);
When the message is complete it looks like this:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tyl="http://www.tylertech.com/"><SOAP-ENV:Header/>
<SOAP-ENV:Body><tyl:OdysseyMsgExecution><tyl:OdysseyMessageXML><Message
MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'><CaseNumber>T-4-CV-2011-004617</CaseNumber>
</Message></tyl:OdysseyMessageXML>
<tyl:siteKey>NMODYSSEYMETRO</tyl:siteKey>
</tyl:OdysseyMsgExecution></SOAP-ENV:Body></SOAP-ENV:Envelope>
notice that the ' marks around FindCaseByCaseNumber and NodeID are NOT escaped. What do I need to do to get the results like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tyl="http://www.tylertech.com/">
<soapenv:Header/>
<soapenv:Body>
<tyl:OdysseyMsgExecution>
<tyl:odysseyMessageXML><Message
MessageType="FindCaseByCaseNumber" NodeID="1"
ReferenceNumber="1" UserID="1" Source="
APIMessage">
<CaseNumber>T-4-CV-2011-004617</CaseNumber>
</Message></tyl:odysseyMessageXML>
<tyl:siteKey> NMODYSSEYMETRO </tyl:siteKey>
</tyl:OdysseyMsgExecution>
</soapenv:Body>
</soapenv:Envelope>
with the " around FindCaseByCaseNumber
can anyone tell me what we are doing incorrectly? We have tried in the addTextNode portion of the code ''' and """ but have been unsuccessful in getting the quotes escaped.
thanks!
Leslie
edit:
In this section of the code where we are creating the message:
OdysseyMessageXML.addTextNode("<Message
MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
);
we need it to be (see double quotes around each value):
OdysseyMessageXML.addTextNode("<Message
MessageType="FindCaseByCaseNumber" NodeID="1" ReferenceNumber="1"
UserID="1"
Source="APIMessage"><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
);
unfortunately this is NOT valid java code. By placing another " at FindCaseByCaseNumber it ends the string. We have tried putting 2 and 3 double quotes in order to get a single double quote escaped in our final message.
Update:
It appears that the API that is accepting our request is case sensitive and we had a capital O instead of a lower case o which was ultimately the problem, not the character escaping after all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用反斜杠转义字符串中的引号:
You can escape the quotes in your string with a backslash: