Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.1
-
Java 5, Spring, Rest Client to access ATOM based Rest Services
Description
I am using Wink to query/read several backend services using the Atom Protocol.
One of those produces farely ugly URLs with "[" and "]" within the URL strings.
When reading from a feed these URLs are already escaped like this http://myserver/dm/atom/library/%5B@Pgistest/@RMain.nsf%5D/feed .
This way I can use them directly to read the next feed:
URI uri = URI.create(uriString);
new RestClient().resource(uri);
At this point everything is fine, but as it continues an exception is thrown
java.lang.IllegalArgumentException: schemeSpecificPart is invalid
at org.apache.wink.common.internal.UriBuilderImpl.schemeSpecificPart(UriBuilderImpl.java:867)
at org.apache.wink.common.internal.UriBuilderImpl$$EnhancerByCGLIB$$927fbbec.CGLIB$schemeSpecificPart$24(<generated>)
at org.apache.wink.common.internal.UriBuilderImpl$$EnhancerByCGLIB$$927fbbec$$FastClassByCGLIB$$10e694a6.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at de.gish.lc.services.wink.RuntimeDelegateImpl$1.intercept(RuntimeDelegateImpl.java:39)
at org.apache.wink.common.internal.UriBuilderImpl$$EnhancerByCGLIB$$927fbbec.schemeSpecificPart(<generated>)
at org.apache.wink.common.internal.UriBuilderImpl.uri(UriBuilderImpl.java:961)
at org.apache.wink.common.internal.UriBuilderImpl$$EnhancerByCGLIB$$927fbbec.CGLIB$uri$0(<generated>)
at org.apache.wink.common.internal.UriBuilderImpl$$EnhancerByCGLIB$$927fbbec$$FastClassByCGLIB$$10e694a6.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at de.gish.lc.services.wink.RuntimeDelegateImpl$1.intercept(RuntimeDelegateImpl.java:39)
at org.apache.wink.common.internal.UriBuilderImpl$$EnhancerByCGLIB$$927fbbec.uri(<generated>)
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:81)
at org.apache.wink.client.internal.ResourceImpl.<init>(ResourceImpl.java:72)
at org.apache.wink.client.RestClient.resource(RestClient.java:99)
at de.gish.lc.rest.connection.impl.StaticUserLoginBasedConnectionFactory.getResource(StaticUserLoginBasedConnectionFactory.java:105)
at de.gish.lc.services.wink.AbstractWinkService.readAtomFeed(AbstractWinkService.java:175)
at de.gish.lc.services.wink.QuickrServiceWink.readFeed(QuickrServiceWink.java:47)
at de.gish.lc.services.wink.QuickrServiceWink.readLibraryFeedForEntry(QuickrServiceWink.java:119)
at de.gish.lc.services.QuickrServiceTest.readLibraryFeedForEntry(QuickrServiceTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.net.URISyntaxException: Illegal character in path at index 39: https://quickr.gish.de/dm/atom/library/[@Pgistest/@RMain.nsf]/feed
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:3066)
at java.net.URI$Parser.parse(URI.java:3014)
at java.net.URI.<init>(URI.java:807)
at org.apache.wink.common.internal.UriBuilderImpl.schemeSpecificPart(UriBuilderImpl.java:865)
... 48 more
This looks like it is out of the public UriBuilder schemeSpecificPart(String ssp) throws IllegalArgumentException
{...}but as I investigated further the "ssp" String now is "//myserver/dm/atom/library/[@Pgistest/@RMain.nsf]/feed"
which means that the brackts ("[" and "]") are not escaped any more.
The call comes from
public UriBuilder uri(URI uri) throws IllegalArgumentException {
....
if (uri.getSchemeSpecificPart() != null)
{ logger.debug("Constructing schemeSpecificPart"); schemeSpecificPart(uri.getSchemeSpecificPart()); } ....
}
The URI object I created at the beginning with the escape characters for the brackets now returns an unescaped URI string as result of uri.getSchemeSpecificPart().
As this is used as a direct input for constructing a new URI object within this part of the UriBuilderImpl this leads to an IllegalArgumentException.
public UriBuilder schemeSpecificPart(String ssp) throws IllegalArgumentException {
...
URI uri = null;
try
catch (URISyntaxException e)
{ throw new IllegalArgumentException("schemeSpecificPart is invalid", e); } ....
}
This leads to the conclusion that URIs with special characters like brackets are currently not supported as (feed) urls.
My current workaround is to use a proxy for the UriBuilderImpl class which catches the Exception and will than encode the part of the URI again before use.
Enhancer e = new Enhancer();
e.setSuperclass(originalBuilder.getClass());
e.setCallback(new MethodInterceptor() {
public Object intercept(Object obj, java.lang.reflect.Method method, Object[] args, MethodProxy proxy) throws Throwable {
Object result;
if ("schemeSpecificPart".equals(method.getName())) {
try
catch (IllegalArgumentException iae) {
String ssp = (String) args[0];
String encoded = UriUtils.encodeUri(ssp, "UTF-8");
LOG.debug("in [{}], out [{}]", new Object[]
);
// set encoded value:
result = proxy.invokeSuper(obj, new Object[]
);
}
} else
{ // do normal execution result = proxy.invokeSuper(obj, args); } return result;
}
});
As we are using the Spring framework I used the UriUtils from Spring to escape the URI string again.
As this is just a workaround not a solution, I hope for a fix within Wink to handle this.