Search in sources :

Example 31 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class RegistrationListenerBean method invokeMethod.

private void invokeMethod(String methodName, Registration registration) {
    try {
        Method method = getMethod(methodName);
        method.invoke(m_target, registration.getProvider(m_serviceInterface), registration.getProperties());
    } catch (Throwable e) {
        throw new UndeclaredThrowableException(e, "Unexexpected exception invoking method " + methodName);
    } finally {
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Method(java.lang.reflect.Method)

Example 32 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class AnnotationBasedEventListenerAdapter method onEvent.

/* (non-Javadoc)
     * @see org.opennms.netmgt.eventd.EventListener#onEvent(org.opennms.netmgt.xml.event.Event)
     */
/** {@inheritDoc} */
@Override
public void onEvent(final Event event) {
    if (event.getUei() == null) {
        return;
    }
    Method m = m_ueiToHandlerMap.get(event.getUei());
    if (m == null) {
        // Try to get a catch-all event handler
        m = m_ueiToHandlerMap.get(EventHandler.ALL_UEIS);
        if (m == null) {
            throw new IllegalArgumentException("Received an event for which we have no handler!");
        }
    }
    final Method method = m;
    Logging.withPrefix(m_logPrefix, new Runnable() {

        @Override
        public void run() {
            try {
                preprocessEvent(event);
                processEvent(event, method);
                postprocessEvent(event);
            } catch (IllegalArgumentException e) {
                throw e;
            } catch (IllegalAccessException e) {
                throw new UndeclaredThrowableException(e);
            } catch (InvocationTargetException e) {
                handleException(event, e.getCause());
            }
        }
    });
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 33 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class TcpEventReceiver method start.

/**
     * Allocates the server socket and starts up the server socket processor
     * thread. If an error occurs allocating the server socket or the Fiber is
     * in an erronous state then a
     * {@link java.lang.RuntimeException runtime exception}is thrown.
     *
     * @throws java.lang.reflect.UndeclaredThrowableException
     *             Thrown if an error occurs allocating the server socket.
     * @throws java.lang.RuntimeException
     *             Thrown if the fiber is in an erronous state or the underlying
     *             thread cannot be started.
     */
@Override
public synchronized void start() {
    assertNotRunning();
    m_status = STARTING;
    try {
        InetAddress address = "*".equals(m_ipAddress) ? null : InetAddressUtils.addr(m_ipAddress);
        m_server = new TcpServer(this, m_eventHandlers, m_tcpPort, address);
        if (m_logPrefix != null) {
            m_server.setLogPrefix(m_logPrefix);
        }
        if (m_recsPerConn != UNLIMITED_EVENTS) {
            m_server.setEventsPerConnection(m_recsPerConn);
        }
    } catch (IOException e) {
        throw new UndeclaredThrowableException(e, "Error opening server socket: " + e);
    }
    m_worker = new Thread(m_server, "Event TCP Server[" + m_tcpPort + "]");
    try {
        m_worker.start();
    } catch (RuntimeException e) {
        m_worker.interrupt();
        m_status = STOPPED;
        throw e;
    }
    m_status = RUNNING;
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Example 34 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class SmtpMonitorIT method testPollCase3.

@Test
public void testPollCase3() 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: 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.isUp());
    assertFalse(ps.isDown());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 35 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project opennms by OpenNMS.

the class SmtpMonitorIT method testPollCase2.

@Test
public void testPollCase2() 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());
                    System.out.println("S: 250 send me mail now!");
                    s.getOutputStream().write("250 send me mail now!\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());
}
Also used : PollStatus(org.opennms.netmgt.poller.PollStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) MonitoredService(org.opennms.netmgt.poller.MonitoredService) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) ServiceMonitor(org.opennms.netmgt.poller.ServiceMonitor) MockMonitoredService(org.opennms.netmgt.poller.mock.MockMonitoredService) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BufferedReader(java.io.BufferedReader) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6