users@jersey.java.net

[Jersey] Re: Optional Headers with Jersey 2.0 Proxy

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Mon, 27 Apr 2015 16:45:42 +0200

Or, you can also use @javax.ws.rs.DefaultValue to inject default value for a header, if it is not present.

Marek

> On 26 Apr 2015, at 12:25, Guillaume Polet <guillaume.polet_at_bluepimento.eu> wrote:
>
> You can access the complete list of HttpHeaders with the use of @Context
>
> public Response updateMetadatas(@PathParam("account") String accountName, @HeaderParam("X-Auth-Token") String Token, @Context HttpHeaders hh)
>
> Guillaume
>
> Le 26/04/2015 3:00, Gordon Lawrenz a écrit :
>> Hello,
>>
>> For a project I need to add optional Headers with previously not specified names to requests sent by WebResources. For better understanding here is an example:
>>
>> I made an interface for to access the openstack-swift-api.
>> It looks like this:
>>
>> @Path("/")
>> public interface SwiftApiProxy {
>> ...
>> @POST
>> @Path("/v1/​{account}​")
>> public Response updateMetadatas(@PathParam("account") String accountName, @HeaderParam("X-Auth-Token") String Token);
>> ...
>> }
>>
>> I'm creating instances of this resource with the help of an AbstractBinder and WebResourceFactory:
>>
>> public class CustomBinder extends AbstractBinder {
>> @Override
>> protected void configure() {
>> bind(WebResourceFactory.newResource(SwiftApiProxy.class, ClientBuilder.newClient().target("http://localhost:8080" <http://localhost:8080/>).register(CustomBodyHandler.class))).to(SwiftApiProxy.class);
>> }
>> }
>>
>> They get injected with @Inject where I need them. My problem is that I don't know how to handle optional headers. That means I optionally need to add headers like "X-Account-Meta-name" to the GET request. where {name} is not known beforehand. Is there a way (which I didn't found) to add those headers easily?
>>
>> Here is also a link to the documentation of the API i want to use: http://developer.openstack.org/api-ref-objectstorage-v1.html <http://developer.openstack.org/api-ref-objectstorage-v1.html>
>>
>> Kind Regards,
>> Gordon Lawrenz
>