hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remis (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (HTTPCLIENT-1435) Proxy authentication of Fluent API does not work
Date Thu, 21 Nov 2013 14:05:35 GMT

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Remis updated HTTPCLIENT-1435:
------------------------------

    Description: 
The sample code below demonstrates the issue.
package com.test;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;

public class Test {
    public static void main(final String[] args) {
        final HttpHost proxy = new HttpHost("my-proxy.com", 8080);
        final String username = "username";
        final String password = "password";
        final String uri = "https://www.my-uri.com/servlet/action";

        // WORKS: HTTP/1.1 200 OK
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(username,
password));
        final HttpPost httppost = new HttpPost(uri);
        httppost.setConfig(RequestConfig.custom().setProxy(proxy).build());
        try {
            System.out.println(HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build()
                    .execute(httppost).getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }

        // WORKS: as expected: HTTP/1.1 407 Proxy Authentication Required
        try {
            System.out.println(Request.Post(uri).viaProxy(proxy).execute().returnResponse().getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }

        // FAILS (not expected): java.net.UnknownHostException:
        try {
            final Executor executor = Executor.newInstance().auth(proxy, username, password).authPreemptive(proxy);
            System.out.println(executor.execute(Request.Post(uri).viaProxy(proxy)).returnResponse().getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}

  was:
The sample code below demonstrates the issue.
{code:title=Test.java}
package com.test;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;

public class Test {
    public static void main(final String[] args) {
        final HttpHost proxy = new HttpHost("my-proxy.com", 8080);
        final String username = "username";
        final String password = "password";
        final String uri = "https://www.my-uri.com/servlet/action";

        // WORKS: HTTP/1.1 200 OK
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(username,
password));
        final HttpPost httppost = new HttpPost(uri);
        httppost.setConfig(RequestConfig.custom().setProxy(proxy).build());
        try {
            System.out.println(HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build()
                    .execute(httppost).getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }

        // WORKS: as expected: HTTP/1.1 407 Proxy Authentication Required
        try {
            System.out.println(Request.Post(uri).viaProxy(proxy).execute().returnResponse().getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }

        // FAILS (not expected): java.net.UnknownHostException:
        try {
            final Executor executor = Executor.newInstance().auth(proxy, username, password).authPreemptive(proxy);
            System.out.println(executor.execute(Request.Post(uri).viaProxy(proxy)).returnResponse().getStatusLine());
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}
{code}


> Proxy authentication of Fluent API does not work
> ------------------------------------------------
>
>                 Key: HTTPCLIENT-1435
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1435
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Fluent HC
>    Affects Versions: 4.3.1
>         Environment: Win7 + JDK6 + HttpClient 4.3.1 + HttpCore 4.3
>            Reporter: Remis
>
> The sample code below demonstrates the issue.
> package com.test;
> import org.apache.http.HttpHost;
> import org.apache.http.auth.AuthScope;
> import org.apache.http.auth.UsernamePasswordCredentials;
> import org.apache.http.client.CredentialsProvider;
> import org.apache.http.client.config.RequestConfig;
> import org.apache.http.client.fluent.Executor;
> import org.apache.http.client.fluent.Request;
> import org.apache.http.client.methods.HttpPost;
> import org.apache.http.impl.client.BasicCredentialsProvider;
> import org.apache.http.impl.client.HttpClientBuilder;
> public class Test {
>     public static void main(final String[] args) {
>         final HttpHost proxy = new HttpHost("my-proxy.com", 8080);
>         final String username = "username";
>         final String password = "password";
>         final String uri = "https://www.my-uri.com/servlet/action";
>         // WORKS: HTTP/1.1 200 OK
>         final CredentialsProvider credsProvider = new BasicCredentialsProvider();
>         credsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(username,
password));
>         final HttpPost httppost = new HttpPost(uri);
>         httppost.setConfig(RequestConfig.custom().setProxy(proxy).build());
>         try {
>             System.out.println(HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build()
>                     .execute(httppost).getStatusLine());
>         } catch (final Exception e) {
>             e.printStackTrace();
>         }
>         // WORKS: as expected: HTTP/1.1 407 Proxy Authentication Required
>         try {
>             System.out.println(Request.Post(uri).viaProxy(proxy).execute().returnResponse().getStatusLine());
>         } catch (final Exception e) {
>             e.printStackTrace();
>         }
>         // FAILS (not expected): java.net.UnknownHostException:
>         try {
>             final Executor executor = Executor.newInstance().auth(proxy, username, password).authPreemptive(proxy);
>             System.out.println(executor.execute(Request.Post(uri).viaProxy(proxy)).returnResponse().getStatusLine());
>         } catch (final Exception e) {
>             e.printStackTrace();
>         }
>     }
> }



--
This message was sent by Atlassian JIRA
(v6.1#6144)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message