Search in sources :

Example 1 with RequestLog

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

the class AsyncServletTest method setUp.

@Before
public void setUp() throws Exception {
    _connector = new ServerConnector(_server);
    _server.setConnectors(new Connector[] { _connector });
    _log = new ArrayList<>();
    RequestLog log = new Log();
    RequestLogHandler logHandler = new RequestLogHandler();
    logHandler.setRequestLog(log);
    _server.setHandler(logHandler);
    _expectedLogs = 1;
    _expectedCode = "200 ";
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/ctx");
    logHandler.setHandler(context);
    context.addEventListener(new DebugListener());
    _errorHandler = new ErrorPageErrorHandler();
    context.setErrorHandler(_errorHandler);
    _errorHandler.addErrorPage(300, 599, "/error/custom");
    _servletHandler = context.getServletHandler();
    ServletHolder holder = new ServletHolder(_servlet);
    holder.setAsyncSupported(true);
    _servletHandler.addServletWithMapping(holder, "/error/*");
    _servletHandler.addServletWithMapping(holder, "/path/*");
    _servletHandler.addServletWithMapping(holder, "/path1/*");
    _servletHandler.addServletWithMapping(holder, "/path2/*");
    _servletHandler.addServletWithMapping(holder, "/p th3/*");
    _servletHandler.addServletWithMapping(new ServletHolder(new FwdServlet()), "/fwd/*");
    ServletHolder holder2 = new ServletHolder("NoAsync", _servlet);
    holder2.setAsyncSupported(false);
    _servletHandler.addServletWithMapping(holder2, "/noasync/*");
    _server.start();
    _port = _connector.getLocalPort();
    __history.clear();
    __latch = new CountDownLatch(1);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) RequestLog(org.eclipse.jetty.server.RequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) DebugListener(org.eclipse.jetty.server.DebugListener) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 2 with RequestLog

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

the class TestHttpRequestLog method testAppenderUndefined.

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

Example 3 with RequestLog

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

the class TestHttpRequestLog method testAppenderDefined.

@Test
public void testAppenderDefined() {
    HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender();
    requestLogAppender.setName("testrequestlog");
    Logger.getLogger("http.requests.test").addAppender(requestLogAppender);
    RequestLog requestLog = HttpRequestLog.getRequestLog("test");
    Logger.getLogger("http.requests.test").removeAppender(requestLogAppender);
    assertNotNull("RequestLog should not be null", requestLog);
    assertEquals("Class mismatch", NCSARequestLog.class, requestLog.getClass());
}
Also used : NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) Test(org.junit.Test)

Example 4 with RequestLog

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

the class HttpRequestLog method getRequestLog.

public static RequestLog getRequestLog(String name) {
    String lookup = serverToComponent.get(name);
    if (lookup != null) {
        name = lookup;
    }
    String loggerName = "http.requests." + name;
    String appenderName = name + "requestlog";
    Log logger = LogFactory.getLog(loggerName);
    boolean isLog4JLogger;
    ;
    try {
        isLog4JLogger = logger instanceof Log4JLogger;
    } catch (NoClassDefFoundError err) {
        // In some dependent projects, log4j may not even be on the classpath at
        // runtime, in which case the above instanceof check will throw
        // NoClassDefFoundError.
        LOG.debug("Could not load Log4JLogger class", err);
        isLog4JLogger = false;
    }
    if (isLog4JLogger) {
        Log4JLogger httpLog4JLog = (Log4JLogger) logger;
        Logger httpLogger = httpLog4JLog.getLogger();
        Appender appender = null;
        try {
            appender = httpLogger.getAppender(appenderName);
        } catch (LogConfigurationException e) {
            LOG.warn("Http request log for " + loggerName + " could not be created");
            throw e;
        }
        if (appender == null) {
            LOG.info("Http request log for " + loggerName + " is not defined");
            return null;
        }
        if (appender instanceof HttpRequestLogAppender) {
            HttpRequestLogAppender requestLogAppender = (HttpRequestLogAppender) appender;
            NCSARequestLog requestLog = new NCSARequestLog();
            requestLog.setFilename(requestLogAppender.getFilename());
            requestLog.setRetainDays(requestLogAppender.getRetainDays());
            return requestLog;
        } else {
            LOG.warn("Jetty request log for " + loggerName + " was of the wrong class");
            return null;
        }
    } else {
        LOG.warn("Jetty request log can only be enabled using Log4j");
        return null;
    }
}
Also used : Appender(org.apache.log4j.Appender) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) RequestLog(org.eclipse.jetty.server.RequestLog) Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) LogConfigurationException(org.apache.commons.logging.LogConfigurationException) Logger(org.apache.log4j.Logger) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger)

Example 5 with RequestLog

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

the class HttpServer2 method initializeWebServer.

private void initializeWebServer(String name, String hostName, Configuration conf, String[] pathSpecs) throws IOException {
    Preconditions.checkNotNull(webAppContext);
    int maxThreads = conf.getInt(HTTP_MAX_THREADS_KEY, -1);
    // If HTTP_MAX_THREADS is not configured, QueueThreadPool() will use the
    // default value (currently 250).
    QueuedThreadPool threadPool = (QueuedThreadPool) webServer.getThreadPool();
    threadPool.setDaemon(true);
    if (maxThreads != -1) {
        threadPool.setMaxThreads(maxThreads);
    }
    SessionManager sm = webAppContext.getSessionHandler().getSessionManager();
    if (sm instanceof AbstractSessionManager) {
        AbstractSessionManager asm = (AbstractSessionManager) sm;
        asm.setHttpOnly(true);
        asm.getSessionCookieConfig().setSecure(true);
    }
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    RequestLog requestLog = HttpRequestLog.getRequestLog(name);
    handlers.addHandler(contexts);
    if (requestLog != null) {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        requestLogHandler.setRequestLog(requestLog);
        handlers.addHandler(requestLogHandler);
    }
    handlers.addHandler(webAppContext);
    final String appDir = getWebAppsPath(name);
    addDefaultApps(contexts, appDir, conf);
    webServer.setHandler(handlers);
    Map<String, String> xFrameParams = new HashMap<>();
    xFrameParams.put(X_FRAME_ENABLED, String.valueOf(this.xFrameOptionIsEnabled));
    xFrameParams.put(X_FRAME_VALUE, this.xFrameOption.toString());
    addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
    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 : Configuration(org.apache.hadoop.conf.Configuration) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HashMap(java.util.HashMap) SessionManager(org.eclipse.jetty.server.SessionManager) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) AuthenticationFilterInitializer(org.apache.hadoop.security.AuthenticationFilterInitializer) RequestLog(org.eclipse.jetty.server.RequestLog) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) AbstractSessionManager(org.eclipse.jetty.server.session.AbstractSessionManager)

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 StatisticsHandler (org.eclipse.jetty.server.handler.StatisticsHandler)3 AthenzRequestLog (com.yahoo.athenz.container.log.AthenzRequestLog)2 HashMap (java.util.HashMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 RewriteHandler (org.eclipse.jetty.rewrite.handler.RewriteHandler)2 CustomRequestLog (org.eclipse.jetty.server.CustomRequestLog)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