Changeset 6477
- Timestamp:
- Jun 12, 2014, 11:49:30 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 3 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.classpath
r6476 r6477 20 20 <classpathentry kind="lib" path="lib/dist/commons-io-1.4.jar"/> 21 21 <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"/>24 22 <classpathentry kind="lib" path="lib/dist/json-simple-1.1.1.jar"/> 25 23 <classpathentry kind="lib" path="lib/svn/svnant-1.4dev.jar"/> … … 33 31 <classpathentry kind="lib" path="lib/dist/jcommon-1.0.21.jar"/> 34 32 <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"/> 35 35 <classpathentry kind="output" path="xbin"/> 36 36 </classpath> -
trunk/doc/3rd-party-components.txt
r6476 r6477 183 183 184 184 More info : http://hc.apache.org/ 185 Version : 4. 2.3186 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.jar185 Version : 4.3.4 186 License : Apache License 2.0 (apache.license-2.0.txt) 187 Jar files : httpclient-4.3.4.jar, httpcore-4.3.2.jar, commons-codec-1.6.jar, 188 commons-logging-1.1.3.jar 189 189 190 190 Apache Commons Email -
trunk/src/core/net/sf/basedb/core/FileServer.java
r6127 r6477 28 28 import java.util.Set; 29 29 30 import org.apache.http.conn.ssl.SSL SocketFactory;30 import org.apache.http.conn.ssl.SSLConnectionSocketFactory; 31 31 32 32 import net.sf.basedb.core.data.FileServerData; 33 33 import net.sf.basedb.core.query.Hql; 34 34 import net.sf.basedb.core.query.Restrictions; 35 import net.sf.basedb.util.ssl.SSLUtil ;35 import net.sf.basedb.util.ssl.SSLUtil2; 36 36 37 37 /** … … 374 374 try 375 375 { 376 return (X509Certificate)SSLUtil .getCertificate(new ByteArrayInputStream(cert), "X.509", null);376 return (X509Certificate)SSLUtil2.getCertificate(new ByteArrayInputStream(cert), "X.509", null); 377 377 } 378 378 catch (Exception ex) … … 439 439 try 440 440 { 441 KeyStore ks = SSLUtil .createKeyStore(new ByteArrayInputStream(key), getClientCertificatePassword(), "PKCS12", null);441 KeyStore ks = SSLUtil2.createKeyStore(new ByteArrayInputStream(key), getClientCertificatePassword(), "PKCS12", null); 442 442 return (X509Certificate)ks.getCertificate(ks.aliases().nextElement()); 443 443 } … … 485 485 Otherwise, the default (as configured in base.config) certificates are used. 486 486 @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()); 491 505 } 492 506 -
trunk/src/core/net/sf/basedb/util/HttpUtil.java
r5360 r6477 22 22 package net.sf.basedb.util; 23 23 24 import java.io.IOException; 24 25 import java.text.SimpleDateFormat; 25 26 import java.util.Date; 26 27 import java.util.Locale; 27 28 29 30 28 31 import org.apache.http.Header; 29 32 import org.apache.http.HttpResponse; 30 33 import org.apache.http.client.HttpClient; 34 import org.apache.http.impl.client.CloseableHttpClient; 31 35 32 36 /** … … 115 119 without trowing an exception. Useful to use in try-catch-finally 116 120 clauses. 121 @deprecated In 3.4, use {@link #shutdown(CloseableHttpClient)} instead 117 122 */ 123 @Deprecated 118 124 public static void shutdown(HttpClient client) 119 125 { … … 125 131 {} 126 132 } 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 } 127 150 128 151 } -
trunk/src/core/net/sf/basedb/util/ssl/SSLUtil.java
r5870 r6477 43 43 import javax.net.ssl.TrustManagerFactory; 44 44 45 import org.apache.http.conn.ssl.SSLSocketFactory;46 47 45 import net.sf.basedb.core.BaseException; 48 46 import net.sf.basedb.core.Config; … … 54 52 @since 2.16 55 53 @base.modified $Date$ 54 @deprecated In 3.4, use {@link SSLUtil2} instead 56 55 */ 56 @Deprecated 57 57 public class SSLUtil 58 58 { … … 60 60 private static KeyManager[] defaultKeyManagers; 61 61 private static TrustManager[] defaultTrustManagers; 62 private static SSLSocketFactory defaultSocketFactory;62 private static org.apache.http.conn.ssl.SSLSocketFactory defaultSocketFactory; 63 63 64 64 /** … … 115 115 @return A SSL socket factory 116 116 */ 117 public static SSLSocketFactory getSSLSocketFactory()117 public static org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory() 118 118 { 119 119 if (defaultSocketFactory == null) … … 133 133 SSLContext.getInstance(sslProtocol, sslProvider); 134 134 context.init(keyManagers, trustManagers, null); 135 defaultSocketFactory = new SSLSocketFactory(context);135 defaultSocketFactory = new org.apache.http.conn.ssl.SSLSocketFactory(context); 136 136 } 137 137 else 138 138 { 139 defaultSocketFactory = new SSLSocketFactory(SSLContext.getDefault());139 defaultSocketFactory = new org.apache.http.conn.ssl.SSLSocketFactory(SSLContext.getDefault()); 140 140 } 141 141 } … … 164 164 @return A socket factory 165 165 */ 166 public static SSLSocketFactory getSSLSocketFactory(byte[] serverCertificate,166 public static org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory(byte[] serverCertificate, 167 167 byte[] clientCertificate, String clientCertificatePassword) 168 168 { … … 174 174 String sslProtocol = Config.getString("ssl.context.protocol", "TLS"); 175 175 String sslProvider = Config.getString("ssl.context.provider"); 176 SSLSocketFactory factory = null;176 org.apache.http.conn.ssl.SSLSocketFactory factory = null; 177 177 try 178 178 { … … 214 214 SSLContext.getInstance(sslProtocol, sslProvider); 215 215 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()); 221 221 } 222 222 } -
trunk/src/core/net/sf/basedb/util/uri/http/HttpConnectionManager.java
r5870 r6477 22 22 package net.sf.basedb.util.uri.http; 23 23 24 import java.io.Closeable;25 24 import java.io.IOException; 26 25 import java.io.InputStream; … … 34 33 import org.apache.http.auth.Credentials; 35 34 import org.apache.http.auth.UsernamePasswordCredentials; 35 import org.apache.http.client.CredentialsProvider; 36 36 import org.apache.http.client.HttpClient; 37 import org.apache.http.impl.client.CloseableHttpClient; 37 38 import org.apache.http.client.methods.HttpGet; 38 39 import 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; 40 import org.apache.http.conn.ssl.SSLConnectionSocketFactory; 41 import org.apache.http.impl.client.BasicCredentialsProvider; 42 import org.apache.http.impl.client.HttpClientBuilder; 43 import org.apache.http.impl.conn.DefaultSchemePortResolver; 42 44 43 45 import net.sf.basedb.core.InvalidDataException; 44 46 import net.sf.basedb.util.HttpUtil; 45 import net.sf.basedb.util.ssl.SSLUtil ;47 import net.sf.basedb.util.ssl.SSLUtil2; 46 48 import net.sf.basedb.util.uri.CloseResourceInputStream; 47 49 import net.sf.basedb.util.uri.ConnectionParameters; … … 89 91 { 90 92 URI uri = getURI(); 91 HttpClient client = null;93 CloseableHttpClient client = null; 92 94 InputStream stream = null; 93 95 try 94 96 { 95 97 HttpGet get = new HttpGet(uri); 96 client = create HttpClient(uri, parameters);98 client = createCloseableHttpClient(uri, parameters); 97 99 HttpResponse response = client.execute(get); 98 100 if (metadata == null) metadata = createMetadata(uri, response); … … 101 103 { 102 104 // 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); 104 106 } 105 107 } … … 119 121 { 120 122 URI uri = getURI(); 121 HttpClient client = null;123 CloseableHttpClient client = null; 122 124 try 123 125 { 124 126 HttpHead head = new HttpHead(uri); 125 client = create HttpClient(uri, parameters);127 client = createCloseableHttpClient(uri, parameters); 126 128 HttpResponse response = client.execute(head); 127 129 … … 152 154 } 153 155 // -------------------------------------- 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 } 154 166 155 167 /** … … 157 169 given URI. 158 170 */ 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(); 163 177 164 178 // Do we need to provide username/password? … … 166 180 { 167 181 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); 169 186 } 170 187 … … 172 189 { 173 190 // Adds support for https urls 174 SSL SocketFactory sslFactory = null;191 SSLConnectionSocketFactory sslFactory = null; 175 192 if (parameters == null) 176 193 { 177 sslFactory = SSLUtil .getSSLSocketFactory();194 sslFactory = SSLUtil2.getSSLSocketFactory(); 178 195 } 179 196 else 180 197 { 181 sslFactory = SSLUtil .getSSLSocketFactory(parameters.getServerCertificate(),198 sslFactory = SSLUtil2.getSSLSocketFactory(parameters.getServerCertificate(), 182 199 parameters.getClientCertificate(), parameters.getClientCertificatePassword()); 183 200 } 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(); 188 207 } 189 208 … … 219 238 return meta; 220 239 } 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 243 241 244 242 }
Note: See TracChangeset
for help on using the changeset viewer.