开发者

JAX-WS endpoint only partially escaping XML String

I have a JAX-WS endpoint with a number of methods that all return XML documents that are converted to a String.

This has been working fine on Sun Java System Application Server 9.1 Update 2 for some time, but needs to be deployed to a new server.

It was deployed to Glassfish 3.0.1 without any problem except one small issue. Original Response example excerpt:

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:getTransactionTypesResponse xmlns:ns2="http://myns.com.au/">
      <return xmlns="">&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;my_xml version="1.2" query_date=""&gt;
  &lt;add_transaction_type description="Contributions" name="Contribution" type="C"/&gt;
  &lt;add_transaction_type description="Transfer In" name="Xfr or R/O In" type="X"/&gt;
&lt;/my_xml&gt;
      </return>
    </ns2:getTransactionTypesResponse>
  </S:Body>
</S:Envelope>

On the new server it comes back as:

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:getTransactionTypesResponse xmlns:ns2="http://myns.com.au/">
      <return>&lt;?xml version="1.0" encoding="UTF-8"?>

&lt;myxml version="1.2" query_date="">
  &lt;add_transaction_type description="Contributions" name="Contribution" type="C"/>
  &lt;add_transaction_type description="Administration Fee" name="Fee:AUM" type="U"/>
&lt;/my_xml>
      </return>
    </ns2:getTransactionTypesResponse>
  </S:Body>
</S:Envelope>

Almost exactly the same but only the opening angle brackets are escaped, not the closing brackets.

I have tested this using direct HTTP POST requests so I know it is not being mangled by any client code.

I upgraded the server again to Glassfish 3.1 thinking there was a problem with the included webservice libraries but with no luck. My application relies totally on the webservice support in glassfish - it does not include any of its own WS or XML libraries.

The endpoint is basically defined as follows:

@WebService
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public class MyEndpoint {
  @WebMethod()
  public String getTransactionTypes() {
    return someMethodThatReturnsXmlString();
  }
}

I have been unable to find anyone else with this issue, except a reference from this poster who has observed it as a consumer of a service: Can I force JAXB not to开发者_运维知识库 convert " into &quot;, for example, when marshalling to XML?

This is a published service so I can't rely on consumers being able to update their clients to handle this. Interestingly my existing testing interface using a generated Java client doesn't seem bothered by it, but I can't rely on this.

Has anyone encountered this and been able to solve it? Is there a way I can hook into the WS framework and do my own escaping as a workaround?

Thanks in advance.


From http://www.w3.org/TR/xml/#syntax, section 2.4

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 " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and must, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

It states that the right angle bracket (>) may be escaped but does not have to be, so you should be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜