use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.
the class SmtpMonitorIT method testPollCaseForCRLFCheck.
@Test
public void testPollCaseForCRLFCheck() throws UnknownHostException, InterruptedException {
m_serverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
m_serverSocket.setSoTimeout(1000);
Socket s = m_serverSocket.accept();
System.out.println("S: 220 localhost.localdomain ESMTP bogon");
// Having \r should fail in cheking for end of the line as the requirement is for CRLF
s.getOutputStream().write("220 localhost.localdomain ESMTP bogon\r".getBytes());
BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
String command = r.readLine();
System.out.println("C: " + command);
if (command.startsWith("HELO ")) {
System.out.println("S: 250 Hello");
s.getOutputStream().write("250 Hello\r\n".getBytes());
}
command = r.readLine();
System.out.println("C: " + command);
if (command.equals("QUIT")) {
System.out.println("S: 221-Goodbye, friend.");
s.getOutputStream().write("221-Goodbye, friend.\r\n".getBytes());
System.out.println("S: 221 See ya");
s.getOutputStream().write("221 See ya\r\n".getBytes());
}
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
});
m_serverThread.start();
ServiceMonitor sm = new SmtpMonitor();
MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("port", m_serverSocket.getLocalPort());
PollStatus ps = sm.poll(svc, parms);
assertTrue(ps.isUnavailable());
assertFalse(ps.isUp());
}
use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.
the class SmtpMonitorIT method testPoll.
@Test
public void testPoll() throws UnknownHostException, InterruptedException {
m_serverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
m_serverSocket.setSoTimeout(1000);
Socket s = m_serverSocket.accept();
System.out.println("S: 220 localhost.localdomain ESMTP bogon");
s.getOutputStream().write("220 localhost.localdomain ESMTP bogon\r\n".getBytes());
BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
String command = r.readLine();
System.out.println("C: " + command);
if (command.startsWith("HELO ")) {
System.out.println("S: 250 Hello");
s.getOutputStream().write("250 Hello\r\n".getBytes());
}
command = r.readLine();
System.out.println("C: " + command);
if (command.equals("QUIT")) {
System.out.println("S: 250 Hello");
s.getOutputStream().write("221 See ya\r\n".getBytes());
}
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
});
m_serverThread.start();
ServiceMonitor sm = new SmtpMonitor();
MonitoredService svc = new MockMonitoredService(1, "Node One", InetAddressUtils.addr("127.0.0.1"), "SMTP");
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("port", m_serverSocket.getLocalPort());
PollStatus ps = sm.poll(svc, parms);
assertTrue(ps.isUp());
assertFalse(ps.isDown());
}
use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.
the class JdbcFilterDao method getNodeMap.
/**
* {@inheritDoc}
*
* This method returns a map of all nodeids and nodelabels that match
* the rule that is passed in, sorted by nodeid.
* @exception FilterParseException
* if a rule is syntactically incorrect or failed in
* executing the SQL statement
*/
@Override
public SortedMap<Integer, String> getNodeMap(final String rule) throws FilterParseException {
final SortedMap<Integer, String> resultMap = new TreeMap<Integer, String>();
String sqlString;
LOG.debug("Filter.getNodeMap({})", rule);
// get the database connection
Connection conn = null;
final DBUtils d = new DBUtils(getClass());
try {
conn = getDataSource().getConnection();
d.watch(conn);
// parse the rule and get the sql select statement
sqlString = getNodeMappingStatement(rule);
LOG.debug("Filter.getNodeMap({}): SQL statement: {}", rule, sqlString);
// execute query
final Statement stmt = conn.createStatement();
d.watch(stmt);
final ResultSet rset = stmt.executeQuery(sqlString);
d.watch(rset);
if (rset != null) {
// Iterate through the result and build the map
while (rset.next()) {
resultMap.put(Integer.valueOf(rset.getInt(1)), rset.getString(2));
}
}
} catch (final FilterParseException e) {
LOG.warn("Filter Parse Exception occurred getting node map.", e);
throw new FilterParseException("Filter Parse Exception occurred getting node map: " + e.getLocalizedMessage(), e);
} catch (final SQLException e) {
LOG.warn("SQL Exception occurred getting node map.", e);
throw new FilterParseException("SQL Exception occurred getting node map: " + e.getLocalizedMessage(), e);
} catch (final Throwable e) {
LOG.error("Exception getting database connection.", e);
throw new UndeclaredThrowableException(e);
} finally {
d.cleanUp();
}
return Collections.unmodifiableSortedMap(resultMap);
}
use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.
the class FtpMonitorTest method testMonitorFailureWithBogusResponse.
public void testMonitorFailureWithBogusResponse() throws Exception {
Thread m_serverThread = new Thread(new Runnable() {
@Override
public void run() {
try {
m_serverSocket.setSoTimeout(1000);
Socket s = m_serverSocket.accept();
s.getOutputStream().write("Go away!".getBytes());
} catch (Throwable e) {
throw new UndeclaredThrowableException(e);
}
}
});
m_serverThread.start();
PollStatus status = doPoll();
assertTrue("status should be unavailable (Down), but is: " + status, status.isUnavailable());
}
use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.
the class Scriptd method onInit.
/**
* Initialize the <em>Scriptd</em> service.
*/
@Override
protected void onInit() {
// Load the configuration information
//
ScriptdConfigFactory aFactory = null;
try {
ScriptdConfigFactory.reload();
aFactory = ScriptdConfigFactory.getInstance();
} catch (IOException ex) {
LOG.error("Failed to load scriptd configuration", ex);
throw new UndeclaredThrowableException(ex);
}
// get the node DAO
BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
NodeDao nodeDao = BeanUtils.getBean(bf, "nodeDao", NodeDao.class);
m_executor = new Executor(aFactory, nodeDao);
}
Aggregations