Java Code Examples for org.eclipse.jetty.server.Server#setRequestLog()

The following examples show how to use org.eclipse.jetty.server.Server#setRequestLog() . 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: KafkaCruiseControlApp.java    From cruise-control with BSD 2-Clause "Simplified" License 5 votes vote down vote up
KafkaCruiseControlApp(KafkaCruiseControlConfig config, Integer port, String hostname) throws ServletException {
  this._config = config;

  MetricRegistry metricRegistry = new MetricRegistry();
  _jmxReporter = JmxReporter.forRegistry(metricRegistry).inDomain(METRIC_DOMAIN).build();
  _jmxReporter.start();

  _kafkaCruiseControl = new AsyncKafkaCruiseControl(config, metricRegistry);

  _server = new Server();
  NCSARequestLog requestLog = createRequestLog();
  if (requestLog != null) {
    _server.setRequestLog(requestLog);
  }
  _server.setConnectors(new Connector[]{ setupHttpConnector(hostname, port) });

  ServletContextHandler contextHandler = createContextHandler();
  maybeSetSecurityHandler(contextHandler);
  _server.setHandler(contextHandler);

  setupWebUi(contextHandler);

  KafkaCruiseControlServlet servlet = new KafkaCruiseControlServlet(_kafkaCruiseControl, metricRegistry);
  String apiUrlPrefix = config.getString(WebServerConfig.WEBSERVER_API_URLPREFIX_CONFIG);
  ServletHolder servletHolder = new ServletHolder(servlet);
  contextHandler.addServlet(servletHolder, apiUrlPrefix);
}
 
Example 2
Source File: MockHttpApiRule.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws Exception {
  handler = new MockHandler();
  server = new Server();
  final ServerConnector http = new ServerConnector(server);
  http.setHost("localhost");
  server.addConnector(http);
  server.setStopAtShutdown(true);
  server.setHandler(handler);
  server.setRequestLog(buildRequestLog());
  server.start();
}
 
Example 3
Source File: JettyHttpServer.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Inject
public JettyHttpServer(
        final CurrentContainer container,
        final Metric metric,
        final ServerConfig serverConfig,
        final ServletPathsConfig servletPathsConfig,
        final ThreadFactory threadFactory,
        final FilterBindings filterBindings,
        final ComponentRegistry<ConnectorFactory> connectorFactories,
        final ComponentRegistry<ServletHolder> servletHolders,
        final FilterInvoker filterInvoker,
        final AccessLog accessLog) {
    super(container);
    if (connectorFactories.allComponents().isEmpty())
        throw new IllegalArgumentException("No connectors configured.");
    this.metric = metric;

    initializeJettyLogging();

    server = new Server();
    server.setStopTimeout((long)(serverConfig.stopTimeout() * 1000.0));
    server.setRequestLog(new AccessLogRequestLog(accessLog));
    setupJmx(server, serverConfig);
    ((QueuedThreadPool)server.getThreadPool()).setMaxThreads(serverConfig.maxWorkerThreads());

    for (ConnectorFactory connectorFactory : connectorFactories.allComponents()) {
        ConnectorConfig connectorConfig = connectorFactory.getConnectorConfig();
        server.addConnector(connectorFactory.createConnector(metric, server));
        listenedPorts.add(connectorConfig.listenPort());
    }

    janitor = newJanitor(threadFactory);

    JDiscContext jDiscContext = new JDiscContext(
            filterBindings.getRequestFilters().activate(),
            filterBindings.getResponseFilters().activate(),
            container,
            janitor,
            metric,
            serverConfig);

    ServletHolder jdiscServlet = new ServletHolder(new JDiscHttpServlet(jDiscContext));
    FilterHolder jDiscFilterInvokerFilter = new FilterHolder(new JDiscFilterInvokerFilter(jDiscContext, filterInvoker));

    List<JDiscServerConnector> connectors = Arrays.stream(server.getConnectors())
            .map(JDiscServerConnector.class::cast)
            .collect(toList());

    server.setHandler(
            getHandlerCollection(
                    serverConfig,
                    servletPathsConfig,
                    connectors,
                    jdiscServlet,
                    servletHolders,
                    jDiscFilterInvokerFilter));

    int numMetricReporterThreads = 1;
    metricReporterExecutor = Executors.newScheduledThreadPool(
            numMetricReporterThreads,
            new ThreadFactoryBuilder()
                    .setDaemon(true)
                    .setNameFormat(JettyHttpServer.class.getName() + "-MetricReporter-%d")
                    .setThreadFactory(threadFactory)
                    .build()
    );
    metricReporterExecutor.scheduleAtFixedRate(new MetricTask(), 0, 2, TimeUnit.SECONDS);
}
 
Example 4
Source File: JettyServiceBuilder.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a newly-created {@link JettyService} based on the properties of this builder.
 */
public JettyService build() {
    final JettyServiceConfig config = new JettyServiceConfig(
            hostname, dumpAfterStart, dumpBeforeStop, stopTimeoutMillis, handler, requestLog,
            sessionIdManagerFactory, attrs, beans, handlerWrappers, eventListeners, lifeCycleListeners,
            configurators);

    final Function<ScheduledExecutorService, Server> serverFactory = blockingTaskExecutor -> {
        final Server server = new Server(new ArmeriaThreadPool(blockingTaskExecutor));

        if (config.dumpAfterStart() != null) {
            server.setDumpAfterStart(config.dumpAfterStart());
        }
        if (config.dumpBeforeStop() != null) {
            server.setDumpBeforeStop(config.dumpBeforeStop());
        }
        if (config.stopTimeoutMillis() != null) {
            server.setStopTimeout(config.stopTimeoutMillis());
        }

        if (config.handler() != null) {
            server.setHandler(config.handler());
        }
        if (config.requestLog() != null) {
            server.setRequestLog(requestLog);
        }
        if (config.sessionIdManagerFactory() != null) {
            server.setSessionIdManager(config.sessionIdManagerFactory().apply(server));
        }

        config.handlerWrappers().forEach(server::insertHandler);
        config.attrs().forEach(server::setAttribute);
        config.beans().forEach(bean -> {
            final Boolean managed = bean.isManaged();
            if (managed == null) {
                server.addBean(bean.bean());
            } else {
                server.addBean(bean.bean(), managed);
            }
        });

        config.eventListeners().forEach(server::addEventListener);
        config.lifeCycleListeners().forEach(server::addLifeCycleListener);

        config.configurators().forEach(c -> c.accept(server));

        return server;
    };

    final Consumer<Server> postStopTask = server -> {
        try {
            JettyService.logger.info("Destroying an embedded Jetty: {}", server);
            server.destroy();
        } catch (Exception e) {
            JettyService.logger.warn("Failed to destroy an embedded Jetty: {}", server, e);
        }
    };

    return new JettyService(config.hostname(), serverFactory, postStopTask);
}