-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1072 from kushalagrawal1/master
Issue : #[1070](#1070)
- Loading branch information
Showing
6 changed files
with
151 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...y/src/main/java/org/openstack4j/connectors/resteasy/executors/ApacheHttpClientEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.openstack4j.connectors.resteasy.executors; | ||
|
||
import org.apache.http.HttpHost; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.config.RequestConfig; | ||
import org.apache.http.conn.ssl.NoopHostnameVerifier; | ||
import org.apache.http.impl.client.DefaultRedirectStrategy; | ||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; | ||
import org.openstack4j.core.transport.Config; | ||
import org.openstack4j.core.transport.UntrustedSSL; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
/** | ||
* Default Apache HttpClient based Executor | ||
* | ||
* @author Jeremy Unruh | ||
*/ | ||
public class ApacheHttpClientEngine extends ApacheHttpClient4Engine { | ||
|
||
ApacheHttpClientEngine(HttpClient client) { | ||
super(client); | ||
} | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ApacheHttpClientEngine.class); | ||
|
||
public static ApacheHttpClientEngine create(Config config) { | ||
|
||
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom(); | ||
|
||
if (config.getReadTimeout() > 0) { | ||
requestConfigBuilder.setConnectionRequestTimeout(config.getReadTimeout()); | ||
} | ||
|
||
if (config.getConnectTimeout() > 0) { | ||
requestConfigBuilder.setConnectTimeout(config.getConnectTimeout()); | ||
} | ||
|
||
/*HttpClient client*/ | ||
|
||
HttpClientBuilder httpClientBuilder = HttpClients.custom(); | ||
|
||
if (config.isIgnoreSSLVerification()) { | ||
httpClientBuilder.setSSLContext(UntrustedSSL.getSSLContext()); | ||
httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier()); | ||
} | ||
|
||
if (config.getHostNameVerifier() != null) { | ||
httpClientBuilder.setSSLHostnameVerifier(config.getHostNameVerifier()); | ||
} | ||
|
||
if (config.getProxy() != null) { | ||
try { | ||
URL url = new URL(config.getProxy().getHost()); | ||
HttpHost proxy = new HttpHost(url.getHost(), config.getProxy().getPort(), url.getProtocol()); | ||
requestConfigBuilder.setProxy(proxy); | ||
} catch (MalformedURLException e) { | ||
LOGGER.error("Invalid proxy Url :%s",config.getProxy(),e); | ||
} | ||
} | ||
|
||
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build()); | ||
httpClientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() { | ||
@Override | ||
protected boolean isRedirectable(String method) | ||
{ | ||
return true; | ||
} | ||
}); | ||
|
||
HttpClient client = httpClientBuilder.build(); | ||
return new ApacheHttpClientEngine(client); | ||
} | ||
|
||
} |
Oops, something went wrong.