dev@jersey.java.net

Re: [Jersey] Leading Spaces in JAXB

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 03 Aug 2009 11:25:41 +0200

Hi,

The second example you present is not a well-formed XML document,
because there are space characters before the prolog, and any
conforming XML parser will fail to parse such a document.

The grammer of an XML document starts with:

   document ::= prolog element Misc*

         prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?

    XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'

Note that there is no optional space characters declared before the
"XMLDecl". The start of an XML document MUST begin with a '<'
character encoded in a Unicode character encoding, such as UTF-8 or
UTF-16.

What HTTP client are you using? and why is it adding spaces before the
XML document?

Paul.

On Aug 3, 2009, at 10:54 AM, Minjal Shah wrote:

> Hi Paul,
>
> Below are the two cases :
>
> The request that works:
> POST /abc/xyz HTTP/1.1
> Content-Type: application/xml
> Host: localhost:9998
> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> Content-Length: 167
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?
> ><VSEDHCPConfigResource><a>value1</a><b>valueb</b><c>valuec</
> c><d>valued</d><e>valuee</e></VSEDHCPConfigResource>
>
>
> The request that fails : (leading spaces in message body)
> POST /abc/xyz HTTP/1.1
> Content-Type: application/xml
> Host: localhost:9998
> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> Content-Length: 169
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?
> ><VSEDHCPConfigResource><a>value1</a><b>valueb</b><c>valuec</
> c><d>valued</d><e>valuee</e></VSEDHCPConfigResource>
>
> This handling of leading spaces is what is expected to be the
> default behavior with the apps ? Is there a way to override this?
> There is one more observation. The leading spaces are handled if <?
> xml version="1.0" encoding="UTF-8" standalone="yes"?> is removed
> from the message body. Why this difference in the handling ?
>
> Thanks,
> Minjal
>
>
>
> From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
> To: Minjal Shah <shahminjal_at_yahoo.co.in>
> Sent: Monday, 3 August, 2009 12:38:34 PM
> Subject: Re: [Jersey] Leading Spaces in JAXB
>
>
> On Aug 3, 2009, at 8:23 AM, Minjal Shah wrote:
>
>> Hi Paul,
>>
>> I had a query.
>> When jersey/JAXB handles trailing spaces and spaces in between the
>> tags in the xml body, why does it throw a BAD REQUEST when the xml
>> body has leading spaces ?
>>
>
> Can you send me an example of the latter as i am not totally sure
> what you mean?
>
> I suspect the wrapped exception in the bad request is originating
> from the XML parser because the XML document is not well formed, but
> i would need to see the stack trace to confirm that or not.
>
> Paul.
>
>
>> Please explain.
>>
>> Thanks,
>> Minjal
>
> Looking for local information? Find it on Yahoo! Local