Search in sources :

Example 16 with MultiException

use of org.eclipse.jetty.util.MultiException in project hbase by apache.

the class HttpServer method start.

/**
   * Start the server. Does not wait for the server to start.
   */
public void start() throws IOException {
    try {
        try {
            openListeners();
            webServer.start();
        } catch (IOException ex) {
            LOG.info("HttpServer.start() threw a non Bind IOException", ex);
            throw ex;
        } catch (MultiException ex) {
            LOG.info("HttpServer.start() threw a MultiException", ex);
            throw ex;
        }
        // Make sure there is no handler failures.
        Handler[] handlers = webServer.getHandlers();
        for (int i = 0; i < handlers.length; i++) {
            if (handlers[i].isFailed()) {
                throw new IOException("Problem in starting http server. Server handlers failed");
            }
        }
        // Make sure there are no errors initializing the context.
        Throwable unavailableException = webAppContext.getUnavailableException();
        if (unavailableException != null) {
            // Have to stop the webserver, or else its non-daemon threads
            // will hang forever.
            webServer.stop();
            throw new IOException("Unable to initialize WebAppContext", unavailableException);
        }
    } catch (IOException e) {
        throw e;
    } catch (InterruptedException e) {
        throw (IOException) new InterruptedIOException("Interrupted while starting HTTP server").initCause(e);
    } catch (Exception e) {
        throw new IOException("Problem starting http server", e);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Handler(org.eclipse.jetty.server.Handler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) MultiException(org.eclipse.jetty.util.MultiException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) MultiException(org.eclipse.jetty.util.MultiException) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) IOException(java.io.IOException)

Example 17 with MultiException

use of org.eclipse.jetty.util.MultiException in project hadoop by apache.

the class TestLogAggregationService method checkEvents.

@SuppressWarnings("unchecked")
private static <T extends Event<?>> void checkEvents(EventHandler<T> eventHandler, T[] expectedEvents, boolean inOrder, String... methods) throws Exception {
    Class<T> genericClass = (Class<T>) expectedEvents.getClass().getComponentType();
    ArgumentCaptor<T> eventCaptor = ArgumentCaptor.forClass(genericClass);
    // captor work work unless used via a verify
    verify(eventHandler, atLeast(0)).handle(eventCaptor.capture());
    List<T> actualEvents = eventCaptor.getAllValues();
    // batch up exceptions so junit presents them as one
    MultiException failures = new MultiException();
    try {
        assertEquals("expected events", expectedEvents.length, actualEvents.size());
    } catch (Throwable e) {
        failures.add(e);
    }
    if (inOrder) {
        // sequentially verify the events
        int len = Math.max(expectedEvents.length, actualEvents.size());
        for (int n = 0; n < len; n++) {
            try {
                String expect = (n < expectedEvents.length) ? eventToString(expectedEvents[n], methods) : null;
                String actual = (n < actualEvents.size()) ? eventToString(actualEvents.get(n), methods) : null;
                assertEquals("event#" + n, expect, actual);
            } catch (Throwable e) {
                failures.add(e);
            }
        }
    } else {
        // verify the actual events were expected
        // verify no expected events were not seen
        Set<String> expectedSet = new HashSet<String>();
        for (T expectedEvent : expectedEvents) {
            expectedSet.add(eventToString(expectedEvent, methods));
        }
        for (T actualEvent : actualEvents) {
            try {
                String actual = eventToString(actualEvent, methods);
                assertTrue("unexpected event: " + actual, expectedSet.remove(actual));
            } catch (Throwable e) {
                failures.add(e);
            }
        }
        for (String expected : expectedSet) {
            try {
                Assert.fail("missing event: " + expected);
            } catch (Throwable e) {
                failures.add(e);
            }
        }
    }
    failures.ifExceptionThrow();
}
Also used : MultiException(org.eclipse.jetty.util.MultiException) HashSet(java.util.HashSet)

Example 18 with MultiException

use of org.eclipse.jetty.util.MultiException in project hadoop by apache.

the class HttpServer2 method start.

/**
   * Start the server. Does not wait for the server to start.
   */
public void start() throws IOException {
    try {
        try {
            openListeners();
            webServer.start();
        } catch (IOException ex) {
            LOG.info("HttpServer.start() threw a non Bind IOException", ex);
            throw ex;
        } catch (MultiException ex) {
            LOG.info("HttpServer.start() threw a MultiException", ex);
            throw ex;
        }
        // Make sure there is no handler failures.
        Handler[] hs = webServer.getHandlers();
        for (Handler handler : hs) {
            if (handler.isFailed()) {
                throw new IOException("Problem in starting http server. Server handlers failed");
            }
        }
        // Make sure there are no errors initializing the context.
        Throwable unavailableException = webAppContext.getUnavailableException();
        if (unavailableException != null) {
            // Have to stop the webserver, or else its non-daemon threads
            // will hang forever.
            webServer.stop();
            throw new IOException("Unable to initialize WebAppContext", unavailableException);
        }
    } catch (IOException e) {
        throw e;
    } catch (InterruptedException e) {
        throw (IOException) new InterruptedIOException("Interrupted while starting HTTP server").initCause(e);
    } catch (Exception e) {
        throw new IOException("Problem starting http server", e);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Handler(org.eclipse.jetty.server.Handler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) MultiException(org.eclipse.jetty.util.MultiException) ServletException(javax.servlet.ServletException) MultiException(org.eclipse.jetty.util.MultiException) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) InterruptedIOException(java.io.InterruptedIOException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) IOException(java.io.IOException)

Aggregations

MultiException (org.eclipse.jetty.util.MultiException)18 IOException (java.io.IOException)14 ServletException (javax.servlet.ServletException)7 FileNotFoundException (java.io.FileNotFoundException)4 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)4 InputStream (java.io.InputStream)3 MalformedURLException (java.net.MalformedURLException)3 JarInputStream (java.util.jar.JarInputStream)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 JarEntry (java.util.jar.JarEntry)2 UnavailableException (javax.servlet.UnavailableException)2 Handler (org.eclipse.jetty.server.Handler)2 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)2 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)2 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)2