users@jersey.java.net

[Jersey] Re: Optional Headers with Jersey 2.0 Proxy

From: Guillaume Polet <guillaume.polet_at_bluepimento.eu>
Date: Sun, 26 Apr 2015 12:25:32 +0200

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