Bug in httpClientHelper when proxy is used

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in httpClientHelper when proxy is used

Jean-Christophe Malapert-3
Hello,

I use the restlet version 2.3.10 and org.restlet.ext.httpclient extension.

Each request passes through a proxy. 
                Engine.getInstance().getRegisteredClients().clear();
                Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
                this.client = new ClientResource(uri);
Client proxy = new Client(new Context(), Arrays.asList(Protocol.HTTP, Protocol.HTTPS));
proxy.getContext().getParameters().add("proxyHost", host);
proxy.getContext().getParameters().add("proxyPort", port);               
this.client.setProxyChallengeResponse(ChallengeScheme.HTTP_BASIC, login, pwd);
this.client.setNext(proxy);

Restlet works perfectly when I want to query an URL using HTTP protocol but there is a problem when I want to query an URL using HTTPS protocol. I seems that the credentials are not send to the proxy when the target uses the HTTPS protocol.

If I write a simple code with the last version of httpclient, I can pass my proxy :
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_HOST), Integer.valueOf(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_PORT))),
                new UsernamePasswordCredentials(DoiSettings.getInstance().getSecret(Consts.SERVER_PROXY_LOGIN), DoiSettings.getInstance().getSecret(Consts.SERVER_PROXY_PWD))
        );
        CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
        
        
        int status = 0;
        try {
            //HttpHost target = new HttpHost("www.google.fr", 443, "https");
            HttpHost proxy = new HttpHost(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_HOST), Integer.valueOf(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_PORT)), "http");            
           
            RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
            HttpGet request = new HttpGet("https://www.google.fr");
            request.setConfig(config);                        
            
            System.out.println("Executing request " + request.getRequestLine()+" to "+ request.getURI() +" via "+proxy);
            CloseableHttpResponse response = httpclient.execute(request);
            status = response.getStatusLine().getStatusCode();
            try {
                System.out.println("--------");
                System.out.println(response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
            } finally {
                response.close();
            }
            
        } finally {
            httpclient.close();
        }


Any idea to solve my problem ?

Thanks,
Jean-Christophe

--
You received this message because you are subscribed to the Google Groups "Restlet Framework (Discuss)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Bug in httpClientHelper when proxy is used

Thierry Boileau-4
Hello Jean-Christophe,

I've added this ticket for handling your issue: https://github.com/restlet/restlet-framework-java/issues/1274

best regards
Thierry Boileau

Le lun. 28 août 2017 à 15:13, Jean-Christophe Malapert <[hidden email]> a écrit :
Hello,

I use the restlet version 2.3.10 and org.restlet.ext.httpclient extension.

Each request passes through a proxy. 
                Engine.getInstance().getRegisteredClients().clear();
                Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
                this.client = new ClientResource(uri);
Client proxy = new Client(new Context(), Arrays.asList(Protocol.HTTP, Protocol.HTTPS));
proxy.getContext().getParameters().add("proxyHost", host);
proxy.getContext().getParameters().add("proxyPort", port);               
this.client.setProxyChallengeResponse(ChallengeScheme.HTTP_BASIC, login, pwd);
this.client.setNext(proxy);

Restlet works perfectly when I want to query an URL using HTTP protocol but there is a problem when I want to query an URL using HTTPS protocol. I seems that the credentials are not send to the proxy when the target uses the HTTPS protocol.

If I write a simple code with the last version of httpclient, I can pass my proxy :
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_HOST), Integer.valueOf(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_PORT))),
                new UsernamePasswordCredentials(DoiSettings.getInstance().getSecret(Consts.SERVER_PROXY_LOGIN), DoiSettings.getInstance().getSecret(Consts.SERVER_PROXY_PWD))
        );
        CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
        
        
        int status = 0;
        try {
            //HttpHost target = new HttpHost("www.google.fr", 443, "https");
            HttpHost proxy = new HttpHost(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_HOST), Integer.valueOf(DoiSettings.getInstance().getString(Consts.SERVER_PROXY_PORT)), "http");            
           
            RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
            HttpGet request = new HttpGet("https://www.google.fr");
            request.setConfig(config);                        
            
            System.out.println("Executing request " + request.getRequestLine()+" to "+ request.getURI() +" via "+proxy);
            CloseableHttpResponse response = httpclient.execute(request);
            status = response.getStatusLine().getStatusCode();
            try {
                System.out.println("--------");
                System.out.println(response.getStatusLine());
                System.out.println(EntityUtils.toString(response.getEntity()));
            } finally {
                response.close();
            }
            
        } finally {
            httpclient.close();
        }


Any idea to solve my problem ?

Thanks,
Jean-Christophe

--
You received this message because you are subscribed to the Google Groups "Restlet Framework (Discuss)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].