Hi guys!
Upgrading from jersey-core 1.17.1 to 1.18.1, and we are experiencing a
potential bug with regards to URL encoding.
The following test case shows the issue:
public class JsonEncodingTest extends JerseyTest {
@Test
public void testJsonEncoding() {
resource().queryParam("json", "{\"foo\":\"bar\"}");
}
}
In 1.17.1 everything is fine, java.net.URI#URI(java.lang.String)
constructor is called with the parameter:
http://localhost:9998/?json=%7B%22foo%22:%22bar%22%7D
In 1.18.1 it fails with the exception below. The value passed to the URI
constructor is then:
http://localhost:9998/?json=%7B"foo":"bar"%7D
Is this a known issue, are we doing something wrong, or should I file a bug?
Best regards,
Alf Kristian
The stacktrace:
javax.ws.rs.core.UriBuilderException: java.net.URISyntaxException:
Illegal character in query at index 31:
http://localhost:9998/?json=%7B
"foo":"bar"%7D
at
com.sun.jersey.api.uri.UriBuilderImpl.createURI(UriBuilderImpl.java:723)
at
com.sun.jersey.api.uri.UriBuilderImpl._build(UriBuilderImpl.java:651)
at
com.sun.jersey.api.uri.UriBuilderImpl.build(UriBuilderImpl.java:641)
at
com.sun.jersey.api.client.WebResource.<init>(WebResource.java:88)
at
com.sun.jersey.api.client.WebResource.queryParam(WebResource.java:443)
at
com.comoyo.analytics.instrumentation.rs.InstrumentationTest.testJsonEncoding(InstrumentationTest.java:844)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.net.URISyntaxException: Illegal character in query
at index 31:
http://localhost:9998/?json=%7B"foo":"bar"%7D
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at
com.sun.jersey.api.uri.UriBuilderImpl.createURI(UriBuilderImpl.java:721)
... 28 more