org.glassfish.grizzly.http.server.HttpServer.start()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(104)

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

HttpServer.start介绍

[英]Starts the HttpServer.
[中]

代码示例

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

public static void main(String[] args) {
    try {
      System.out.println("\"JAX-RS 2.1 Server-Sent Events\" Jersey Example App");

      final ResourceConfig resourceConfig = new ResourceConfig(JaxRsServerSentEventsResource.class);

      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
      Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
      server.start();

      System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C",
          BASE_URI, ROOT_PATH));

      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("JSON with JAXB Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.%nStop the application using CTRL+C"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("JSON with MOXy Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.%nStop the application using CTRL+C"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("JSON with Jackson Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.%nStop the application using CTRL+C"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(final String[] args) {
  try {
    System.out.println("JSON with Jackson Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.%nStop the application using CTRL+C"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
    try {
      System.out.println("\"Hello World\" Jersey Example App");

      ResourceConfig resourceConfig = new ResourceConfig(HelloWorldResource.class, CounterResource.class);
      HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
      Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));

      server.start();

      System.out.println("Application started.\nTry out");
      System.out.println(String.format("%s%s", BASE_URI, ROOT_HELLO_PATH));
      System.out.println(String.format("%s%s%s", BASE_URI, ROOT_COUNTER_PATH, "/request"));
      System.out.println(String.format("%s%s%s", BASE_URI, ROOT_COUNTER_PATH, "/application"));
      System.out.println("Stop the application using CTRL+C");

      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("JAXB Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(
        String.format("Application started.%nTry out %s%nStop the application using CTRL+C", BASE_URI));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("XML with MOXy Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp());
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.%nTry out %s%nStop the application using CTRL+C",
        BASE_URI + "/customer"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("Jersey HTTP PATCH Support Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.\nTry out %s/%s\nStop the application using CTRL+C",
        BASE_URI,
        ROOT_PATH));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("JSONP Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(
        String.format("Application started.%nTry out %s%s%nStop the application using CTRL+C", BASE_URI, ROOT_PATH));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
    try {
      System.out.println("\"Server-Sent Events\" Jersey Example App");

      final ResourceConfig resourceConfig = new ResourceConfig(ServerSentEventsResource.class, SseFeature.class);

      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
          server.shutdownNow();
        }
      }));
      server.start();

      System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C",
          BASE_URI, ROOT_PATH));

      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("System Properties Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, createApp(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(
        String.format("Application started.%n"
            + "Try out %s%n"
            + "Stop the application using CTRL+C",
            BASE_URI + "/properties"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
  try {
    System.out.println("\"Custom Executor Managed Async Resources\" Jersey Example App");
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, create(), false);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
        server.shutdownNow();
      }
    }));
    server.start();
    System.out.println(String.format("Application started.\n"
        + "To test long-running asynchronous operation resource, try %s%s\n"
        + "To test async chat resource, try %s%s\n"
        + "Stop the application using CTRL+C", BASE_URI, ASYNC_LONG_RUNNING_MANAGED_OP_PATH, BASE_URI, "chat"));
    Thread.currentThread().join();
  } catch (IOException | InterruptedException ex) {
    Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
  }
}

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

public static void main(String[] args) {
    try {
      System.out.println("\"Hello World\" Jersey Example App");

      final ResourceConfig resourceConfig = new ResourceConfig(HelloWorldResource.class);
      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, resourceConfig, false);
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
          server.shutdownNow();
        }
      }));
      server.start();

      System.out.println(String.format("Application started.\nTry out %s%s\nStop the application using CTRL+C",
          BASE_URI, ROOT_PATH));
      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }

  }
}

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

public static void main(String[] args) {
    try {
      System.out.println("Simple Console Jersey Example App");

      final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), createApp(), false);
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
          server.shutdownNow();
        }
      }));
      server.start();

      System.out.println(
          String.format("Application started.%nTry out %s%nStop the application using CTRL+C", BASE_URI + "/form"));

      Thread.currentThread().join();
    } catch (IOException | InterruptedException ex) {
      Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
}

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

@Override
public void start() {
  if (server.isStarted()) {
    LOGGER.log(Level.WARNING, "Ignoring start request - GrizzlyTestContainer is already started.");
  } else {
    LOGGER.log(Level.FINE, "Starting GrizzlyTestContainer...");
    try {
      server.start();
      if (baseUri.getPort() == 0) {
        baseUri = UriBuilder.fromUri(baseUri)
            .port(server.getListener("grizzly").getPort())
            .build();
        LOGGER.log(Level.INFO, "Started GrizzlyTestContainer at the base URI " + baseUri);
      }
    } catch (final IOException ioe) {
      throw new TestContainerException(ioe);
    }
  }
}

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

@Override
public void start() {
  if (server.isStarted()) {
    LOGGER.log(Level.WARNING, "Ignoring start request - GrizzlyWebTestContainer is already started.");
  } else {
    LOGGER.log(Level.FINE, "Starting GrizzlyWebTestContainer...");
    try {
      server.start();
      if (baseUri.getPort() == 0) {
        baseUri = UriBuilder.fromUri(baseUri)
            .port(server.getListener("grizzly").getPort())
            .build();
        LOGGER.log(Level.INFO, "Started GrizzlyWebTestContainer at the base URI " + baseUri);
      }
    } catch (final IOException ioe) {
      throw new TestContainerException(ioe);
    }
  }
}

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

public static void main(String[] args) throws Exception {
    System.out.println("Jersey performance test web service application");

    final String jaxRsApp = args.length > 0 ? args[0] : null;
    //noinspection unchecked
    final ResourceConfig resourceConfig = ResourceConfig
        .forApplicationClass((Class<? extends Application>) Class.forName(jaxRsApp));
    URI baseUri = args.length > 1 ? URI.create(args[1]) : BASE_URI;
    int selectors = args.length > 2 ? Integer.parseInt(args[2]) : DEFAULT_SELECTORS;
    int workers = args.length > 3 ? Integer.parseInt(args[3]) : DEFAULT_WORKERS;
    final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    final TCPNIOTransport transport = server.getListener("grizzly").getTransport();
    transport.setSelectorRunnersCount(selectors);
    transport.setWorkerThreadPoolConfig(ThreadPoolConfig.defaultConfig().setCorePoolSize(workers).setMaxPoolSize(workers));

    server.start();

    System.out.println(String.format("Application started.\nTry out %s\nHit Ctrl-C to stop it...",
        baseUri));

    while (server.isStarted()) {
      Thread.sleep(600000);
    }
  }
}

代码示例来源:origin: hierynomus/sshj

@Override
protected void before() throws Throwable {
  docRoot.create();
  httpServer = org.glassfish.grizzly.http.server.HttpServer.createSimpleServer(docRoot.getRoot().getAbsolutePath());
  httpServer.start();
}

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

@BeforeClass
public static void setup() throws IOException {
 httpServer = GrizzlyHttpServerFactory.createHttpServer(
   SERVER_URI,
   createResourceConfig(),
   false);
 httpServer.start();
 client = ClientBuilder.newBuilder()
   .register(GsonMessageBodyProvider.class)
   .register(PURE_GSON_TEXT_PLAIN)
   .build();
}

相关文章