hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewan.sla...@googlemail.com
Subject Re: Upgrade from Commons HttpClient to HttpClient 4.1
Date Mon, 07 Feb 2011 10:01:38 GMT
Hi Guys,

Thanks for the suggestions.

It seems that upgrade in this case uses what one of my friends (who works in product management
for a software vendor) describes as a "bumpy upgrade path with limited appeal to the customer"
i.e. no backward compatibility ;-)

I am currently reading through the 4.1 docs as per Oleg's advice, but to save time, does anyone
know where I can download the 3.x client from?

Also, would it be feasible to provide a 3.x compatible wrapper for the 4.1 client to smooth
the upgrade path?

Cheers,

Ewan

Sent from my BlackBerry® wireless device

-----Original Message-----
From: "Elias, Sean" <eliass@newsltd.com.au>
Date: Mon, 7 Feb 2011 12:13:09 
To: HttpClient User Discussion<httpclient-users@hc.apache.org>
Reply-To: "HttpClient User Discussion" <httpclient-users@hc.apache.org>
Subject: RE: Upgrade from Commons HttpClient to HttpClient 4.1

I worked this out using the following example
http://theskeleton.wordpress.com/2010/07/24/avoiding-the-javax-net-ssl-s
slpeerunverifiedexception-peer-not-authenticated-with-httpclient/.

Below is the class for reference. Use as follows:

DefaultHttpClient httpClient =
HttpClientIgnoreInvalidSSLCertificate.createClient();


public class HttpClientIgnoreInvalidSSLCertificate {

    public static DefaultHttpClient createClient() {
        try {
        	DefaultHttpClient base = new DefaultHttpClient();
            SSLContext ctx = SSLContext.getInstance("TLS");
            X509TrustManager tm = new X509TrustManager() {

                public void checkClientTrusted(X509Certificate[] xcs,
String string) throws CertificateException {
                }

                public void checkServerTrusted(X509Certificate[] xcs,
String string) throws CertificateException {
                }

                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            };
            ctx.init(null, new TrustManager[]{tm}, null);
            SSLSocketFactory ssf = new SSLSocketFactory(ctx);
 
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            ClientConnectionManager ccm = base.getConnectionManager();
            SchemeRegistry sr = ccm.getSchemeRegistry();
            sr.register(new Scheme("https", ssf, 443));
            return new DefaultHttpClient(ccm, base.getParams());
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

-----Original Message-----
From: Oleg Kalnichevski [mailto:olegk@apache.org] 
Sent: Sunday, 6 February 2011 11:05 PM
To: HttpClient User Discussion
Subject: Re: Upgrade from Commons HttpClient to HttpClient 4.1

On Fri, 2011-02-04 at 11:30 +0000, Ewan Slater wrote:
> Hi,
> 
> I have downloaded (and wish to run) a piece of example code for
> accessing an application that was written for Commons HttpClient.
> 
> I have downloaded HttpClient 4.1 as this is recommended and I would
> like to upgrade the example code to use HttpClient 4.1.
> 
> I have searched for upgrade / translate commons httpclient to
> httpclient and variants thereof, but I can't find a guide to how to do
> this.
> 
> It doesn't seem as simple as just changing
> org.apache.commons.httpclient.Credentials to
> org.apache.http.client.Credentials for example ('cos it doesn't
> exist).
> 
> I'm guessing that org.apache.http.auth.Credentials is *probably* what
> I'm after, but some kind of guide would be really useful.
> 
> If anyone could point me to one that would be great.
> 

Ewan,

The 3.1 and 4.1 APIs are so different that it is not possible to
mechanically port to the new API just by replacing old classes and
interfaces with new ones.

I strongly recommend investing 30 minutes of your time into reading the
HttpClient tutorial and refactoring your code to take full advantage of
HttpClient 4.1 capabilities.

http://hc.apache.org/httpcomponents-core-ga/tutorial/html/  

Oleg


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



***********************************************************************************************
This message and its attachments may contain legally privileged or confidential information.
It is intended solely for the named addressee. If you are not the addressee indicated in this
message or responsible for delivery of the message to the addressee, you may not copy or deliver
this message or its attachments to anyone. Rather, you should permanently delete this message
and its attachments and kindly notify the sender by reply e-mail. Any content of this message
and its attachments which does not relate to the official business of the sending company
must
be taken not to have been sent or endorsed by that company or any of its related entities.
No
warranty is made that the e-mail or attachments are free from computer virus or other defect.
***********************************************************************************************

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

Mime
View raw message