|
9 | 9 |
|
10 | 10 | package com.mirth.connect.util; |
11 | 11 |
|
12 | | -import java.nio.charset.Charset; |
13 | 12 | import java.util.ArrayList; |
14 | 13 | import java.util.LinkedHashMap; |
15 | 14 | import java.util.List; |
|
19 | 18 | import javax.net.ssl.HostnameVerifier; |
20 | 19 | import javax.net.ssl.SSLContext; |
21 | 20 |
|
22 | | -import org.apache.commons.io.IOUtils; |
23 | | -import org.apache.http.HttpEntity; |
24 | | -import org.apache.http.HttpStatus; |
25 | | -import org.apache.http.StatusLine; |
26 | 21 | import org.apache.http.client.config.CookieSpecs; |
27 | | -import org.apache.http.client.config.RequestConfig; |
28 | 22 | import org.apache.http.client.methods.CloseableHttpResponse; |
29 | | -import org.apache.http.client.methods.HttpGet; |
30 | | -import org.apache.http.client.protocol.HttpClientContext; |
31 | 23 | import org.apache.http.client.utils.HttpClientUtils; |
32 | 24 | import org.apache.http.config.RegistryBuilder; |
33 | 25 | import org.apache.http.config.SocketConfig; |
|
39 | 31 | import org.apache.http.conn.util.PublicSuffixMatcher; |
40 | 32 | import org.apache.http.conn.util.PublicSuffixMatcherLoader; |
41 | 33 | import org.apache.http.cookie.CookieSpecProvider; |
42 | | -import org.apache.http.entity.ContentType; |
43 | 34 | import org.apache.http.impl.client.CloseableHttpClient; |
44 | 35 | import org.apache.http.impl.client.HttpClientBuilder; |
45 | 36 | import org.apache.http.impl.client.HttpClients; |
|
48 | 39 | import org.apache.http.impl.cookie.IgnoreSpecProvider; |
49 | 40 | import org.apache.http.impl.cookie.NetscapeDraftSpecProvider; |
50 | 41 | import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; |
51 | | -import org.apache.http.ssl.SSLContexts; |
52 | 42 | import org.apache.logging.log4j.LogManager; |
53 | 43 | import org.apache.logging.log4j.Logger; |
54 | 44 |
|
@@ -145,57 +135,6 @@ public static Map<String, List<String>> getTableMap(String mapVariable, MessageM |
145 | 135 | return map; |
146 | 136 | } |
147 | 137 |
|
148 | | - public static String executeGetRequest(String url, int timeout, boolean hostnameVerification, String[] protocols, String[] cipherSuites) { |
149 | | - return executeGetRequest(url, timeout, hostnameVerification, protocols, cipherSuites, SSLContexts.createSystemDefault()); |
150 | | - } |
151 | | - |
152 | | - public static String executeGetRequest(String url, int timeout, boolean hostnameVerification, String[] protocols, String[] cipherSuites, SSLContext sslContext) { |
153 | | - try { |
154 | | - return doExecuteGetRequest(url, timeout, hostnameVerification, protocols, cipherSuites, sslContext); |
155 | | - } catch (Throwable t) { |
156 | | - logger.error("Error executing GET request at URL " + url, t); |
157 | | - return ""; |
158 | | - } |
159 | | - } |
160 | | - |
161 | | - static String doExecuteGetRequest(String url, int timeout, boolean hostnameVerification, String[] protocols, String[] cipherSuites, SSLContext sslContext) throws Exception { |
162 | | - CloseableHttpClient client = null; |
163 | | - CloseableHttpResponse response = null; |
164 | | - |
165 | | - try { |
166 | | - client = getHttpClient(timeout, hostnameVerification, protocols, cipherSuites, sslContext); |
167 | | - |
168 | | - HttpGet get = new HttpGet(url); |
169 | | - RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build(); |
170 | | - HttpClientContext getContext = HttpClientContext.create(); |
171 | | - getContext.setRequestConfig(requestConfig); |
172 | | - |
173 | | - response = client.execute(get, getContext); |
174 | | - |
175 | | - StatusLine statusLine = response.getStatusLine(); |
176 | | - int statusCode = statusLine.getStatusCode(); |
177 | | - if (statusCode != HttpStatus.SC_OK) { |
178 | | - throw new Exception(statusLine.toString()); |
179 | | - } |
180 | | - |
181 | | - HttpEntity responseEntity = response.getEntity(); |
182 | | - |
183 | | - Charset responseCharset = null; |
184 | | - try { |
185 | | - responseCharset = ContentType.getOrDefault(responseEntity).getCharset(); |
186 | | - } catch (Exception e) { |
187 | | - responseCharset = ContentType.TEXT_PLAIN.getCharset(); |
188 | | - } |
189 | | - |
190 | | - return IOUtils.toString(responseEntity.getContent(), responseCharset).trim(); |
191 | | - } finally { |
192 | | - if (client != null) { |
193 | | - HttpClientUtils.closeQuietly(response); |
194 | | - HttpClientUtils.closeQuietly(client); |
195 | | - } |
196 | | - } |
197 | | - } |
198 | | - |
199 | 138 | public static CloseableHttpClient getHttpClient(int timeout, boolean hostnameVerification, String[] protocols, String[] cipherSuites, SSLContext sslContext) { |
200 | 139 | HostnameVerifier hostnameVerifier = hostnameVerification ? new DefaultHostnameVerifier() : NoopHostnameVerifier.INSTANCE; |
201 | 140 |
|
|
0 commit comments