I haven't dug into this code, but I suspect you aren't manipulating References properly. I advise printing out the intermediate steps of your Reference computation to see where it goes wrong.
Also, the template argument to Redirector is ignored if you override getTargetRef. --tim On Sat, Apr 27, 2013 at 6:03 PM, Grant <gsing...@apache.org> wrote: > > I don't understand what you mean by "the handling of the {rr} template". > > The approach I suggested, overriding getTargetRef, ignores the template > > argument entirely. > > > > In my old code, I had: > URI = hardcoded URI to resource > Redirector redir = new Redirector(router.getContext(), URI + "{rr}", > Redirector.MODE_SERVER_OUTBOUND); > router.attach("", redir, Template.MODE_STARTS_WITH); > > So, when I pass in http://foo:port/a/b/c, it redirects to URI/a/b/c > > In my new code, I pass in the target template simply as {rr} and then iin > the getTargetRef, I do: > protected Reference getTargetRef(Request request, Response response) { > URI serviceURI = serviceLocator.getServiceURI(service); //THIS looks > up the location of the service > // Create the template > Template rt = new Template(this.targetTemplate); > rt.setLogger(getLogger()); > > // Return the formatted target URI > if (new Reference(this.targetTemplate).isRelative()) { > // Be sure to keep the resource's base reference. > //Reference baseRef = new Reference(serviceURI.uri); > if (log.isInfoEnabled()) { > log.info("dynRedir from {} to {}", request.getResourceRef(), > serviceURI.uri); > } > String format = rt.format(request, > response); > try { > return new Reference(new URI(serviceURI.uri.toString() + format)); > } catch (URISyntaxException e) { > log.error("Exception", e); > throw new RuntimeException(e); > } > } > > return new Reference(rt.format(request, response)); > } > /////////////////// > > I attach my DynamicRedirector at, for example, "/a". When I pass in > "http://foo:port/a/b/c", I want it to select my DynamicRedirector due to > the "/a" (I'm using STARTS_WITH mode) part and then redirect to the target > by passing along "b/c" (i.e. the {rr} part) such that the new URL would be > something like "http://dynamicHost:port/b/c", based on what my > serviceLocator returns. Like I said, it works great if I'm just matching > at "/a", but it doesn't handle the "/b/c" part. AFAICT, the handle() > methods in Restlet are continuing to resolve down to the last endpoint > (i.e. "b/c") even though it has a match at "/a". > > I will see if I can work up a standalone test example to demonstrate it. > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3054458 > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3054459