users@jersey.java.net

Re: [Jersey] How do you configure proxy in Jersey client

From: Srinivas Naresh Bhimisetty <shri.naresh_at_gmail.com>
Date: Thu, 2 Sep 2010 16:15:12 +0530

Not sure if this helps, but did you try something like this?

               ....
               DefaultApacheHttpClientConfig cc = new
DefaultApacheHttpClientConfig();

cc.getProperties().put(DefaultApacheHttpClientConfig.PROPERTY_PROXY_URI,"http://
proxy.ergogroup.no:3128/");
              ApacheHttpClient c = ApacheHttpClient.create(cc);
              WebResource webResource = c.resource("
http://www.balder.no/images/sn_banner_180x100px.gif");
              ...

i.e., using the ApacheHttpClient instead of Client and adding the "http://"
in the PROPERTY_PROXY_URI property.

- Naresh

On Thu, Sep 2, 2010 at 2:45 PM, Sverre Kristoffer Furseth <
sverre.kristoffer.furseth_at_gmail.com> wrote:

> Do not find any good information on google , hence this mail ....
>
> Refering to test attached underneath :
> - http client apache works : SUCCESS
> - jersey client do not work : FAIL
>
> I have tried setting proxy in the Java Console and as properties with
> -D option as
> "-Dhttp.proxyHost=proxy.ergogroup.no -Dhttp.proxyPort=3128"
>
> without any luck
>
> Versions in use :
> <jersey-client.version>1.1.5</jersey-client.version>
> <commons-net.version>2.0</commons-net.version>
>
> TEST :
> ---8<--------
> package no.my.client.proxy;
>
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.UsernamePasswordCredentials;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.junit.Test;
>
> import com.sun.jersey.api.client.Client;
> import com.sun.jersey.api.client.ClientResponse;
> import com.sun.jersey.api.client.WebResource;
> import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
>
> public class SimpleProxyTest {
>
> @Test
> public void testSimple() throws Exception {
> System.out.println("test");
>
>
> HttpClient httpclient = new HttpClient();
> httpclient.getHostConfiguration().setProxy("
> proxy.ergogroup.no", 3128);
> GetMethod httpget = new GetMethod("
> https://www.verisign.com/");
> try {
> httpclient.executeMethod(httpget);
> System.out.println(httpget.getStatusLine());
> } finally {
> httpget.releaseConnection();
> }
> }
>
> @Test
> public void testSimpleJerseyClient() throws Exception {
> System.out.println("test");
> DefaultApacheHttpClientConfig cc = new
> DefaultApacheHttpClientConfig();
>
> cc.getProperties().put(DefaultApacheHttpClientConfig.PROPERTY_PROXY_URI,"
> proxy.ergogroup.no:3128");
> Client c = Client.create(cc);
> WebResource webResource =
> c.resource("http://www.balder.no/images/sn_banner_180x100px.gif");
> ClientResponse response =
> webResource.get(ClientResponse.class);
> System.out.println(response.getHeaders());
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>