Marc Portier <mpo <at> outerthought.org> writes:
Marc,
> Sean,
> it looks like you are mixing up headers with attributes.
Indeed.
> * Headers is what is passing over the wire in the 'header' of HTTP messages.
>
> * Attributes is what can be attached to the in memory request objects
> these stay inside the VM. (not passed over the wire)
>
> The confusion is easily made by the fact that the restlet API is holding
> all the header-lines in a Series<Paramater> object that is hooked up as
> a single attribute with name "org.restlet.http.headers".
That is very confusing.
> I'm assuming the design opts to do things like this since the
> request-response model is not limited to merely the HTTP protocol.
I am pretty sure you are right.
> Now, assuming you want to pass data in a custom header from the client
> to the server, you can use this on the client:
>
> > Request request = new Request();
> > request.setResourceRef("http://127.0.0.1:8182/header/");
> > Series<Parameter> headers = new Form();
> > headers.add("X-mpo", "my own header added");
> > request.getAttributes().put("org.restlet.http.headers", headers);
>
> on the server you can just dump and return the headers with:
> > StringBuffer sb = new StringBuffer();
> > Series<Parameter> headers = (Series)
request.getAttributes().get("org.restlet.http.headers");
> > for (Parameter h : headers)
> > {
> > sb.append("header name = ");
> > sb.append(h.getName());
> > sb.append("\n value = ");
> > sb.append(h.getValue());
> > sb.append("\n");
> > System.out.println(sb.toString());
> > }
> > response.setEntity(sb.toString(), MediaType.TEXT_PLAIN);
Thanks this is what I'm looking for.
> Note that passing those values as request-parameters is a more common
> way of doing things. (headers are a more hidden way of passing stuff,
> and will typically require custom clients to be able to set them and
> pass them over.
The nature of the data is
a clientId and a callId. These are going to be used for governance and
should be part of every call in our environment. It seemed to me that
since it was not application related, that it ought to be hidden. I'd love
to hear about alternatives though.
> Further samples for this are to be found in the examples:
> see in the package org.restlet.example.misc for the classes HeaderTest,
> SimpleClient and SimpleServer.
>
> HTH,
> -marc=
It sure does. Thanks,
Sean