users@jersey.java.net

Re: [Jersey] Slashes in query string

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 15 Jul 2009 13:14:26 +0200

On Jul 15, 2009, at 1:12 PM, Paul Sandoz wrote:

> Hi Martin,
>
> Note that it is the '{' character that is causing the issue in the
> example you presented. If you remove the '{' and '}' then it should
> work.
>
> IMHO the browsers are not conforming to HTTP 1.1 that specifies a
> normative dependency on RFC2396:
>
> For definitive information on URL syntax and semantics, see
> "Uniform Resource Identifiers (URI): Generic Syntax
> and Semantics," RFC 2396 [42] (which replaces RFCs 1738 [4] and RFC
> 1808 [11]). This specification adopts the
> definitions of "URI-reference", "absoluteURI", "relativeURI",
> "port", "host","abs_path", "rel_path", and "authority"
> from that specification.
>
> http://greenbytes.de/tech/webdav/rfc2616.html#general.syntax
>
>
> The way to fix this (which may related to another issue with '{' and
> '}' in paths but is likely to be harder to fix because of the way
> java.net.URI is utilized) is for the UriBuilder implementation to
> have a mode where by '{' and "}' characters are not treated as
> syntax for template parameters. Then when Jersey builds the URI and
> adds the query parameter
>

[finish the sentence!] the '{' and "}' characters will get percent
encoded.

Paul.

> Would you mind logging an issue?
>
> Thanks,
> Paul.
>
> On Jul 15, 2009, at 12:15 PM, Martin Probst wrote:
>
>> Hi,
>>
>> I've noticed an odd thing when trying out URIs with a slash in the
>> query string with a browser. E.g. if I type this into my browsers
>> address bar:
>>
>> http://localhost:9999/REST/_query?xquery=<res>{count(//
>> *:dependency)}</res>
>>
>> I get the attractive stack trace below. It happens with both Safari 4
>> and Firefox 3.5. After perusing the specs a bit, I think the issue is
>> that java.net.URI parses URIs according to RFC 2396. And the query
>> component part of http://www.apps.ietf.org/rfc/rfc2396.html#sec-3.4
>> specifies that the character '/' is reserved in a query (as well as
>> several others). The browsers seem to implement RFC 3986, and there
>> (see http://labs.apache.org/webarch/uri/rfc/rfc3986.html#query) the
>> query string may contain a '/' (and also a '?').
>>
>> I know this is massively ugly, but maybe a workaround would be to
>> manually escape those characters before passing them to URI? Or does
>> anyone know of a compliant RFC 3986 implementation for Java?
>>
>> The stack trace:
>>
>> javax.ws.rs.core.UriBuilderException: java.net.URISyntaxException:
>> Illegal character in query at index 50:
>> http://localhost:9999/REST/_query?xquery=%3Cres%3E{count(//
>> *:dependency)}%3C/res%3E
>> at
>> com.sun.jersey.api.uri.UriBuilderImpl.createURI(UriBuilderImpl.java:
>> 600)
>> at
>> com.sun.jersey.api.uri.UriBuilderImpl._build(UriBuilderImpl.java:544)
>> at com.sun.jersey.api.uri.UriBuilderImpl.build(UriBuilderImpl.java:
>> 534)
>> at
>> com
>> .sun
>> .jersey
>> .spi
>> .container.servlet.ServletContainer.service(ServletContainer.java:
>> 586)
>> at .... snip ....
>> at org.mortbay.thread.QueuedThreadPool
>> $PoolThread.run(QueuedThreadPool.java:520)
>> Caused by: java.net.URISyntaxException: Illegal character in query at
>> index 50: http://localhost:9999/REST/_query?xquery=%3Cres
>> %3E{count(//*:dependency)}%3C/res%3E
>> at java.net.URI$Parser.fail(URI.java:2809)
>> at java.net.URI$Parser.checkChars(URI.java:2982)
>> at java.net.URI$Parser.parseHierarchical(URI.java:3072)
>> at java.net.URI$Parser.parse(URI.java:3014)
>> at java.net.URI.(URI.java:578)
>> at
>> com.sun.jersey.api.uri.UriBuilderImpl.createURI(UriBuilderImpl.java:
>> 598)
>> ... 20 more
>>
>> Martin
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>