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) {
|
private String checkServiceStatus(String service) {
|
||||||
try {
|
try {
|
||||||
if (service.equals(ServiceName.REMOTE_CASE_DATABASE.toString())) {
|
if (service.equals(ServiceName.REMOTE_CASE_DATABASE.toString())) {
|
||||||
if (canConnectToRemoteDb()) {
|
if (UserPreferences.getDatabaseConnectionInfo().canConnect()) {
|
||||||
setServiceStatus(ServiceName.REMOTE_CASE_DATABASE.toString(), ServiceStatus.UP.toString(), "");
|
setServiceStatus(ServiceName.REMOTE_CASE_DATABASE.toString(), ServiceStatus.UP.toString(), "");
|
||||||
return ServiceStatus.UP.toString();
|
return ServiceStatus.UP.toString();
|
||||||
} else {
|
} else {
|
||||||
@ -221,7 +221,7 @@ public class ServicesMonitor {
|
|||||||
return ServiceStatus.DOWN.toString();
|
return ServiceStatus.DOWN.toString();
|
||||||
}
|
}
|
||||||
} else if (service.equals(ServiceName.MESSAGING.toString())) {
|
} else if (service.equals(ServiceName.MESSAGING.toString())) {
|
||||||
if (canConnectToMessagingService()) {
|
if (UserPreferences.getMessageServiceConnectionInfo().canConnect()) {
|
||||||
setServiceStatus(ServiceName.MESSAGING.toString(), ServiceStatus.UP.toString(), "");
|
setServiceStatus(ServiceName.MESSAGING.toString(), ServiceStatus.UP.toString(), "");
|
||||||
return ServiceStatus.UP.toString();
|
return ServiceStatus.UP.toString();
|
||||||
} else {
|
} else {
|
||||||
@ -297,33 +297,6 @@ public class ServicesMonitor {
|
|||||||
public void removeSubscriber(PropertyChangeListener subscriber) {
|
public void removeSubscriber(PropertyChangeListener subscriber) {
|
||||||
eventPublisher.removeSubscriber(serviceNames, subscriber);
|
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.
|
* Verifies connectivity to all services.
|
||||||
|
@ -21,6 +21,10 @@ package org.sleuthkit.autopsy.events;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import javax.annotation.concurrent.Immutable;
|
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.
|
* 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));
|
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