Search in sources :

Example 11 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project hbase by apache.

the class HttpServer method initializeWebServer.

private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws FileNotFoundException, IOException {
    Preconditions.checkNotNull(webAppContext);
    HandlerCollection handlerCollection = new HandlerCollection();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLog requestLog = HttpRequestLog.getRequestLog(name);
    if (requestLog != null) {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        requestLogHandler.setRequestLog(requestLog);
        handlerCollection.addHandler(requestLogHandler);
    }
    final String appDir = getWebAppsPath(name);
    handlerCollection.addHandler(contexts);
    handlerCollection.addHandler(webAppContext);
    webServer.setHandler(handlerCollection);
    addDefaultApps(contexts, appDir, conf);
    addGlobalFilter("safety", QuotingInputFilter.class.getName(), null);
    Map<String, String> params = new HashMap<>();
    params.put("xframeoptions", conf.get("hbase.http.filter.xframeoptions.mode", "DENY"));
    addGlobalFilter("clickjackingprevention", ClickjackingPreventionFilter.class.getName(), params);
    final FilterInitializer[] initializers = getFilterInitializers(conf);
    if (initializers != null) {
        conf = new Configuration(conf);
        conf.set(BIND_ADDRESS, hostName);
        for (FilterInitializer c : initializers) {
            c.initFilter(this, conf);
        }
    }
    addDefaultServlets();
    if (pathSpecs != null) {
        for (String path : pathSpecs) {
            LOG.info("adding path spec: " + path);
            addFilterPathMapping(path, webAppContext);
        }
    }
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog) Configuration(org.apache.hadoop.conf.Configuration) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HashMap(java.util.HashMap) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 12 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project hadoop by apache.

the class TestHttpRequestLog method testAppenderUndefined.

@Test
public void testAppenderUndefined() {
    RequestLog requestLog = HttpRequestLog.getRequestLog("test");
    assertNull("RequestLog should be null", requestLog);
}
Also used : NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) Test(org.junit.Test)

Example 13 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project athenz by yahoo.

the class AthenzJettyContainerTest method testSlf4jRequestLogHandler.

@Test
public void testSlf4jRequestLogHandler() {
    System.setProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER, "AthenzAccessLogger");
    AthenzJettyContainer container = new AthenzJettyContainer();
    container.createServer(100);
    container.addRequestLogHandler();
    // now retrieve the request log handler
    Handler[] handlers = container.getHandlers().getHandlers();
    RequestLogHandler logHandler = null;
    for (Handler handler : handlers) {
        if (handler instanceof RequestLogHandler) {
            logHandler = (RequestLogHandler) handler;
            break;
        }
    }
    assertNotNull(logHandler);
    RequestLog reqLog = logHandler.getRequestLog();
    assertNotNull(reqLog);
    assertEquals(reqLog.getClass(), Slf4jRequestLog.class);
    assertEquals(((Slf4jRequestLog) reqLog).getLoggerName(), "AthenzAccessLogger");
    System.clearProperty(AthenzConsts.ATHENZ_PROP_ACCESS_SLF4J_LOGGER);
}
Also used : RequestLog(org.eclipse.jetty.server.RequestLog) AthenzRequestLog(com.yahoo.athenz.container.log.AthenzRequestLog) Slf4jRequestLog(org.eclipse.jetty.server.Slf4jRequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) Test(org.testng.annotations.Test)

Example 14 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project felix by apache.

the class RequestLogTrackerTest method testInvokeRequestLog.

@Test
public void testInvokeRequestLog() throws Exception {
    RequestLogTracker tracker = new RequestLogTracker(context, null);
    RequestLog mockRequestLog = mock(RequestLog.class);
    ServiceReference<RequestLog> mockSvcRef = mock(ServiceReference.class);
    when(context.getService(mockSvcRef)).thenReturn(mockRequestLog);
    // These invocations not passed through to the mock because it is not registered yet
    for (int i = 0; i < 10; i++) tracker.log(null, null);
    tracker.addingService(mockSvcRef);
    // These will pass through
    for (int i = 0; i < 15; i++) tracker.log(null, null);
    tracker.removedService(mockSvcRef, mockRequestLog);
    // And these will not.
    for (int i = 0; i < 50; i++) tracker.log(null, null);
    verify(mockRequestLog, times(15)).log(isNull(Request.class), isNull(Response.class));
}
Also used : Response(org.eclipse.jetty.server.Response) RequestLog(org.eclipse.jetty.server.RequestLog) Request(org.eclipse.jetty.server.Request) Test(org.junit.Test)

Example 15 with RequestLog

use of org.eclipse.jetty.server.RequestLog in project felix by apache.

the class RequestLogTrackerTest method testNaughtyService.

@Test
public void testNaughtyService() throws Exception {
    RequestLogTracker tracker = new RequestLogTracker(context, null);
    AtomicInteger counter = new AtomicInteger(0);
    RequestLog mockRequestLog = new RequestLog() {

        @Override
        public void log(Request request, Response response) {
            counter.addAndGet(1);
            throw new RuntimeException("This service always explodes");
        }
    };
    ServiceReference<RequestLog> mockSvcRef = mock(ServiceReference.class);
    Bundle mockBundle = mock(Bundle.class);
    when(mockSvcRef.getBundle()).thenReturn(mockBundle);
    when(mockBundle.getSymbolicName()).thenReturn("org.example");
    when(mockBundle.getVersion()).thenReturn(new Version("1.0.0"));
    when(context.getService(mockSvcRef)).thenReturn(mockRequestLog);
    tracker.addingService(mockSvcRef);
    // Invoke 200 times
    for (int i = 0; i < 200; i++) tracker.log(null, null);
    tracker.removedService(mockSvcRef, mockRequestLog);
    // Invoked 100 times and then removed
    assertEquals(100, counter.get());
}
Also used : Response(org.eclipse.jetty.server.Response) RequestLog(org.eclipse.jetty.server.RequestLog) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.eclipse.jetty.server.Request) Test(org.junit.Test)

Aggregations

RequestLog (org.eclipse.jetty.server.RequestLog)18 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)8 Test (org.junit.Test)6 NCSARequestLog (org.eclipse.jetty.server.NCSARequestLog)5 Request (org.eclipse.jetty.server.Request)3 Response (org.eclipse.jetty.server.Response)3 AthenzRequestLog (com.yahoo.athenz.container.log.AthenzRequestLog)2 HashMap (java.util.HashMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 CustomRequestLog (org.eclipse.jetty.server.CustomRequestLog)2 Handler (org.eclipse.jetty.server.Handler)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 IAccessEvent (ch.qos.logback.access.spi.IAccessEvent)1 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 Context (ch.qos.logback.core.Context)1 CoreConstants (ch.qos.logback.core.CoreConstants)1 PatternLayoutBase (ch.qos.logback.core.pattern.PatternLayoutBase)1 AppenderAttachableImpl (ch.qos.logback.core.spi.AppenderAttachableImpl)1