org.eclipse.jetty.server.RequestLog Java Examples

The following examples show how to use org.eclipse.jetty.server.RequestLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyServiceConfig.java    From armeria with Apache License 2.0 6 votes vote down vote up
JettyServiceConfig(@Nullable String hostname,
                   @Nullable Boolean dumpAfterStart, @Nullable Boolean dumpBeforeStop,
                   @Nullable Long stopTimeoutMillis,
                   @Nullable Handler handler, @Nullable RequestLog requestLog,
                   @Nullable Function<? super Server, ? extends SessionIdManager> sessionIdManagerFactory,
                   Map<String, Object> attrs, List<Bean> beans, List<HandlerWrapper> handlerWrappers,
                   List<Listener> eventListeners, List<LifeCycle.Listener> lifeCycleListeners,
                   List<Consumer<? super Server>> configurators) {

    this.hostname = hostname;
    this.dumpAfterStart = dumpAfterStart;
    this.dumpBeforeStop = dumpBeforeStop;
    this.stopTimeoutMillis = stopTimeoutMillis;
    this.handler = handler;
    this.requestLog = requestLog;
    this.sessionIdManagerFactory = sessionIdManagerFactory;
    this.attrs = Collections.unmodifiableMap(attrs);
    this.beans = Collections.unmodifiableList(beans);
    this.handlerWrappers = Collections.unmodifiableList(handlerWrappers);
    this.eventListeners = Collections.unmodifiableList(eventListeners);
    this.lifeCycleListeners = Collections.unmodifiableList(lifeCycleListeners);
    this.configurators = Collections.unmodifiableList(configurators);
}
 
Example #2
Source File: JettyServiceConfig.java    From armeria with Apache License 2.0 6 votes vote down vote up
static String toString(
        Object holder, @Nullable String hostname, @Nullable Boolean dumpAfterStart,
        @Nullable Boolean dumpBeforeStop, @Nullable Long stopTimeout,
        @Nullable Handler handler, @Nullable RequestLog requestLog,
        @Nullable Function<? super Server, ? extends SessionIdManager> sessionIdManagerFactory,
        Map<String, Object> attrs, List<Bean> beans, List<HandlerWrapper> handlerWrappers,
        List<Listener> eventListeners, List<LifeCycle.Listener> lifeCycleListeners,
        List<Consumer<? super Server>> configurators) {

    return MoreObjects.toStringHelper(holder)
                      .add("hostname", hostname)
                      .add("dumpAfterStart", dumpAfterStart)
                      .add("dumpBeforeStop", dumpBeforeStop)
                      .add("stopTimeoutMillis", stopTimeout)
                      .add("handler", handler)
                      .add("requestLog", requestLog)
                      .add("sessionIdManagerFactory", sessionIdManagerFactory)
                      .add("attrs", attrs)
                      .add("beans", beans)
                      .add("handlerWrappers", handlerWrappers)
                      .add("eventListeners", eventListeners)
                      .add("lifeCycleListeners", lifeCycleListeners)
                      .add("configurators", configurators)
                      .toString();
}
 
Example #3
Source File: TestHttpRequestLog.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@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",
      CustomRequestLog.class, requestLog.getClass());
}
 
Example #4
Source File: HttpRequestLog.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static RequestLog getRequestLog(String name) {
  String lookup = SERVER_TO_COMPONENT.get(name);
  if (lookup != null) {
    name = lookup;
  }
  String loggerName = "http.requests." + name;
  Slf4jRequestLog logger = new Slf4jRequestLog();
  logger.setLoggerName(loggerName);
  return logger;
}
 
Example #5
Source File: ServerDaemon.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
private RequestLog createRequestLog() {
    final NCSARequestLog log = new NCSARequestLog();
    final File logPath = new File(accessLogFile);
    final File parentFile = logPath.getParentFile();
    if (parentFile != null) {
        parentFile.mkdirs();
    }
    log.setFilename(logPath.getPath());
    log.setAppend(true);
    log.setLogTimeZone("GMT");
    log.setLogLatency(true);
    return log;
}
 
Example #6
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
private void initializeWebServer(String name, String hostName,
    ConfigurationSource conf, String[] pathSpecs,
    String authFilterConfigPrefix,
    boolean securityEnabled) 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);
  }

  SessionHandler handler = webAppContext.getSessionHandler();
  handler.setHttpOnly(true);
  handler.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 = setHeaders(conf);
  addGlobalFilter("safety", QuotingInputFilter.class.getName(), xFrameParams);
  final FilterInitializer[] initializers = getFilterInitializers(conf);
  if (initializers != null) {
    conf.set(BIND_ADDRESS, hostName);
    org.apache.hadoop.conf.Configuration hadoopConf =
        LegacyHadoopConfigurationSource.asHadoopConfiguration(conf);
    Map<String, String> filterConfig = getFilterConfigMap(hadoopConf,
        authFilterConfigPrefix);
    for (FilterInitializer c : initializers) {
      if ((c instanceof AuthenticationFilterInitializer) && securityEnabled) {
        addFilter("authentication",
            AuthenticationFilter.class.getName(), filterConfig);
      } else {
        c.initFilter(this, hadoopConf);
      }
    }
  }

  addDefaultServlets();

  if (pathSpecs != null) {
    for (String path : pathSpecs) {
      LOG.info("adding path spec: {}", path);
      addFilterPathMapping(path, webAppContext);
    }
  }
}
 
Example #7
Source File: HttpRequestLog.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
public static RequestLog getRequestLog(String name) {

    String lookup = SERVER_TO_COMPONENT.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;
      org.apache.log4j.Logger httpLogger = httpLog4JLog.getLogger();
      Appender appender = null;

      try {
        appender = httpLogger.getAppender(appenderName);
      } catch (LogConfigurationException e) {
        LOG.warn("Http request log for {} could not be created", loggerName);
        throw e;
      }

      if (appender == null) {
        LOG.info("Http request log for {} is not defined", loggerName);
        return null;
      }

      if (appender instanceof HttpRequestLogAppender) {
        HttpRequestLogAppender requestLogAppender
            = (HttpRequestLogAppender) appender;
        AsyncRequestLogWriter logWriter = new AsyncRequestLogWriter();
        logWriter.setFilename(requestLogAppender.getFilename());
        logWriter.setRetainDays(requestLogAppender.getRetainDays());
        return new CustomRequestLog(logWriter,
            CustomRequestLog.EXTENDED_NCSA_FORMAT);
      } else {
        LOG.warn("Jetty request log for {} was of the wrong class", loggerName);
        return null;
      }
    } else {
      LOG.warn("Jetty request log can only be enabled using Log4j");
      return null;
    }
  }
 
Example #8
Source File: TestHttpRequestLog.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Test
public void testAppenderUndefined() {
  RequestLog requestLog = HttpRequestLog.getRequestLog("test");
  assertNull("RequestLog should be null", requestLog);
}
 
Example #9
Source File: JettyServiceConfig.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Nullable
RequestLog requestLog() {
    return requestLog;
}
 
Example #10
Source File: MockHttpApiRule.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static RequestLog buildRequestLog() {
  final Slf4jRequestLog requestLog = new Slf4jRequestLog();
  requestLog.setLoggerName(LOG.getName() + ".RequestLog");
  requestLog.setExtended(true);
  return requestLog;
}
 
Example #11
Source File: TestHttpRequestLog.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testAppenderDefined() {
  RequestLog requestLog = HttpRequestLog.getRequestLog("test");
  assertNotNull("RequestLog should not be null", requestLog);
  assertEquals("Class mismatch", Slf4jRequestLog.class, requestLog.getClass());
}