Jerome,
We're still finding some missing pieces trying to get this accomplished.
Below is a note from one of my colleagues on her current approach.
Thank you,
Leigh.



Here's what I found when I tried to store information into the attributes of 
org.restlet.data.Request.  I've got it working but it is relying on the fact 
that I looked at the implementation.  I'm probably missing another class that I 
need to subclass in order to make this right but I'm just not seeing it right 
now.  If you do, let me know and I'll fix this before I checkin.
I have a servlet that extends com.noelios.restlet.ext.servlet.ServerServlet.  
It overwrites the service method and calls super.service after it's done a few 
things (storing into the HttpServletRequest's attributes so that the 
information can be retrieved later and put into the org.restlet.data.Request 
attributes).

ServerServlet.server gets a com.noelios.restlet.http.HttpServlerHelper and 
calls helper.handle(new ServletCall(helper.getServer(),request, response)) 

where request and response are javax.servlet.http.HttpServletRequest and 
javax.servlet.http.HttpServletResponse respectively.  (The handle method 
eventually calls into the Finder's that I wrote.)

 ServletCall extends com.noelios.restlet.http.HttpServerCall.  ServletCall 
keeps the request and response (but doesn't pass them to HttpServerCall).

 As far as I can tell, HttpServerHelper is responsible for creating the 
restlet's Request.  It does this with a call to 
           HttpRequest request = getConverter().toRequest(httpCall);
The problem is that the httpCall is an HttpServerCall which doesn't keep the 
javax.servlet.http.HttpServletRequest (only ServletCall does that).

I currently have my own HttpServerConverter (returned by getConverter above) 
that overwrites the toRequest method.  The method is 
            public HttpRequest toRequest(HttpServerCall httpCall);
Currently, I'm checking to see if httpCall is an instance of ServletCall, and 
if so getting the attributes out of the javax.servlet.http.HttpServletRequest 
and putting them in the restlet's Request attributes.  This works but relies on 
the fact that I've read the code and know that I really will have a 
ServletCall. 

-----Original Message-----
From: Jerome Louvel [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 12, 2007 12:19 AM
To: [email protected]
Subject: Re: Servlet Connector and passing per-request attributes


Leigh,

Thanks for the detailled background info. You current workaround works
but is indeed not very satisfactory. A better way would be to use the
Restlet's Request.getAttributes() method and to automatically copy any
Servlet's request attribute in the Restlet's request attributes map.

This will require a change to ServerServlet and will only go in Restlet
1.1. You can try to create a subclass of ServerServlet for now in order
to do this copy yourself.

Best regards,
Jerome

Klotz, Leigh a écrit :
> I'm trying out Restlets in a Tomcat servlet container.
>
> As part of the integration testing, I'm using an existing servlet to
> establish authentication and resource access tokens, then using the
> servlet API
> servletContext.getRequestDispatcher(location).forward(request, response)
> to forward to a RESTLet connected using
> com.noelios.restlet.ext.servlet.ServerServlet.  My plan was to put the
> objects necessary for the servlet to access my existing application's
> resources on the HttpServletRequest inside my servlet with
> httpServletRequest.setAttribute(key, value) and then retrieve them in
> the org.restlet.resource.Resource implementation.
>
> I'm not finding a path way that provides the Resource with access to the
> javax.servlet.http.HttpServletRequest object, or its Attributes.
>
> I'm not using an IOC framework
>
> I've read
> http://restlet.tigris.org/servlets/ReadMsg?list=discuss&&msgNo=397 but
> it seems not to have happened (at least, there is no Maplet and some of
> the other classes mentioned aren't there either.)
>
> I need a way to pass this information through on a per-request basis
> (i.e., they aren't servlet init parameters).
>
> I've got the following hack but it's clearly wrong.
>
>   private Object getHttpRequestAttribute(String name) {
>     Request request = getRequest();
>     com.noelios.restlet.http.HttpRequest hr =
> (com.noelios.restlet.http.HttpRequest)request;
>     com.noelios.restlet.http.HttpCall hc = hr.getHttpCall();
>     com.noelios.restlet.ext.servlet.ServletCall sc =
> (com.noelios.restlet.ext.servlet.ServletCall)hc;
>     HttpServletRequest hsr = sc.getRequest();
>     return (hsr.getAttribute(name));
>   }
>  
> Do you have any suggestions for how to re-cast the problem or how to
> pass the objects?
>
> Thank you,
> Leigh.
>
>  


Reply via email to