users@jersey.java.net

[Jersey] Re: Client and custom socket factory

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Sun, 20 Feb 2011 09:19:52 -0500

Got it, thanks.

I did file a JIRA enhancement request on this. I fumbled for words,
though - I don't really know the right way to solve this.

My "ideal" solution would be everything gets done via guice :-) but
that doesn't help non-guice users, does it.

--Chris



        DefaultApacheHttpClientConfig cc = new DefaultApacheHttpClientConfig();
        cc.getState().setCredentials(null, null, -1, login, password);

        HostConfiguration hostConfig = new HostConfiguration();
    // set local source address here

        HttpClient apacheClient = new HttpClient();
        apacheClient.setHostConfiguration(hostConfig);


        ApacheHttpClientHandler handler = new
ApacheHttpClientHandler(apacheClient, cc);
        ApacheHttpClient jerseyClient = new ApacheHttpClient(handler);
        jerseyClient.addFilter(new GZIPContentEncodingFilter(true));

On Sun, Feb 20, 2011 at 3:50 AM, Petr Jurák <petr.jurak_at_gmail.com> wrote:
> Hi,
> look at ApacheHttpClient and ApacheHttpClientHandler. You can create
> Apache client, pass it to handler and use that handler in
> com.sun.jersey.client.apache.ApacheHttpClient.
> But I think, there is no way to achieve this behavior with
> com.sun.jersey.api.client.Client. I think you can create on Jira new
> improvement task for this.
> Regards,
> Petr
>
> 2011/2/20 Christopher Piggott <cpiggott_at_gmail.com>:
>> Hi,
>>
>> On Fri, Feb 11, 2011 at 9:59 AM, Petr Jurák <petr.jurak_at_gmail.com> wrote:
>>> Ok, I see what you want.
>>> So try jersey with apache client:
>>>
>>> HostConfiguration hostConfiguration = new HostConfiguration();
>>> byte b[] = new byte[4];
>>> b[0] = new Integer(192).byteValue();
>>> b[1] = new Integer(168).byteValue();
>>> b[2] = new Integer(1).byteValue();
>>> b[3] = new Integer(11).byteValue();
>>>
>>> hostConfiguration.setLocalAddress(InetAddress.getByAddress(b));
>>> HttpClient client = new HttpClient();
>>> client.setHostConfiguration(hostConfiguration);
>>>
>>> Something like that. I hope this help.
>>>
>>> Regards,
>>> Petr
>>
>> That gets me an HttpClient object, but how do I get from there to a
>> jersey client (com.sun.jersey.api.client.Client) ?
>>
>