SAAJ SOAP 操作中的转义字符

发布于 2024-11-05 11:06:31 字数 2657 浏览 0 评论 0原文

我们有一段代码在 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>&lt;Message
 MessageType='FindCaseByCaseNumber' NodeID='1' ReferenceNumber='1'
UserID='1'
Source='APIMessage'&gt;&lt;CaseNumber&gt;T-4-CV-2011-004617&lt;/CaseNumber&gt;
&lt;/Message&gt;</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>&lt;Message
 MessageType=&quot;FindCaseByCaseNumber&quot; NodeID=&quot;1&quot; 
ReferenceNumber=&quot;1&quot; UserID=&quot;1&quot; Source=&quot;
APIMessage&quot;&gt;
&lt;CaseNumber&gt;T-4-CV-2011-004617&lt;/CaseNumber&gt;
  &lt;/Message&gt;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温折酒 2024-11-12 11:06:31

您可以使用反斜杠转义字符串中的引号:

OdysseyMessageXML.addTextNode("<Message
MessageType=\"FindCaseByCaseNumber\" NodeID=\"1\" ReferenceNumber=\"1\"
UserID=\"1\"
Source=\"APIMessage\"><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
); 

You can escape the quotes in your string with a backslash:

OdysseyMessageXML.addTextNode("<Message
MessageType=\"FindCaseByCaseNumber\" NodeID=\"1\" ReferenceNumber=\"1\"
UserID=\"1\"
Source=\"APIMessage\"><CaseNumber>T-4-CV-2011-004617</CaseNumber></Message>"
); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文