org.eclipse.jetty.server.Server.addBean()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(237)

本文整理了Java中org.eclipse.jetty.server.Server.addBean()方法的一些代码示例,展示了Server.addBean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server.addBean()方法的具体详情如下:
包路径:org.eclipse.jetty.server.Server
类名称:Server
方法名:addBean

Server.addBean介绍

[英]Add an associated bean. The bean will be added to the servers Containerand if it is a LifeCycle instance, it will be started/stopped along with the Server. Any beans that are also Destroyable, will be destroyed with the server.
[中]添加一个关联的bean。bean将被添加到servers容器中,如果它是一个生命周期实例,它将与服务器一起启动/停止。任何也可以销毁的bean都将随服务器一起销毁。

代码示例

代码示例来源:origin: dropwizard/dropwizard

private List<Connector> buildAdminConnectors(MetricRegistry metricRegistry, Server server) {
  // threadpool is shared between all the connectors, so it should be managed by the server instead of the
  // individual connectors
  final QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(metricRegistry, adminMaxThreads, adminMinThreads);
  threadPool.setName("dw-admin");
  server.addBean(threadPool);
  final List<Connector> connectors = new ArrayList<>();
  for (ConnectorFactory factory : adminConnectors) {
    final Connector connector = factory.build(server, metricRegistry, "admin", threadPool);
    if (connector instanceof ContainerLifeCycle) {
      ((ContainerLifeCycle) connector).unmanage(threadPool);
    }
    connectors.add(connector);
  }
  return connectors;
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldSetErrorHandlerForServer() throws Exception {
  jetty9Server.configure();
  verify(server).addBean(any(JettyCustomErrorPageHandler.class));
}

代码示例来源:origin: org.springframework.boot/spring-boot

private void initialize() {
  synchronized (this.monitor) {
    try {
      // Cache the connectors and then remove them to prevent requests being
      // handled before the application context is ready.
      this.connectors = this.server.getConnectors();
      this.server.addBean(new AbstractLifeCycle() {
        @Override
        protected void doStart() throws Exception {
          for (Connector connector : JettyWebServer.this.connectors) {
            Assert.state(connector.isStopped(), () -> "Connector "
                + connector + " has been started prematurely");
          }
          JettyWebServer.this.server.setConnectors(null);
        }
      });
      // Start the server so that the ServletContext is available
      this.server.start();
      this.server.setStopAtShutdown(false);
    }
    catch (Throwable ex) {
      // Ensure process isn't left running
      stopSilently();
      throw new WebServerException("Unable to start embedded Jetty web server",
          ex);
    }
  }
}

代码示例来源:origin: dropwizard/dropwizard

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
  final HttpConfiguration httpConfig = buildHttpConfiguration();
  final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
  final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory());
  sslContextFactory.addLifeCycleListener(logSslInfoOnStart(sslContextFactory));
  server.addBean(sslContextFactory);
  server.addBean(new SslReload(sslContextFactory, this::configureSslContextFactory));
  final SslConnectionFactory sslConnectionFactory =
      new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString());
  final Scheduler scheduler = new ScheduledExecutorScheduler();
  final ByteBufferPool bufferPool = buildBufferPool();
  return buildConnector(server, scheduler, bufferPool, name, threadPool,
             new Jetty93InstrumentedConnectionFactory(
                 sslConnectionFactory,
                 metrics.timer(httpConnections())),
                 httpConnectionFactory);
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

/** Get/Set/Create the server default Configuration ClassList.
 * <p>Get the class list from: a Server bean; or the attribute (which can
 * either be a ClassList instance or an String[] of class names); or a new instance
 * with default configuration classes.</p>
 * <p>This method also adds the obtained ClassList instance as a dependent bean
 * on the server and clears the attribute</p>
 * @param server The server the default is for
 * @return the server default ClassList instance of the configuration classes for this server. Changes to this list will change the server default instance.
 */
public static ClassList setServerDefault(Server server)
{
  ClassList cl=server.getBean(ClassList.class);
  if (cl!=null)
    return cl;
  cl=serverDefault(server);
  server.addBean(cl);
  server.setAttribute(ATTR,null);
  return cl;
}

代码示例来源:origin: line/armeria

final Boolean managed = bean.isManaged();
if (managed == null) {
  server.addBean(bean.bean());
} else {
  server.addBean(bean.bean(), managed);

代码示例来源:origin: apache/hive

/**
 * Secure the web server with PAM.
 */
void setupPam(Builder b, Handler handler) {
 LoginService loginService = new PamLoginService();
 webServer.addBean(loginService);
 ConstraintSecurityHandler security = new ConstraintSecurityHandler();
 Constraint constraint = new PamConstraint();
 ConstraintMapping mapping = new PamConstraintMapping(constraint);
 security.setConstraintMappings(Collections.singletonList(mapping));
 security.setAuthenticator(b.pamAuthenticator);
 security.setLoginService(loginService);
 security.setHandler(handler);
 webServer.setHandler(security);
}

代码示例来源:origin: dropwizard/dropwizard

protected Server buildServer(LifecycleEnvironment lifecycle,
               ThreadPool threadPool) {
  final Server server = new Server(threadPool);
  server.addLifeCycleListener(buildSetUIDListener());
  lifecycle.attach(server);
  final ErrorHandler errorHandler = new ErrorHandler();
  errorHandler.setServer(server);
  errorHandler.setShowStacks(false);
  server.addBean(errorHandler);
  server.setStopAtShutdown(true);
  server.setStopTimeout(shutdownGracePeriod.toMilliseconds());
  return server;
}

代码示例来源:origin: gocd/gocd

@Override
public void configure() throws Exception {
  server.addEventListener(mbeans());
  server.addConnector(plainConnector());
  server.addConnector(sslConnector());
  ContextHandlerCollection handlers = new ContextHandlerCollection();
  deploymentManager.setContexts(handlers);
  createWebAppContext();
  JettyCustomErrorPageHandler errorHandler = new JettyCustomErrorPageHandler();
  webAppContext.setErrorHandler(errorHandler);
  webAppContext.setGzipHandler(gzipHandler());
  server.addBean(errorHandler);
  server.addBean(deploymentManager);
  HandlerCollection serverLevelHandlers = new HandlerCollection();
  serverLevelHandlers.setHandlers(new Handler[]{handlers});
  server.setHandler(serverLevelHandlers);
  performCustomConfiguration();
  server.setStopAtShutdown(true);
}

代码示例来源:origin: dropwizard/dropwizard

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
  // HTTP/2 requires that a server MUST support TLSv1.2 and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher
  // See http://http2.github.io/http2-spec/index.html#rfc.section.9.2.2
  setSupportedProtocols(Collections.singletonList("TLSv1.2"));
  checkSupportedCipherSuites();
  // Setup connection factories
  final HttpConfiguration httpConfig = buildHttpConfiguration();
  final HttpConnectionFactory http1 = buildHttpConnectionFactory(httpConfig);
  final HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpConfig);
  http2.setMaxConcurrentStreams(maxConcurrentStreams);
  http2.setInitialStreamRecvWindow(initialStreamRecvWindow);
  final NegotiatingServerConnectionFactory alpn = new ALPNServerConnectionFactory(H2, H2_17);
  alpn.setDefaultProtocol(HTTP_1_1); // Speak HTTP 1.1 over TLS if negotiation fails
  final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory());
  sslContextFactory.addLifeCycleListener(logSslInfoOnStart(sslContextFactory));
  server.addBean(sslContextFactory);
  server.addBean(new SslReload(sslContextFactory, this::configureSslContextFactory));
  // We should use ALPN as a negotiation protocol. Old clients that don't support it will be served
  // via HTTPS. New clients, however, that want to use HTTP/2 will use TLS with ALPN extension.
  // If negotiation succeeds, the client and server switch to HTTP/2 protocol.
  final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, "alpn");
  return buildConnector(server, new ScheduledExecutorScheduler(), buildBufferPool(), name, threadPool,
      new Jetty93InstrumentedConnectionFactory(sslConnectionFactory, metrics.timer(httpConnections())),
      alpn, http2, http1);
}

代码示例来源:origin: apache/flume

srv.addBean(mbContainer);

代码示例来源:origin: dropwizard/dropwizard

protected Handler addRequestLog(Server server, Handler handler, String name) {
  if (getRequestLogFactory().isEnabled()) {
    final RequestLogHandler requestLogHandler = new RequestLogHandler();
    requestLogHandler.setRequestLog(getRequestLogFactory().build(name));
    // server should own the request log's lifecycle since it's already started,
    // the handler might not become managed in case of an error which would leave
    // the request log stranded
    server.addBean(requestLogHandler.getRequestLog(), true);
    requestLogHandler.setHandler(handler);
    return requestLogHandler;
  }
  return handler;
}

代码示例来源:origin: kairosdb/kairosdb

m_server.addBean(errorHandler);

代码示例来源:origin: Codecademy/EventHub

new Password(properties.getProperty("eventhubhandler.password")), new String[]{"user"});
server.addBean(loginService);

代码示例来源:origin: igniterealtime/Openfire

if (JMXManager.isEnabled()) {
  JMXManager jmx = JMXManager.getInstance();
  httpBindServer.addBean(jmx.getContainer());

代码示例来源:origin: apache/nifi

deploymentManager.setContextAttribute(CONTAINER_INCLUDE_PATTERN_KEY, CONTAINER_INCLUDE_PATTERN_VALUE);
deploymentManager.setContexts(contextHandlers);
server.addBean(deploymentManager);

代码示例来源:origin: apache/hive

webServer.addBean(low);

代码示例来源:origin: AsyncHttpClient/async-http-client

private static void addAuthHandler(Server server, String auth, LoginAuthenticator authenticator, Handler handler) {
 server.addBean(LOGIN_SERVICE);
 Constraint constraint = new Constraint();
 constraint.setName(auth);
 constraint.setRoles(new String[]{USER, ADMIN});
 constraint.setAuthenticate(true);
 ConstraintMapping mapping = new ConstraintMapping();
 mapping.setConstraint(constraint);
 mapping.setPathSpec("/*");
 Set<String> knownRoles = new HashSet<>();
 knownRoles.add(USER);
 knownRoles.add(ADMIN);
 List<ConstraintMapping> cm = new ArrayList<>();
 cm.add(mapping);
 ConstraintSecurityHandler security = new ConstraintSecurityHandler();
 security.setConstraintMappings(cm, knownRoles);
 security.setAuthenticator(authenticator);
 security.setLoginService(LOGIN_SERVICE);
 security.setHandler(handler);
 server.setHandler(security);
}

代码示例来源:origin: apache/incubator-druid

server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true);

代码示例来源:origin: apache/nifi

server.addBean(loginService);
securityHandler.setLoginService(loginService);

相关文章