gpt4 book ai didi

java - 使用 Spring 的 SOAP 服务。转义特殊字符

转载 作者:行者123 更新时间:2023-12-02 06:53:53 33 4
gpt4 key购买 nike

我有一个使用 Spring 框架开发的 SOAP Web 服务。每当请求包含一些无效数据时,我需要显示如下错误消息

Error occurred. Invalid data for <Field Name>.

所以我的代码如下所示,用于名称验证。当名称字段没有传递任何值时,此错误将作为响应发送。

Assert.notNull(name, "Error occurred. No value passed for the field <name>. ");

所以我期望的是

Error occurred. No value passed for the field <name>.

但是 SOAP UI 中的响应如下所示。

Error occurred. No value passed for the field &lt;name>.

如何在 SOAP UI 中显示正确的 < 符号?我试过CDATA。但不确定接收方如何使用 CDATA 处理请求。

SOAP UI 中的 CDATA 消息如下所示

Error occurred. No value passed for the field <![CDATA[<]]name>.

最佳答案

XML 规范指出:

The ampersand character (&) and the left angle bracket (<) must not appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they must be escaped using either numeric character references or the strings " &amp; " and " &lt; " respectively. The right angle bracket (>) may be represented using the string " &gt; ", and must, for compatibility, be escaped using either " &gt; " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

因此,您需要转义错误字符串中的左尖括号:

Error occurred. No value passed for the field &lt;name>.

或者将整个错误字符串封装在 CDATA 部分中:

<![CDATA[Error occurred. No value passed for the field <name>.]]>

有关更多信息,请参阅 http://www.w3.org/TR/xml/#syntax

关于java - 使用 Spring 的 SOAP 服务。转义特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17651528/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com