users@jersey.java.net

[Jersey] Re: Best practice of setting User-Agent on Jersey Client

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Tue, 31 Jan 2012 11:54:14 +0100

Hello,

this solution is fine, we don't have any explicit property which would
set this header, so using client filter is good way how to do it.

Regards,
Pavel

On 1/30/12 5:26 PM, mail_at_akirakoyasu.net wrote:
> Hi there,
>
> I'm using jersey-core-1.11 and jersey-client-1.11.
>
> I'd like to set HTTP header "User-Agent" on Jersey Client class.
> Not WebResource class..., because I'll make many WebResources /
> requests.
>
> My code is:
>
> Client client = Client.create();
> client.addFilter(new ClientFilter() {
> @Override
> public ClientResponse handle(ClientRequest
> request)
> throws ClientHandlerException {
> request.getHeaders().add(
> HttpHeaders.USER_AGENT,
> "<< user-agent>>");
> return getNext().handle(request);
> }
> });
>
> How do you think?
> Would you please tell me your best practices.
>
> Thank you.
>