dev@jersey.java.net

Re: [Jersey] Leading Spaces in JAXB

From: Minjal Shah <shahminjal_at_yahoo.co.in>
Date: Mon, 3 Aug 2009 16:09:10 +0530 (IST)

Hi Paul, The request that has leading spaces, was sent out using netcat. As you pointed out, the grammer does not allow it, BAD REQUEST is justified. Thanks ! But, now with the request like the below where the XMLDecl is omitted, does not mind getting leading spaces. 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: 112 <VSEDHCPConfigResource><a>value1</a><b>valueb</b><c>valuec</c><d>valued</d><e>valuee</e></VSEDHCPConfigResource> Please explain. Thanks, Minjal >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. ________________________________ From: Minjal Shah <shahminjal@yahoo.co.in> To: dev@jersey.dev.java.net Sent: Monday, 3 August, 2009 2:24:10 PM Subject: [Jersey] Leading Spaces in JAXB 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@Sun.COM> To: Minjal Shah <shahminjal@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 Yahoo! recommends that you upgrade to the new and safer Internet Explorer 8. http://downloads.yahoo.com/in/internetexplorer/