Вопрос

I have a SOAP web service developed using Spring framework. Whenever the request contains some invalid data i need to display error message like below

Error occurred. Invalid data for <Field Name>.

So my code looks as below for name validation. This error will be sent as response wheneve no value passed for the name field.

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

So what i expected as out out is

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

But the response in SOAP UI was like below.

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

How to display the proper < symbol in SOAP UI? I tried CDATA. But not sure how the receiver process the request with CDATA.

With CDATA message in SOAP UI was like below

Error occurred. No value passed for the field <![CDATA[<]]name>.
Это было полезно?

Решение

The XML Specification states:

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.

So, you need to either escape the left angle bracket in your error string:

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

Or encapsulate the entire error string in a CDATA section:

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

For more information see http://www.w3.org/TR/xml/#syntax

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top