Hi Jerome,

As I said the server side isn't an option and I need to do this  
systematically. The Filter seems like the way to go. You're right that  
I was sending through the client instead of the filter. However my  
aplication expects a Client object and the Filter does not have the  
same API. Do I need to instead extend Client instead of filter?

You may want to reconsider how Filter hooks in. It's inappropriate for  
it to change the API. A Filter should really attach to an object, not  
wrap it.

Jean-Philippe



On May 5, 2010, at 4:36 AM, Jerome Louvel <jerome.lou...@noelios.com>  
wrote:

> Hi Jean-Philippe,
>
>
>
> If your goal is to systematically add cookies to your client  
> requests, you should definitely use the Restlet API (Request#cookies  
> property) instead of setting a custom header. To set the cookies on  
> the server-side, you need instead to use the Response#cookieSettings  
> property. For complete mapping between Restlet API and HTTP headers,  
> check this page:
>
> http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/324-restlet/130-restlet.html
>
>
>
> The Client class is a stateless connector that is not appropriate  
> for cookie management. It was designed to be shared by several  
> threads/applications. Even though it is possible to instantiate  
> several of them in the same JVM, it is recommended to share them (of  
> course based on the protocol they support, HTTP(S) in your case).
>
>
>
> I would instead suggest using a CookieFilter in front of the Client  
> to systematically add the cookies (maybe based on the target URI…).  
> I don’t see why this wouldn’t work as you say in your previous  
> email. Note that your “clientHelper” bean doesn’t seem used nor  
> useful.
>
>
>
> Are you sure that you send outgoing requests to the “myFilter”  
> bean and not just to the “client” one? In order for filtering to  
> happen, you need to explicitly call it. It will then forward the cal 
> l to the ‘next’ Restlet attached, the “client” one in your cas 
> e.
>
>
>
> Also, note that we have a RFE to provide a cookie manager filter,  
> able to store cookie settings and to send them again based on target  
> URI and other criteria:
>
> http://restlet.tigris.org/issues/show_bug.cgi?id=42
>
>
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Technical Lead ~ http://www.restlet.org
> Noelios Technologies ~ http://www.noelios.com
>
>
>
>
>
>
>
>
>
>
>
> De : Jean-Philippe Steinmetz [mailto:caskate...@gmail.com]
> Envoyé : mercredi 5 mai 2010 04:38
> À : discuss@restlet.tigris.org
> Objet : Re: Client Custom Header
>
>
>
> Since no one seems to have responded to this problem I was hoping  
> someone could shed some light on cookie setting. Similarly to adding  
> my own header to all outgoing client requests I could instead set a  
> cookie. My one requirement here is that I don't want to modify every  
> outgoing request individually. In other words, the following code  
> won't work...
>
> request.getCookies().add("myCookie", "value");
>
> Instead I need a solution where I set the cookie for the Client  
> instance once and it is respected across all future connections and  
> requests. Is this possible? Or am I really stuck having to add it to  
> every outgoing request? Also please note it is not possible to set  
> the cookie on the server side.
>
> On Mon, May 3, 2010 at 5:24 PM, Jean-Philippe Steinmetz <caskate...@gmail.com 
> > wrote:
>
> Hi Stephan,
>
> Thank you for the response. I've implemented a filter and created  
> one while setting the "next" property to be my client but I am not  
> getting any calls to the beforeHandle function. My code looks like  
> the following.
>
> class MyFilter extends Filter
> {
>     public MyFilter() { this(null);
>     public MyFilter(Context context) { this(context, null); }
>     public MyFilter(Context context, Restlet next) { super(context,  
> next); }
>
>     public int beforeHandle(Request request, Response response)
>     {
>         System.out.println("HIT!");
>         return CONTINUE;
>     }
> }
>
> And my Spring configuration looks like this...
>
> <bean id="client" class="org.restlet.Client">
>     <constructor-arg index="0">
>         <bean class="org.restlet.Context"/>
>     </constructor-arg>
>     <constructor-arg index="1">
>         <util:constant static-field="org.restlet.data.Protocol.HTTP"/>
>     </constructor-arg>
> </bean>
> <bean id="clientHelper"  
> class="com.noelios.restlet.ext.httpclient.HttpClientHelper">
>     <constructor-arg ref="client"/>
> </bean>
> <bean id="myFilter" class="MyFilter">
>     <property name="next" ref="client" />
> </bean>
>
> What am I missing? Thanks again.
>
> Jean-Philippe
>
>
>
> On Sat, May 1, 2010 at 3:49 AM, Stephan Koops <stephan.ko...@web.de>  
> wrote:
>
> Hi Jean,
>
> the access is on both sides the same. That's an advantage of Restlet.
> To add the header for every request you could create a filter. It adds
> the header. Instead of send the request directly by the Client object
> you set the Client as next Restlet in the filter and your application
> sends all request via the filter.
> (I hope that's right ...)
>
> best regards
>   Stephan
>
> Jean-Philippe Steinmetz schrieb:
>
> > Hi,
> >
> > I'm trying to add a custom HTTP header to outgoing requests when  
> using
> > the restlet client API. Ideally i'm looking for some way to  
> implement
> > a helper class that can inject my header into every request as they
> > are processed. However in looking through the documentation i'm not
> > really finding what i'm looking for. I see in the FAQ it's  
> possible to
> > access headers but this seems to be from the server perspective. How
> > do I get access from a client perspective?
> >
> > Thanks in advance,
> >
> > Jean-Philippe Steinmetz
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2600427
>
>
>
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2603507

Reply via email to