io.undertow.Undertow类的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(363)

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

Undertow介绍

[英]Convenience class used to build an Undertow server.
[中]方便类用于构建一个底层服务器。

代码示例

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

private void createServer() {
  logger.log(Level.FINE, "Locked to build server...");
  OAuthTokenInterceptor extractingHttpHandler = new ExtractingTokenInterceptor(ioQueue);
  IPAddressAccessControlHandler ipAddressAccessControlHandler = new IPAddressAccessControlHandler();
  ipAddressAccessControlHandler.setDefaultAllow(false);
  for (InetAddress inetAddress : allowedClients) {
    ipAddressAccessControlHandler.addAllow(inetAddress.getHostAddress());
  }
  server = Undertow.builder()
          .addHttpListener(port, "localhost")
          .setHandler(ipAddressAccessControlHandler)
          .setHandler(Handlers.path()
                          .addExactPath(createPath(extractingHttpHandler.getPathPrefix()), extractingHttpHandler)
                          .addExactPath(createPath(interceptor.getPathPrefix()), interceptor)
          )
          .build();
  logger.log(Level.INFO, "Starting token web listener...");
  server.start();
}

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

private void stopSilently() {
  try {
    if (this.undertow != null) {
      this.undertow.stop();
    }
  }
  catch (Exception ex) {
    // Ignore
  }
}

代码示例来源:origin: openzipkin/brave

protected int initServer() throws Exception {
 DeploymentInfo servletBuilder = Servlets.deployment()
   .setClassLoader(getClass().getClassLoader())
   .setContextPath("/")
   .setDeploymentName("test.war");
 init(servletBuilder);
 DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
 manager.deploy();
 server = Undertow.builder()
   .addHttpListener(0, "127.0.0.1")
   .setHandler(manager.start()).build();
 server.start();
 return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void start() throws Exception {
  this.server.start();
  Undertow.ListenerInfo info = this.server.getListenerInfo().get(0);
  this.port = ((InetSocketAddress) info.getAddress()).getPort();
}

代码示例来源:origin: jooby-project/jooby

@Inject
public UndertowServer(final org.jooby.spi.HttpHandler dispatcher, final Config conf,
  final Provider<SSLContext> sslContext) throws Exception {
 awaitShutdown = conf.getDuration("undertow.awaitShutdown", TimeUnit.MILLISECONDS);
 boolean http2 = conf.getBoolean("server.http2.enabled");
 shutdown = new GracefulShutdownHandler(doHandler(dispatcher, conf));
 Undertow.Builder ubuilder = configure(conf, io.undertow.Undertow.builder())
   .addHttpListener(conf.getInt("application.port"),
     host(conf.getString("application.host")));
 ubuilder.setServerOption(UndertowOptions.ENABLE_HTTP2, http2);
 boolean securePort = conf.hasPath("application.securePort");
 if (securePort) {
  ubuilder.addHttpsListener(conf.getInt("application.securePort"),
    host(conf.getString("application.host")), sslContext.get());
 }
 this.server = ubuilder.setHandler(shutdown)
   .build();
}

代码示例来源:origin: jooby-project/jooby

@Override
public void start() throws Exception {
 server.start();
}

代码示例来源:origin: openzipkin/brave

int getPort() {
  return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
 }
}

代码示例来源:origin: openzipkin/brave

@Override protected int initServer() {
 server = (PortExposing) new PortExposing()
   .deploy(App.class)
   .start(Undertow.builder().addHttpListener(8888, "127.0.0.1"));
 return server.getPort();
}

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

public void start() throws ServiceAlreadyStartedException {
  webServer.start();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void startInternal() {
  this.server.start();
  Undertow.ListenerInfo info = this.server.getListenerInfo().get(0);
  setPort(((InetSocketAddress) info.getAddress()).getPort());
}

代码示例来源:origin: noboomu/proteus

public void healthy()
{
  startupDuration = Duration.ofMillis(System.currentTimeMillis() - startTime);
  for(ListenerInfo info : undertow.getListenerInfo())
  {
    log.debug("listener info: " + info);
    SocketAddress address = info.getAddress();
    
    if(address != null)
    { 
      ports.add( ((java.net.InetSocketAddress) address).getPort());
    }
  }
  printStatus();
  
  running.set(true); 
}

代码示例来源:origin: networknt/light-4j

static private boolean bind(HttpHandler handler, int port) {
  try {
    Undertow.Builder builder = Undertow.builder();
    if (config.enableHttps) {
      port = port < 0 ? config.getHttpsPort() : port;
      sslContext = createSSLContext();
      builder.addHttpsListener(port, config.getIp(), sslContext);
    } else if (config.enableHttp) {
      port = port < 0 ? config.getHttpPort() : port;
      builder.addHttpListener(port, config.getIp());
    } else {
      throw new RuntimeException(
      builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true);
        .setHandler(Handlers.header(handler, Headers.SERVER_STRING, "L")).setWorkerThreads(200).build();
    server.start();
    System.out.println("HOST IP " + System.getenv(STATUS_HOST_IP));

代码示例来源:origin: networknt/light-4j

static public void stop() {
  if (server != null)
    server.stop();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected void initServer() throws Exception {
  this.server = Undertow.builder().addHttpListener(getPort(), getHost())
      .setHandler(initHttpHandlerAdapter())
      .build();
}

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

this.undertow = this.builder.build();
this.undertow.start();
this.started = true;
logger.info("Undertow started on port(s) " + getPortsDescription());

代码示例来源:origin: openzipkin/brave

@Setup(Level.Trial) public void init() throws Exception {
 server = Undertow.builder()
   .addHttpListener(0, "127.0.0.1")
   .setHandler(exchange -> {
    exchange.getResponseHeaders().put(CONTENT_TYPE, "text/plain; charset=UTF-8");
    exchange.getResponseSender().send("hello world");
   }).build();
 server.start();
 baseUrl = "http://127.0.0.1:" +
   ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort();
 client = newClient();
 tracedClient = newClient(HttpTracing.create(
   Tracing.newBuilder().spanReporter(Reporter.NOOP).build()
 ));
 unsampledClient = newClient(HttpTracing.create(
   Tracing.newBuilder().sampler(Sampler.NEVER_SAMPLE).spanReporter(Reporter.NOOP).build()
 ));
}

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

public Undertow start() {
  Undertow undertow = undertowBuilder.build();
  undertow.start();
  /*
   *  Undertow logs this on debug but we generally set 3rd party
   *  default logger levels to info so we log it here. If it wasn't using the
   *  io.undertow context we could turn on just that logger but no big deal.
   */
  undertow.getListenerInfo()
      .stream()
      .forEach(listenerInfo -> logger.info(listenerInfo.toString()));
  return undertow;
}

代码示例来源:origin: resteasy/Resteasy

public UndertowJaxrsServer start()
{
 server = Undertow.builder()
     .addHttpListener(PortProvider.getPort(), "localhost")
     .setHandler(root)
     .build();
 server.start();
 return this;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void stop() throws Exception {
  this.server.stop();
  this.port = 0;
}

代码示例来源:origin: spring-projects/spring-framework

this.manager.deploy();
HttpHandler httpHandler = this.manager.start();
this.server = Undertow.builder().addHttpListener(0, "localhost").setHandler(httpHandler).build();

相关文章