Thierry Boileau <[email protected]> wrote on 01/26/2010 02:21:31
AM:
>
> could you provide a sample application?
Hi, Thierry-
I'm having a little trouble getting a sample app put together that
demonstrates the exact behavior - I'm not getting ANY response in my
sample app, even though it looks like it's trying to return exactly the
WadlRepresentation I've described. The Response entity isn't making it
back into my httpclient.OptionsMethod's response body, for some reason.
That exercise has helped me figure out what's going on, though. There's a
wrinkle in what I'm doing, and it's why I'm having a problem. I route to
resource A using either {http://myhost/a} or {https://myhost/a} but I
route to resource B using only {https://myhost/b}. If a request comes in
for {http://myhost/b}, I redirect to {https://myhost/b} using a filter.
This works great - I don't know if it's the preferred solution, but I've
had no difficulty with it.
@Override
public Restlet createRoot()
{
Context context = getContext();
Router rootRouter = new Router(context);
Router httpsRouter = new Router(context);
Filter redirectToHttpsFilter = new Filter() {
@Override
protected int beforeHandle(Request request, Response response)
{
org.restlet.data.Protocol protocol = request.getProtocol();
if (protocol.equals(org.restlet.data.Protocol.HTTP))
{
Reference ref = request.getResourceRef();
String hostDomain = ref.getHostDomain();
String path = ref.getPath();
response.redirectPermanent("https://" + hostDomain +
":8443" + path);
return STOP;
}
return super.beforeHandle(request, response);
}
};
rootRouter.attach("/a", ResourceA.class).setMatchingMode(Template.
MODE_EQUALS);
rootRouter.attachDefault(redirectToHttpsFilter);
redirectToHttpsFilter.setNext(httpsRouter);
httpsRouter.attach("/b", ResourceB.class).setMatchingMode(Template.
MODE_EQUALS);
return rootRouter;
}
Here's what seems to be happening with the WADL stuff: when the
ResourceInfo is created for rootRouter, it calls getResourceInfos(), which
goes through all of its routes and retrieves the children's ResourceInfos.
However, because the filter is configued as the "default" without a
route, it doesn't get enumerated. Using the code above, when I step
through getResourceInfos(), router.routes has one entry ("/a"), and
router.defaultRoute is not checked.
I changed the code above by explicitly adding:
rootRouter.attachDefault(redirectToHttpsFilter);
rootRouter.attach("", redirectToHttpsFilter);
and everything seems to be working now.
Remaining questions: should Router.attachDefault() add the new default
route to Router.routes? Or should WadlApplication.getResourceInfos()
check to make sure that it looks at the defaultRoute if it isn't included
in the routes list?
Anyway, thanks for your help!
--------------------------------
John Wismar
mailto:[email protected]
From:
Thierry Boileau <[email protected]>
To:
[email protected]
Date:
01/26/2010 02:21 AM
Subject:
Re: Using WADL classes with filters - use WadlWrapper?
Hello John,
could you provide a sample application? I've just tried with a
WadlApplication and WadlResources (having the same routing plan than you)
and it works for me: that is to say when I send a request option to the
application root URI, I get the description of all resources. The
WadlApplication is normally able to walk across filters.
Best regards,
Thierry Boileau
Hi, all-
I'm using Restlet 1.1.7. I have a situation where my routing chain looks
like:
router +- filter -- filter -- router +- resource C
+- resource A +- resource D
+- resource B +- etc....
My Application and all Resources are Wadl- versions.
When I retrieve the WADL for my app, I get the information about the
resource A and resource B, but not C, D, and so on. I'm guessing that I
can solve this by using WadlWrapper to wrap the filters I'm using, but
it's not clear to me how that is intended to work.
Does anyone have any sample code that shows WadlWrapper in action? Or any
hints about how the filters can be wrapped, and the ResourceInfo
initialized and returned? Or am I looking at this the wrong way, and is
there a different way to retrieve the information about the Resources
behind the filters?
Thanks for your help!
--------------------------------
John Wismar
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2442230