From: Ron S. <rs...@re...> - 2015-03-15 04:36:05
|
Hi Veit, One option is to install a ClientRequestFilter, which can access request headers before a request is sent. For example,, static class TestRequestFilter implements ClientRequestFilter { String value; public void setValue(String value) { this.value = value; } @Override public void filter(ClientRequestContext requestContext) throws IOException { MultivaluedMap<String, Object> mmap = requestContext.getHeaders(); List<Object> list = new ArrayList<Object>(); list.add(value); mmap.put("TestHeader", list); } } which could be used as follows: ResteasyClient client = new ResteasyClientBuilder().build(); TestRequestFilter filter = new TestRequestFilter(); client.register(filter); ResteasyWebTarget target = client.target("http://localhost:8081/post"); TestResource tr = target.proxy(TestResource.class); filter.setValue("abc"); Assert.assertEquals("abc", tr.post("hello 1")); // Resource returns value of header filter.setValue("xyz"); Assert.assertEquals("xyz", tr.post("hello 1")); I've attached an example program, TestProxy.java. -Ron > Hi. > > How can I set http headers when invoking methods on the client side proxy? > I'm aware that I can e.g. set credentials on the underlying HttpClient. > I do that once > before creating the proxy. But when using the proxy, I have to change > some http headers > on every request as well. So, what's the best practive for that? > > Thanks for your help! > Veit |