|
5 | 5 | import java.util.Map; |
6 | 6 |
|
7 | 7 | import org.apache.http.HttpHost; |
| 8 | +import org.apache.http.auth.AuthScope; |
| 9 | +import org.apache.http.auth.UsernamePasswordCredentials; |
| 10 | +import org.apache.http.client.CredentialsProvider; |
8 | 11 | import org.apache.http.client.HttpClient; |
9 | 12 | import org.apache.http.client.config.CookieSpecs; |
10 | 13 | import org.apache.http.client.config.RequestConfig; |
11 | 14 | import org.apache.http.client.protocol.HttpClientContext; |
12 | 15 | import org.apache.http.config.Registry; |
13 | 16 | import org.apache.http.config.RegistryBuilder; |
14 | 17 | import org.apache.http.conn.routing.HttpRoute; |
| 18 | +import org.apache.http.conn.routing.HttpRoutePlanner; |
15 | 19 | import org.apache.http.conn.socket.ConnectionSocketFactory; |
16 | 20 | import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
17 | 21 | import org.apache.http.conn.ssl.NoopHostnameVerifier; |
18 | 22 | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
19 | 23 | import org.apache.http.conn.ssl.TrustAllStrategy; |
20 | 24 | import org.apache.http.impl.client.BasicCookieStore; |
| 25 | +import org.apache.http.impl.client.BasicCredentialsProvider; |
21 | 26 | import org.apache.http.impl.client.HttpClientBuilder; |
| 27 | +import org.apache.http.impl.conn.DefaultProxyRoutePlanner; |
22 | 28 | import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
23 | 29 | import org.apache.http.ssl.SSLContextBuilder; |
24 | 30 |
|
@@ -104,13 +110,27 @@ private void createConnection(String apiManagerURL) throws AppException { |
104 | 110 | // We have make sure, that cookies are correclty parsed! |
105 | 111 | RequestConfig defaultRequestConfig = RequestConfig.custom() |
106 | 112 | .setCookieSpec(CookieSpecs.STANDARD).build(); |
107 | | - |
108 | | - this.httpClient = HttpClientBuilder.create() |
| 113 | + CoreParameters params = CoreParameters.getInstance(); |
| 114 | + |
| 115 | + HttpClientBuilder clientBuilder = HttpClientBuilder.create() |
109 | 116 | .disableRedirectHandling() |
110 | 117 | .setConnectionManager(cm) |
111 | 118 | .useSystemProperties() |
112 | | - .setDefaultRequestConfig(defaultRequestConfig) |
113 | | - .build(); |
| 119 | + .setDefaultRequestConfig(defaultRequestConfig); |
| 120 | + |
| 121 | + // Check if a proxy is configured |
| 122 | + if(params.getProxyHost()!=null) { |
| 123 | + HttpHost proxyHost = new HttpHost(params.getProxyHost(), params.getProxyPort()); |
| 124 | + HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost); |
| 125 | + clientBuilder.setRoutePlanner(routePlanner); |
| 126 | + if(params.getProxyUsername()!=null) { |
| 127 | + CredentialsProvider credentialsPovider = new BasicCredentialsProvider(); |
| 128 | + credentialsPovider.setCredentials(new AuthScope(params.getProxyHost(), params.getPort()), new UsernamePasswordCredentials(params.getProxyUsername(), params.getProxyPassword())); |
| 129 | + clientBuilder.setDefaultCredentialsProvider(credentialsPovider); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + this.httpClient = clientBuilder.build(); |
114 | 134 | } catch (Exception e) { |
115 | 135 | throw new AppException("Can't create connection to API-Manager.", ErrorCode.API_MANAGER_COMMUNICATION); |
116 | 136 | } |
|
0 commit comments