28
28
import org .apache .http .client .methods .HttpPost ;
29
29
import org .apache .http .client .protocol .HttpClientContext ;
30
30
import org .apache .http .client .utils .HttpClientUtils ;
31
+ import org .apache .http .config .RegistryBuilder ;
32
+ import org .apache .http .config .SocketConfig ;
33
+ import org .apache .http .conn .socket .ConnectionSocketFactory ;
34
+ import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
35
+ import org .apache .http .conn .ssl .SSLContexts ;
31
36
import org .apache .http .entity .ContentType ;
32
37
import org .apache .http .impl .client .CloseableHttpClient ;
33
38
import org .apache .http .impl .client .HttpClients ;
39
+ import org .apache .http .impl .conn .BasicHttpClientConnectionManager ;
34
40
import org .apache .http .message .BasicNameValuePair ;
35
41
36
42
import com .fasterxml .jackson .core .type .TypeReference ;
39
45
import com .mirth .connect .model .User ;
40
46
import com .mirth .connect .model .converters .ObjectXMLSerializer ;
41
47
import com .mirth .connect .model .notification .Notification ;
48
+ import com .mirth .connect .util .MirthSSLUtil ;
42
49
43
50
public class ConnectServiceUtil {
44
51
private final static String URL_CONNECT_SERVER = "https://connect.mirthcorp.com" ;
@@ -50,7 +57,7 @@ public class ConnectServiceUtil {
50
57
private final static int TIMEOUT = 10000 ;
51
58
public final static Integer MILLIS_PER_DAY = 86400000 ;
52
59
53
- public static void registerUser (String serverId , String mirthVersion , User user ) throws ClientException {
60
+ public static void registerUser (String serverId , String mirthVersion , User user , String [] protocols , String [] cipherSuites ) throws ClientException {
54
61
CloseableHttpClient httpClient = null ;
55
62
CloseableHttpResponse httpResponse = null ;
56
63
NameValuePair [] params = { new BasicNameValuePair ("serverId" , serverId ),
@@ -65,7 +72,7 @@ public static void registerUser(String serverId, String mirthVersion, User user)
65
72
try {
66
73
HttpClientContext postContext = HttpClientContext .create ();
67
74
postContext .setRequestConfig (requestConfig );
68
- httpClient = HttpClients . createDefault ( );
75
+ httpClient = getClient ( protocols , cipherSuites );
69
76
httpResponse = httpClient .execute (post , postContext );
70
77
StatusLine statusLine = httpResponse .getStatusLine ();
71
78
int statusCode = statusLine .getStatusCode ();
@@ -80,7 +87,7 @@ public static void registerUser(String serverId, String mirthVersion, User user)
80
87
}
81
88
}
82
89
83
- public static List <Notification > getNotifications (String serverId , String mirthVersion , Map <String , String > extensionVersions ) throws Exception {
90
+ public static List <Notification > getNotifications (String serverId , String mirthVersion , Map <String , String > extensionVersions , String [] protocols , String [] cipherSuites ) throws Exception {
84
91
CloseableHttpClient client = null ;
85
92
HttpPost post = new HttpPost ();
86
93
CloseableHttpResponse response = null ;
@@ -101,7 +108,7 @@ public static List<Notification> getNotifications(String serverId, String mirthV
101
108
102
109
HttpClientContext postContext = HttpClientContext .create ();
103
110
postContext .setRequestConfig (requestConfig );
104
- client = HttpClients . createDefault ( );
111
+ client = getClient ( protocols , cipherSuites );
105
112
response = client .execute (post , postContext );
106
113
StatusLine statusLine = response .getStatusLine ();
107
114
int statusCode = statusLine .getStatusCode ();
@@ -138,7 +145,7 @@ public static List<Notification> getNotifications(String serverId, String mirthV
138
145
return allNotifications ;
139
146
}
140
147
141
- public static int getNotificationCount (String serverId , String mirthVersion , Map <String , String > extensionVersions , Set <Integer > archivedNotifications ) {
148
+ public static int getNotificationCount (String serverId , String mirthVersion , Map <String , String > extensionVersions , Set <Integer > archivedNotifications , String [] protocols , String [] cipherSuites ) {
142
149
CloseableHttpClient client = null ;
143
150
HttpPost post = new HttpPost ();
144
151
CloseableHttpResponse response = null ;
@@ -159,7 +166,7 @@ public static int getNotificationCount(String serverId, String mirthVersion, Map
159
166
160
167
HttpClientContext postContext = HttpClientContext .create ();
161
168
postContext .setRequestConfig (requestConfig );
162
- client = HttpClients . createDefault ( );
169
+ client = getClient ( protocols , cipherSuites );
163
170
response = client .execute (post , postContext );
164
171
StatusLine statusLine = response .getStatusLine ();
165
172
int statusCode = statusLine .getStatusCode ();
@@ -188,7 +195,7 @@ public static int getNotificationCount(String serverId, String mirthVersion, Map
188
195
return notificationCount ;
189
196
}
190
197
191
- public static boolean sendStatistics (String serverId , String mirthVersion , boolean server , String data ) {
198
+ public static boolean sendStatistics (String serverId , String mirthVersion , boolean server , String data , String [] protocols , String [] cipherSuites ) {
192
199
if (data == null ) {
193
200
return false ;
194
201
}
@@ -210,7 +217,7 @@ public static boolean sendStatistics(String serverId, String mirthVersion, boole
210
217
try {
211
218
HttpClientContext postContext = HttpClientContext .create ();
212
219
postContext .setRequestConfig (requestConfig );
213
- client = HttpClients . createDefault ( );
220
+ client = getClient ( protocols , cipherSuites );
214
221
response = client .execute (post , postContext );
215
222
StatusLine statusLine = response .getStatusLine ();
216
223
int statusCode = statusLine .getStatusCode ();
@@ -224,4 +231,16 @@ public static boolean sendStatistics(String serverId, String mirthVersion, boole
224
231
}
225
232
return isSent ;
226
233
}
234
+
235
+ private static CloseableHttpClient getClient (String [] protocols , String [] cipherSuites ) {
236
+ RegistryBuilder <ConnectionSocketFactory > socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory > create ();
237
+ String [] enabledProtocols = MirthSSLUtil .getEnabledHttpsProtocols (protocols );
238
+ String [] enabledCipherSuites = MirthSSLUtil .getEnabledHttpsCipherSuites (cipherSuites );
239
+ SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory (SSLContexts .createSystemDefault (), enabledProtocols , enabledCipherSuites , SSLConnectionSocketFactory .STRICT_HOSTNAME_VERIFIER );
240
+ socketFactoryRegistry .register ("https" , sslConnectionSocketFactory );
241
+
242
+ BasicHttpClientConnectionManager httpClientConnectionManager = new BasicHttpClientConnectionManager (socketFactoryRegistry .build ());
243
+ httpClientConnectionManager .setSocketConfig (SocketConfig .custom ().setSoTimeout (TIMEOUT ).build ());
244
+ return HttpClients .custom ().setConnectionManager (httpClientConnectionManager ).build ();
245
+ }
227
246
}
0 commit comments