Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
CLOUDIFY-2414 - HTTPS (SSL) proxy not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
noak committed Jan 27, 2014
1 parent e03ece9 commit 2b80bfd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
Expand Up @@ -22,7 +22,6 @@
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.cloudifysource.domain.cloud.Cloud;
import org.cloudifysource.domain.cloud.ScriptLanguages;
Expand Down Expand Up @@ -79,7 +78,7 @@ public void validateCloudifyUrls(final ValidationContext validationContext) thro

}

private void validateUrl(final DefaultHttpClient httpClient, final String cloudifyUrl,
private void validateUrl(final SystemDefaultHttpClient httpClient, final String cloudifyUrl,
final ValidationContext validationContext)
throws CloudProvisioningException {

Expand Down
Expand Up @@ -52,16 +52,13 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
Expand Down Expand Up @@ -107,7 +104,7 @@ public class GSRestClient {
private static final String MIME_TYPE_APP_JSON = "application/json";

// TODO change when legit certificate is available
private final DefaultHttpClient httpClient;
private final SystemDefaultHttpClient httpClient;
private final URL url;
private final String urlStr;

Expand All @@ -134,7 +131,7 @@ public GSRestClient(final String username, final String password, final URL url,
if (isSSL()) {
httpClient = getSSLHttpClient();
} else {
httpClient = new DefaultHttpClient();
httpClient = new SystemDefaultHttpClient();
}
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {

Expand Down Expand Up @@ -169,7 +166,7 @@ public GSRestClient(Credentials credentials, final URL url, final String version
if (isSSL()) {
httpClient = getSSLHttpClient();
} else {
httpClient = new DefaultHttpClient();
httpClient = new SystemDefaultHttpClient();
}
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {

Expand Down Expand Up @@ -820,7 +817,7 @@ protected final File writeMapToFile(final Properties props) throws IOException {
* @throws RestException
* Reporting different failures while creating the HTTP client
*/
public final DefaultHttpClient getSSLHttpClient() throws RestException {
public final SystemDefaultHttpClient getSSLHttpClient() throws RestException {
try {
final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
// TODO : support self-signed certs if configured by user upon
Expand All @@ -833,13 +830,10 @@ public final DefaultHttpClient getSSLHttpClient() throws RestException {
final HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

final SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme(HTTPS, sf, url.getPort()));

final ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

return new DefaultHttpClient(ccm, params);
SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient(params);
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme(HTTPS, sf, url.getPort()));

return httpClient;
} catch (final KeyStoreException e) {
throw new RestException(e);
} catch (final NoSuchAlgorithmException e) {
Expand Down
Expand Up @@ -32,13 +32,10 @@

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
Expand Down Expand Up @@ -586,7 +583,7 @@ protected void validateFile(final File file) throws RestClientException {
}

private RestClientExecutor createExecutor(final URL url, final String apiVersion) throws RestClientException {
DefaultHttpClient httpClient;
SystemDefaultHttpClient httpClient;
if (HTTPS.equals(url.getProtocol())) {
httpClient = getSSLHttpClient(url);
} else {
Expand All @@ -607,17 +604,16 @@ private RestClientExecutor createExecutor(final URL url, final String apiVersion
* @throws org.cloudifysource.restclient.exceptions.RestClientException
* Reporting different failures while creating the HTTP client
*/
private DefaultHttpClient getSSLHttpClient(final URL url) throws RestClientException {
private SystemDefaultHttpClient getSSLHttpClient(final URL url) throws RestClientException {
try {
final X509TrustManager trustManager = createTrustManager();
final SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { trustManager }, null);
final SSLSocketFactory ssf = new SSLSocketFactory(ctx, createHostnameVerifier());
final AbstractHttpClient base = new DefaultHttpClient();
final ClientConnectionManager ccm = base.getConnectionManager();
final SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme(HTTPS, url.getPort(), ssf));
return new DefaultHttpClient(ccm, base.getParams());
final AbstractHttpClient base = new SystemDefaultHttpClient();
SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient(base.getParams());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme(HTTPS, url.getPort(), ssf));
return httpClient;
} catch (final Exception e) {
throw new RestClientException(FAILED_CREATING_CLIENT, "Failed creating http client",
ExceptionUtils.getFullStackTrace(e));
Expand Down
Expand Up @@ -40,7 +40,7 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.cloudifysource.dsl.internal.CloudifyConstants;
import org.cloudifysource.dsl.internal.CloudifyErrorMessages;
import org.cloudifysource.dsl.rest.response.Response;
Expand All @@ -64,7 +64,7 @@ public class RestClientExecutor {
private static final int DEFAULT_TRIALS_NUM = 1;
private static final int GET_TRIALS_NUM = 3;

private final DefaultHttpClient httpClient;
private final SystemDefaultHttpClient httpClient;
private String urlStr;


Expand All @@ -74,7 +74,7 @@ public class RestClientExecutor {
* @param url .
*/
public RestClientExecutor(
final DefaultHttpClient httpClient,
final SystemDefaultHttpClient httpClient,
final URL url) {
this.httpClient = httpClient;
this.urlStr = url.toExternalForm();
Expand Down

0 comments on commit 2b80bfd

Please sign in to comment.