Skip to content

Commit 317f2b4

Browse files
jonbartelstonygermano
authored andcommitted
OpenIntegrationEngine#24 don't show notifications when there are none
1 parent de9dde6 commit 317f2b4

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed

server/src/com/mirth/connect/client/core/ConnectServiceUtil.java

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -266,51 +266,11 @@ protected static String toNotificationContent (JsonNode node) {
266266
}
267267

268268
public static int getNotificationCount(String serverId, String mirthVersion, Map<String, String> extensionVersions, Set<Integer> archivedNotifications, String[] protocols, String[] cipherSuites) {
269-
CloseableHttpClient client = null;
270-
HttpPost post = new HttpPost();
271-
CloseableHttpResponse response = null;
272-
273269
int notificationCount = 0;
274-
275270
try {
276-
ObjectMapper mapper = new ObjectMapper();
277-
String extensionVersionsJson = mapper.writeValueAsString(extensionVersions);
278-
NameValuePair[] params = { new BasicNameValuePair("op", NOTIFICATION_COUNT_GET),
279-
new BasicNameValuePair("serverId", serverId),
280-
new BasicNameValuePair("version", mirthVersion),
281-
new BasicNameValuePair("extensionVersions", extensionVersionsJson) };
282-
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(TIMEOUT).setConnectionRequestTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build();
283-
284-
post.setURI(URI.create(URL_CONNECT_SERVER + URL_NOTIFICATION_SERVLET));
285-
post.setEntity(new UrlEncodedFormEntity(Arrays.asList(params), Charset.forName("UTF-8")));
286-
287-
HttpClientContext postContext = HttpClientContext.create();
288-
postContext.setRequestConfig(requestConfig);
289-
client = getClient(protocols, cipherSuites);
290-
response = client.execute(post, postContext);
291-
StatusLine statusLine = response.getStatusLine();
292-
int statusCode = statusLine.getStatusCode();
293-
if ((statusCode == HttpStatus.SC_OK)) {
294-
HttpEntity responseEntity = response.getEntity();
295-
Charset responseCharset = null;
296-
try {
297-
responseCharset = ContentType.getOrDefault(responseEntity).getCharset();
298-
} catch (Exception e) {
299-
responseCharset = ContentType.TEXT_PLAIN.getCharset();
300-
}
301-
302-
List<Integer> notificationIds = mapper.readValue(IOUtils.toString(responseEntity.getContent(), responseCharset).trim(), new TypeReference<List<Integer>>() {
303-
});
304-
for (int id : notificationIds) {
305-
if (!archivedNotifications.contains(id)) {
306-
notificationCount++;
307-
}
308-
}
309-
}
310-
} catch (Exception e) {
311-
} finally {
312-
HttpClientUtils.closeQuietly(response);
313-
HttpClientUtils.closeQuietly(client);
271+
notificationCount = getNotifications(serverId, mirthVersion, extensionVersions, protocols, cipherSuites).size();
272+
} catch (Exception ignore) {
273+
System.err.println("Failed to get notification count, defaulting to zero: " + ignore);
314274
}
315275
return notificationCount;
316276
}

0 commit comments

Comments
 (0)