users@jersey.java.net

[Jersey] Optional Headers with Jersey 2.0 Proxy

From: Gordon Lawrenz <gordon.lawrenz_at_rwth-aachen.de>
Date: Sun, 26 Apr 2015 03:00:26 +0200

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").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

Kind Regards,
     Gordon Lawrenz