mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-19 11:07:43 +00:00
Added canConnect() method to the MessageServiceConnectionInfo class
This commit is contained in:
parent
ef48080439
commit
ba8dd33a06
@ -204,7 +204,7 @@ public class ServicesMonitor {
|
||||
private String checkServiceStatus(String service) {
|
||||
try {
|
||||
if (service.equals(ServiceName.REMOTE_CASE_DATABASE.toString())) {
|
||||
if (canConnectToRemoteDb()) {
|
||||
if (UserPreferences.getDatabaseConnectionInfo().canConnect()) {
|
||||
setServiceStatus(ServiceName.REMOTE_CASE_DATABASE.toString(), ServiceStatus.UP.toString(), "");
|
||||
return ServiceStatus.UP.toString();
|
||||
} else {
|
||||
@ -221,7 +221,7 @@ public class ServicesMonitor {
|
||||
return ServiceStatus.DOWN.toString();
|
||||
}
|
||||
} else if (service.equals(ServiceName.MESSAGING.toString())) {
|
||||
if (canConnectToMessagingService()) {
|
||||
if (UserPreferences.getMessageServiceConnectionInfo().canConnect()) {
|
||||
setServiceStatus(ServiceName.MESSAGING.toString(), ServiceStatus.UP.toString(), "");
|
||||
return ServiceStatus.UP.toString();
|
||||
} else {
|
||||
@ -298,33 +298,6 @@ public class ServicesMonitor {
|
||||
eventPublisher.removeSubscriber(serviceNames, subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies connection to remote database.
|
||||
*
|
||||
* @return True if connection can be established, false otherwise.
|
||||
*/
|
||||
private boolean canConnectToRemoteDb() {
|
||||
return UserPreferences.getDatabaseConnectionInfo().canConnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies connection to messaging service.
|
||||
*
|
||||
* @return True if connection can be established, false otherwise.
|
||||
*/
|
||||
private boolean canConnectToMessagingService() {
|
||||
MessageServiceConnectionInfo msgInfo = UserPreferences.getMessageServiceConnectionInfo();
|
||||
try {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(msgInfo.getUserName(), msgInfo.getPassword(), msgInfo.getURI());
|
||||
Connection connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
connection.close();
|
||||
return true;
|
||||
} catch (URISyntaxException | JMSException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies connectivity to all services.
|
||||
*/
|
||||
|
@ -21,6 +21,10 @@ package org.sleuthkit.autopsy.events;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.JMSException;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.sleuthkit.autopsy.core.UserPreferences;
|
||||
|
||||
/**
|
||||
* Connection info for a Java Message Service (JMS) provider. Thread-safe.
|
||||
@ -99,4 +103,20 @@ public final class MessageServiceConnectionInfo {
|
||||
return new URI(String.format(MESSAGE_SERVICE_URI, host, port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies connection to messaging service.
|
||||
*
|
||||
* @return True if connection can be established, false otherwise.
|
||||
*/
|
||||
public boolean canConnect() {
|
||||
try {
|
||||
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(getUserName(), getPassword(), getURI());
|
||||
Connection connection = connectionFactory.createConnection();
|
||||
connection.start();
|
||||
connection.close();
|
||||
return true;
|
||||
} catch (URISyntaxException | JMSException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user