Ticket #371 (closed defect: fixed)
Redirector doesn't work with relative URI's
| Reported by: | jgou | Owned by: | bruno |
|---|---|---|---|
| Priority: | minor | Milestone: | 0.4 |
| Component: | modules/kauri-routing | Version: | |
| Keywords: | Cc: | kauri-discuss@… |
Description
In the router configuration router.groovy you can easily create an org.restlet.routing.Redirector.
e.g.
builder.router {
redirector(
uri: "/redirectme",
match: "equals",
mode: redirectorMode.MODE_CLIENT_SEE_OTHER,
targetTemplate: "<targetURI>"
)
...
}
It seems that the targetURI must be absolute, otherwise you get the following exception:
org.restlet - Exception intercepted while adding the response headers
java.lang.IllegalArgumentException: Relative references are only usable when a base reference is set.
at org.restlet.data.Reference.getTargetRef(Reference.java:1920)
at org.restlet.engine.http.header.HeaderUtils.addResponseHeaders(HeaderUtils.java:565)
...
At first sight it looks like a bug in org.restlet.routing.Redirector .
This should be investigated and if necessary reported on the restlet issue tracker.
Another solution could be to make the KauriModule.publicUri() function available in router.groovy, or support service:/ uri's in the redirector.
Change History
comment:2 Changed 3 years ago by mpo
of course /helloworld-router is as relative as helloworld-router
'absolute' in this regard would be http://localhost:8888/helloworld-router
In any case Location: headers need to be 'absolute' for sure, but I think it makes sense to try and suggest supporting the above 'relative' approach in restlet as well.
Next to that: I do think resolving service:/ uri's to their public counterparts would make sense as well. I suppose (need checking) that fiddling with the read and passed attributes Map in the org.kauriproject.routing.impl.groovybuild.factory.RedirectorFactory#newInstanceInner?
should do the trick?
comment:3 Changed 3 years ago by mpo
http://restlet.tigris.org/issues/show_bug.cgi?id=1190 introduces the suggestion upstream, and proposes a straightforward patch.
As for the support of service:/ uri's I've come to think the 'fiddling with the attributes' is not such a good idea: indeed if people create their own restlet they probably want to leave a Location service:/ uri as well and have it properly resolved prior to leaving the module context. All in all it felt like this should be a separate issue in its own right. (#377)
comment:4 Changed 3 years ago by mpo
patch applied upstream in
http://restlet.tigris.org/source/browse/restlet?view=rev&revision=6950
am building locally, will update pom and maven repo after testing
comment:5 Changed 3 years ago by mpo
- Status changed from new to closed
- Resolution set to fixed
(In [1727]) upgrading to restlet 6950 fixes #371
Note: This upgrade introduces an api change in the Router.
see http://restlet.tigris.org/source/browse/restlet/trunk/modules/org.restlet/src/org/restlet/routing/Router.java?r1=6867&r2=6901
trying to reproduce I get the same error when trying even an absolute template URI
redirector (uri: "/via-absolute", match: "equals", mode: redirectorMode.MODE_CLIENT_SEE_OTHER, targetTemplate: "/helloworld-router");(using the kauri-routing-sample)
The only thing that does work is along these lines:
restlet(uri: "/via2", handle: { request, response -> response.redirectSeeOther(new Reference(request.getResourceRef(), "helloworld-router")); })Which is of course way beyond what should be needed.
But it does suggest that Redirector.java be patched at line 195 from
to
need some further investigation into restlet to make sure.