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