0

I am facing an issue at our glassfish 3.1.2 production server. I have a Jersey REST project deployed and it is throwing URISyntaxException when there is a 'space' in path parameter for any URL. For example if I hit this URL: http://MyDomain:8080/MyApp/MyVersion/MyService/MyPathParam/My%20Path%20param Jersey throws java.lang.IllegalArgumentException with root cause java.net.URISyntaxException: Illegal character in path at index 155: http://MyDomain:8080/MyApp/MyVersion/MyService/MyPathParam/My Path param

The error does not occurs for query parameter. This issue is not reproducible at test environment. Is there any possibility at production glassfish which decodes path parameters before Jersey gets them and jersey throws the above exception? I gone through this link which specifies that glassfish has the facility to decode the request parameters before it reaches to our application, but I didn't get the clear idea. Please help me to get rid of this issue.

Community
  • 1
  • 1
user1120946
  • 171
  • 1
  • 2
  • 13

2 Answers2

1

It is not a good policy to use "spaces" on URLs (URIs) - see more discussion here Is a URL allowed to contain a space?. They are considered "unsafe" (http://www.ietf.org/rfc/rfc1738.txt):

The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs.

Not sure if some "containers" allow this on the URIs (the "query parameters" may be allowed as they are encoded), but even if some allow you should seriously consider not using them. Not sure if this fits your scenario, but you could try URLEncoder.encode() as suggested in this other questions where a similar exception is raised: What I have to do to solve "java.lang.IllegalArgumentException"? (although in the same question there is a debate about using "spaces"... but maybe this is useful for you).

Community
  • 1
  • 1
emgsilva
  • 3,047
  • 1
  • 17
  • 16
  • Yes, I agree with your point that spaces should be avoided in URL but as it is working fine at test environment, it will be hard to convince client to change the implementation. – user1120946 Oct 03 '13 at 08:55
  • are you also using glassfish on development? what are the major differences on development and production setups - probably it will help if you add this to your original question. – emgsilva Oct 03 '13 at 10:11
  • Yes, I use Glassfish on development. Issue doesn't reproduce on development too. And unfortunately, I don't have access to client's glassfish! (test as well as production) :( – user1120946 Oct 04 '13 at 08:50
  • it is indeed a weird situation... I have updated my answer with some further material that you may want to try in your setup (namely `URLEncoder.encode()`). HTH. – emgsilva Oct 04 '13 at 09:09
  • 1
    Finally, the Apache Load Balancer was the culprit! :) mod_jk was decoding the URL and it was forwarding decoded URL to one of the glassfish server. Hence it jersey was throwing URISyntaxException. Issue resolved by changing the property **JkOptions** +ForwardURICompat to **+ForwardURICompatUnparsed** – user1120946 Oct 09 '13 at 09:04
  • good you got it working... I suggest you create an answer with that and mark as the solution to your problem, in that way other people can find the answer to you problem faster. – emgsilva Oct 09 '13 at 09:08
0

The Apache Load Balancer was the culprit! mod_jk was decoding the URL and it was forwarding decoded URL to one of the glassfish server. Hence jersey jax rs was throwing URISyntaxException. Issue resolved by changing the property JkOptions of mod_jk configuration from +ForwardURICompat to +ForwardURICompatUnparsed

user1120946
  • 171
  • 1
  • 2
  • 13