Changeset 6477


Ignore:
Timestamp:
Jun 12, 2014, 11:49:30 AM (9 years ago)
Author:
Nicklas Nordborg
Message:

References #1809: Upgrade 3-rd party libraries

Updated HttpClient? to 4.3.4. Since we expose some methods and classes that has been deprecated (mainly in SSLUtil) we were forced to deprecate some of our own API. New replacement methods have been implemented. The deprecated methods and classes will be removed in BASE 3.5.

Location:
trunk
Files:
4 added
3 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/.classpath

    r6476 r6477  
    2020  <classpathentry kind="lib" path="lib/dist/commons-io-1.4.jar"/>
    2121  <classpathentry kind="lib" path="lib/dist/commons-email-1.3.jar"/>
    22   <classpathentry kind="lib" path="lib/dist/httpclient-4.2.3.jar"/>
    23   <classpathentry kind="lib" path="lib/dist/httpcore-4.2.3.jar"/>
    2422  <classpathentry kind="lib" path="lib/dist/json-simple-1.1.1.jar"/>
    2523  <classpathentry kind="lib" path="lib/svn/svnant-1.4dev.jar"/>
     
    3331  <classpathentry kind="lib" path="lib/dist/jcommon-1.0.21.jar"/>
    3432  <classpathentry kind="lib" path="lib/dist/jfreechart-1.0.17.jar"/>
     33  <classpathentry kind="lib" path="lib/dist/httpclient-4.3.4.jar"/>
     34  <classpathentry kind="lib" path="lib/dist/httpcore-4.3.2.jar"/>
    3535  <classpathentry kind="output" path="xbin"/>
    3636</classpath>
  • trunk/doc/3rd-party-components.txt

    r6476 r6477  
    183183
    184184More info : http://hc.apache.org/
    185 Version   : 4.2.3
    186 License   : Apache License 2.0 (apache.license-2.0.txt)
    187 Jar files : httpclient-4.2.3.jar, httpcore-4.2.3.jar, commons-codec-1.6.jar,
    188             commons-logging-1.1.1.jar
     185Version   : 4.3.4
     186License   : Apache License 2.0 (apache.license-2.0.txt)
     187Jar files : httpclient-4.3.4.jar, httpcore-4.3.2.jar, commons-codec-1.6.jar,
     188            commons-logging-1.1.3.jar
    189189
    190190Apache Commons Email
  • trunk/src/core/net/sf/basedb/core/FileServer.java

    r6127 r6477  
    2828import java.util.Set;
    2929
    30 import org.apache.http.conn.ssl.SSLSocketFactory;
     30import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
    3131
    3232import net.sf.basedb.core.data.FileServerData;
    3333import net.sf.basedb.core.query.Hql;
    3434import net.sf.basedb.core.query.Restrictions;
    35 import net.sf.basedb.util.ssl.SSLUtil;
     35import net.sf.basedb.util.ssl.SSLUtil2;
    3636
    3737/**
     
    374374    try
    375375    {
    376       return (X509Certificate)SSLUtil.getCertificate(new ByteArrayInputStream(cert), "X.509", null);
     376      return (X509Certificate)SSLUtil2.getCertificate(new ByteArrayInputStream(cert), "X.509", null);
    377377    }
    378378    catch (Exception ex)
     
    439439    try
    440440    {
    441       KeyStore ks = SSLUtil.createKeyStore(new ByteArrayInputStream(key), getClientCertificatePassword(), "PKCS12", null);
     441      KeyStore ks = SSLUtil2.createKeyStore(new ByteArrayInputStream(key), getClientCertificatePassword(), "PKCS12", null);
    442442      return (X509Certificate)ks.getCertificate(ks.aliases().nextElement());
    443443    }
     
    485485    Otherwise, the default (as configured in base.config) certificates are used.
    486486    @return A SSL socket factory
    487   */
    488   public SSLSocketFactory getSSLSocketFactory()
    489   {
    490     return SSLUtil.getSSLSocketFactory(getServerCertificate(), getClientCertificate(), getClientCertificatePassword());
     487    @deprecated In 3.4, use {@link #getSSLSocketFactory2()} instead
     488  */
     489  @Deprecated
     490  public org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory()
     491  {
     492    return net.sf.basedb.util.ssl.SSLUtil.getSSLSocketFactory(getServerCertificate(), getClientCertificate(), getClientCertificatePassword());
     493  }
     494 
     495  /**
     496    Get a socket factory that can be used to create SSL connections to the given
     497    server. If a server and/or client certificate has been specified for this
     498    file server the socket factory will be created with those certificates.
     499    Otherwise, the default (as configured in base.config) certificates are used.
     500    @return A SSL socket factory
     501  */
     502  public SSLConnectionSocketFactory getSSLSocketFactory2()
     503  {
     504    return SSLUtil2.getSSLSocketFactory(getServerCertificate(), getClientCertificate(), getClientCertificatePassword());
    491505  }
    492506 
  • trunk/src/core/net/sf/basedb/util/HttpUtil.java

    r5360 r6477  
    2222package net.sf.basedb.util;
    2323
     24import java.io.IOException;
    2425import java.text.SimpleDateFormat;
    2526import java.util.Date;
    2627import java.util.Locale;
    2728
     29
     30
    2831import org.apache.http.Header;
    2932import org.apache.http.HttpResponse;
    3033import org.apache.http.client.HttpClient;
     34import org.apache.http.impl.client.CloseableHttpClient;
    3135
    3236/**
     
    115119    without trowing an exception. Useful to use in try-catch-finally
    116120    clauses.
     121    @deprecated In 3.4, use {@link #shutdown(CloseableHttpClient)} instead
    117122  */
     123  @Deprecated
    118124  public static void shutdown(HttpClient client)
    119125  {
     
    125131    {}
    126132  }
     133
     134  /**
     135    Safely shuts down a http client and it's connection manager
     136    without trowing an exception. Useful to use in try-catch-finally
     137    clauses.
     138  */
     139  public static void shutdown(CloseableHttpClient client)
     140  {
     141    try
     142    {
     143      client.close();
     144    }
     145    catch (IOException ex)
     146    {}
     147    catch (RuntimeException ex)
     148    {}
     149  }
    127150 
    128151}
  • trunk/src/core/net/sf/basedb/util/ssl/SSLUtil.java

    r5870 r6477  
    4343import javax.net.ssl.TrustManagerFactory;
    4444
    45 import org.apache.http.conn.ssl.SSLSocketFactory;
    46 
    4745import net.sf.basedb.core.BaseException;
    4846import net.sf.basedb.core.Config;
     
    5452  @since 2.16
    5553  @base.modified $Date$
     54  @deprecated In 3.4, use {@link SSLUtil2} instead
    5655*/
     56@Deprecated
    5757public class SSLUtil
    5858{
     
    6060  private static KeyManager[] defaultKeyManagers;
    6161  private static TrustManager[] defaultTrustManagers;
    62   private static SSLSocketFactory defaultSocketFactory;
     62  private static org.apache.http.conn.ssl.SSLSocketFactory defaultSocketFactory;
    6363
    6464  /**
     
    115115    @return A SSL socket factory
    116116  */
    117   public static SSLSocketFactory getSSLSocketFactory()
     117  public static org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory()
    118118  {
    119119    if (defaultSocketFactory == null)
     
    133133              SSLContext.getInstance(sslProtocol, sslProvider);
    134134          context.init(keyManagers, trustManagers, null);
    135           defaultSocketFactory = new SSLSocketFactory(context);
     135          defaultSocketFactory = new org.apache.http.conn.ssl.SSLSocketFactory(context);
    136136        }
    137137        else
    138138        {
    139           defaultSocketFactory = new SSLSocketFactory(SSLContext.getDefault());
     139          defaultSocketFactory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault());
    140140        }
    141141      }
     
    164164    @return A socket factory
    165165  */
    166   public static SSLSocketFactory getSSLSocketFactory(byte[] serverCertificate,
     166  public static org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory(byte[] serverCertificate,
    167167      byte[] clientCertificate, String clientCertificatePassword)
    168168  {
     
    174174    String sslProtocol = Config.getString("ssl.context.protocol", "TLS");
    175175    String sslProvider = Config.getString("ssl.context.provider");
    176     SSLSocketFactory factory = null;
     176    org.apache.http.conn.ssl.SSLSocketFactory factory = null;
    177177    try
    178178    {
     
    214214            SSLContext.getInstance(sslProtocol, sslProvider);
    215215        context.init(keyManagers, trustManagers, null);
    216         factory = new SSLSocketFactory(context, new AllowAnyHostNameVerifyer());
    217       }
    218       else
    219       {
    220         factory = new SSLSocketFactory(SSLContext.getDefault());
     216        factory = new org.apache.http.conn.ssl.SSLSocketFactory(context, new AllowAnyHostNameVerifyer());
     217      }
     218      else
     219      {
     220        factory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault());
    221221      }
    222222    }
  • trunk/src/core/net/sf/basedb/util/uri/http/HttpConnectionManager.java

    r5870 r6477  
    2222package net.sf.basedb.util.uri.http;
    2323
    24 import java.io.Closeable;
    2524import java.io.IOException;
    2625import java.io.InputStream;
     
    3433import org.apache.http.auth.Credentials;
    3534import org.apache.http.auth.UsernamePasswordCredentials;
     35import org.apache.http.client.CredentialsProvider;
    3636import org.apache.http.client.HttpClient;
     37import org.apache.http.impl.client.CloseableHttpClient;
    3738import org.apache.http.client.methods.HttpGet;
    3839import org.apache.http.client.methods.HttpHead;
    39 import org.apache.http.conn.scheme.Scheme;
    40 import org.apache.http.conn.ssl.SSLSocketFactory;
    41 import org.apache.http.impl.client.DefaultHttpClient;
     40import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
     41import org.apache.http.impl.client.BasicCredentialsProvider;
     42import org.apache.http.impl.client.HttpClientBuilder;
     43import org.apache.http.impl.conn.DefaultSchemePortResolver;
    4244
    4345import net.sf.basedb.core.InvalidDataException;
    4446import net.sf.basedb.util.HttpUtil;
    45 import net.sf.basedb.util.ssl.SSLUtil;
     47import net.sf.basedb.util.ssl.SSLUtil2;
    4648import net.sf.basedb.util.uri.CloseResourceInputStream;
    4749import net.sf.basedb.util.uri.ConnectionParameters;
     
    8991  {
    9092    URI uri = getURI();
    91     HttpClient client = null;
     93    CloseableHttpClient client = null;
    9294    InputStream stream = null;
    9395    try
    9496    {
    9597      HttpGet get = new HttpGet(uri);
    96       client = createHttpClient(uri, parameters);
     98      client = createCloseableHttpClient(uri, parameters);
    9799      HttpResponse response = client.execute(get);
    98100      if (metadata == null) metadata = createMetadata(uri, response);
     
    101103      {
    102104        // Wrap the stream so that stream.close() will also shutdown the client
    103         stream = new CloseResourceInputStream(entity.getContent(), new CloseableHttpClient(client));
     105        stream = new CloseResourceInputStream(entity.getContent(), client);
    104106      }
    105107    }
     
    119121    {
    120122      URI uri = getURI();
    121       HttpClient client = null;
     123      CloseableHttpClient client = null;
    122124      try
    123125      {
    124126        HttpHead head = new HttpHead(uri);
    125         client = createHttpClient(uri, parameters);
     127        client = createCloseableHttpClient(uri, parameters);
    126128        HttpResponse response = client.execute(head);
    127129
     
    152154  }
    153155  // --------------------------------------
     156 
     157  /**
     158    @deprecated In 3.4, use {@link #createCloseableHttpClient(URI, ConnectionParameters)} instead
     159  */
     160  @Deprecated
     161  public HttpClient createHttpClient(URI uri, ConnectionParameters parameters)
     162    throws IOException
     163  {
     164    return createCloseableHttpClient(uri, parameters);
     165  }
    154166 
    155167  /**
     
    157169    given URI.
    158170  */
    159   public HttpClient createHttpClient(URI uri, ConnectionParameters parameters)
    160     throws IOException
    161   {
    162     DefaultHttpClient httpClient = new DefaultHttpClient();
     171  public CloseableHttpClient createCloseableHttpClient(URI uri, ConnectionParameters parameters)
     172    throws IOException
     173  {
     174    HttpClientBuilder builder = HttpClientBuilder.create();
     175    //HttpClient httpClient = builder.build();
     176    //DefaultHttpClient httpClient = new DefaultHttpClient();
    163177 
    164178    // Do we need to provide username/password?
     
    166180    {
    167181      Credentials credentials = new UsernamePasswordCredentials(parameters.getUsername(), parameters.getPassword());
    168       httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
     182      CredentialsProvider provider = new BasicCredentialsProvider();
     183      provider.setCredentials(AuthScope.ANY, credentials);
     184      builder.setDefaultCredentialsProvider(provider);
     185//      httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
    169186    }
    170187 
     
    172189    {
    173190      // Adds support for https urls
    174       SSLSocketFactory sslFactory = null;
     191      SSLConnectionSocketFactory sslFactory = null;
    175192      if (parameters == null)
    176193      {
    177         sslFactory = SSLUtil.getSSLSocketFactory();
     194        sslFactory = SSLUtil2.getSSLSocketFactory();
    178195      }
    179196      else
    180197      {
    181         sslFactory = SSLUtil.getSSLSocketFactory(parameters.getServerCertificate(),
     198        sslFactory = SSLUtil2.getSSLSocketFactory(parameters.getServerCertificate(),
    182199            parameters.getClientCertificate(), parameters.getClientCertificatePassword());
    183200      }
    184       Scheme https = new Scheme("https", 443, sslFactory);
    185       httpClient.getConnectionManager().getSchemeRegistry().register(https);
    186     }
    187      return httpClient;
     201      //Scheme https = new Scheme("https", 443, sslFactory);
     202      builder.setSchemePortResolver(DefaultSchemePortResolver.INSTANCE);
     203      builder.setSSLSocketFactory(sslFactory);
     204      //httpClient.getConnectionManager().getSchemeRegistry().register(https);
     205    }
     206    return builder.build();
    188207  }
    189208 
     
    219238    return meta;
    220239  }
    221  
    222   /**
    223     Closable implementation that closes the given HttpClient
    224     when the close() method is called.
    225   */
    226   public static class CloseableHttpClient
    227     implements Closeable
    228   {
    229 
    230     private final HttpClient client;
    231     public CloseableHttpClient(HttpClient client)
    232     {
    233       this.client = client;
    234     }
    235    
    236     @Override
    237     public void close()
    238       throws IOException
    239     {
    240       HttpUtil.shutdown(client);
    241     }
    242   }
     240
    243241 
    244242}
Note: See TracChangeset for help on using the changeset viewer.