Hi Lars,

The call converters give you access to all the raw HTTP headers. If you need
the value of some of them (probably in the case of non-standard HTTP
headers?) in your Restlets, then you need to *push* them to the uniform Call
instance. This is what the sample converter code demonstrates. Either you
pass the value as a Call's attribute, either you create a subclass of Call
inside the converter (by overriding the toUniform() method) and using a Java
property.

Your current approach is *pulling* headers from the call, which I want to
discourage because it needs some protocol/connector specific handling within
the uniform Call and Restlets. Remember that one core requirement for Call
and Restlet classes is to be as protocol independent as possible (HTTP,
SMTP, FILE, JDBC for now, FTP, POP3, etc. in the future), so everything that
is protocol specific should be done in the scope of the Connectors (which
are, by nature, protocol-aware). Of course, HTTP being the natural father of
REST, we should provide 100% of the information contained in standard HTTP
headers as higher-level Java properties associated to a Call instance (like
we transform the Accept* headers into
org.restlet.data.ClientData.getAccepted*() methods.

I already know about the X-Forwarded-For header scenario explained by John
D. Mitchell, but I would be very interested to know more about your own
scenarios, requiring you to manipulate raw HTTP headers. Anyway, call
converters should cover your needs, indeed with some refactoring on your
side. Let me know if I missed something.

Cheers,
Jerome  

> -----Message d'origine-----
> De : Lars Heuer [mailto:[EMAIL PROTECTED] 
> Envoyé : jeudi 14 septembre 2006 15:03
> À : [email protected]
> Objet : b19 - Call converters
> 
> Hi Jerome & Co., 
> 
> Here an excerpt of a class I use nearly for all projects 
> where Restlet 
> is involved: 
> 
> public class Headers { 
>     /** 
>      * Constructor that wraps a [EMAIL PROTECTED] 
> org.restlet.data.ParameterList}. 
>      * 
>      * @param paramList The parameter list instance to wrap. 
>      */ 
>     private Headers(ParameterList paramList) { 
>         _paramList = paramList; 
>     } 
> 
>     /** 
>      * Returns a header instance that is bound to the request 
> headers. 
>      * 
>      * @param call The [EMAIL PROTECTED] org.restlet.Call} instance to 
> retrieve the 
>      *              request headers from. 
>      * @return A headers instance that is initialized with 
> the request headers. 
>      */ 
>     public static Headers fromRequest(Call call) { 
>         //FIXME: Does not work with WrapperCall cf. 
> http://restlet.tigris.org/issues/show_bug.cgi?id=158 
>         return new Headers(((HttpServerRestletCall) 
> call).getConnectorCall().getRequestHeaders()); 
>     } 
> 
>     [...] 
> } 
> 
> 
> I looked into the example and source code of the new call converters 
> but they don't help me here, right? 
> 
> In an arbitrary Restlet I use it like: 
> 
>    Headers headers = Headers.fromRequest(call); 
>    if (headers.get("X-bla-bla") == null) { 
>       // do something 
>    } 
>    else { 
>       // do something 
>       headers.add("X-blub-blub", "FooBar"); 
>    } 
> 
> I just want the headers, nothing more, nothing less. :) 
> 
> Best regards, 
> Lars 
> -- 
> http://www.semagia.com 
> 
> 

Reply via email to