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

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

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

HttpServer.getServerConfiguration介绍

暂无

代码示例

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

public boolean start(int httpPort) {
 // ideally greater than reserved port but then port 80 is also valid
 Preconditions.checkArgument(httpPort > 0);
 baseUri = URI.create("http://0.0.0.0:" + Integer.toString(httpPort) + "/");
 httpServer = GrizzlyHttpServerFactory.createHttpServer(baseUri, this);
 setupSwagger(httpServer);
 ClassLoader classLoader = ControllerAdminApiApplication.class.getClassLoader();
 // This is ugly from typical patterns to setup static resources but all our APIs are
 // at path "/". So, configuring static handler for path "/" does not work well.
 // Configuring this as a default servlet is an option but that is still ugly if we evolve
 // So, we setup specific handlers for static resource directory. index.html is served directly
 // by a jersey handler
 httpServer.getServerConfiguration()
   .addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/query/"), "/query/");
 httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/css/"), "/css/");
 httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/js/"), "/js/");
 // without this explicit request to /index.html will not work
 httpServer.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(classLoader, "/static/"), "/index.html");
 started = true;
 LOGGER.info("Start jersey admin API on port: {}", httpPort);
 return true;
}

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

private void setupSwagger(HttpServer httpServer) {
 BeanConfig beanConfig = new BeanConfig();
 beanConfig.setTitle("Pinot Server API");
 beanConfig.setDescription("APIs for accessing Pinot server information");
 beanConfig.setContact("https://github.com/apache/incubator-pinot");
 beanConfig.setVersion("1.0");
 beanConfig.setSchemes(new String[]{"http"});
 beanConfig.setBasePath(baseUri.getPath());
 beanConfig.setResourcePackage(RESOURCE_PACKAGE);
 beanConfig.setScan(true);
 CLStaticHttpHandler staticHttpHandler =
   new CLStaticHttpHandler(AdminApiApplication.class.getClassLoader(), "/api/");
 // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
 httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/api/");
 httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/help/");
 URL swaggerDistLocation =
   AdminApiApplication.class.getClassLoader().getResource("META-INF/resources/webjars/swagger-ui/2.2.2/");
 CLStaticHttpHandler swaggerDist = new CLStaticHttpHandler(new URLClassLoader(new URL[]{swaggerDistLocation}));
 httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
}

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

private void setupSwagger() {
 BeanConfig beanConfig = new BeanConfig();
 beanConfig.setTitle("Pinot Broker API");
 beanConfig.setDescription("APIs for accessing Pinot broker information");
 beanConfig.setContact("https://github.com/apache/incubator-pinot");
 beanConfig.setVersion("1.0");
 beanConfig.setSchemes(new String[]{"http"});
 beanConfig.setBasePath(_baseUri.getPath());
 beanConfig.setResourcePackage(RESOURCE_PACKAGE);
 beanConfig.setScan(true);
 HttpHandler httpHandler = new CLStaticHttpHandler(BrokerAdminApiApplication.class.getClassLoader(), "/api/");
 // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
 _httpServer.getServerConfiguration().addHttpHandler(httpHandler, "/api/", "/help/");
 URL swaggerDistLocation =
   BrokerAdminApiApplication.class.getClassLoader().getResource("META-INF/resources/webjars/swagger-ui/2.2.2/");
 CLStaticHttpHandler swaggerDist = new CLStaticHttpHandler(new URLClassLoader(new URL[]{swaggerDistLocation}));
 _httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
}

代码示例来源:origin: aol/micro-server

private void addAccessLog(HttpServer httpServer) {
  try {
    String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation();
    accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log";
    final AccessLogBuilder builder = new AccessLogBuilder(accessLogLocation);
    builder.rotatedDaily();
    builder.rotationPattern("yyyy-MM-dd");
    builder.instrument(httpServer.getServerConfiguration());
  } catch (Exception e) {
    logger.error(InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getMessage());
    if (e.getCause() != null)
      logger.error("CAUSED BY: " + InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getCause().getMessage());
  }
}

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

private void setupSwagger(HttpServer httpServer) {
 BeanConfig beanConfig = new BeanConfig();
 beanConfig.setTitle("Pinot Controller API");
 beanConfig.setDescription("APIs for accessing Pinot Controller information");
 beanConfig.setContact("https://github.com/apache/incubator-pinot");
 beanConfig.setVersion("1.0");
 if (_useHttps) {
  beanConfig.setSchemes(new String[]{"https"});
 } else {
  beanConfig.setSchemes(new String[]{"http"});
 }
 beanConfig.setBasePath(baseUri.getPath());
 beanConfig.setResourcePackage(RESOURCE_PACKAGE);
 beanConfig.setScan(true);
 ClassLoader loader = this.getClass().getClassLoader();
 CLStaticHttpHandler apiStaticHttpHandler = new CLStaticHttpHandler(loader, "/api/");
 // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
 httpServer.getServerConfiguration().addHttpHandler(apiStaticHttpHandler, "/api/");
 httpServer.getServerConfiguration().addHttpHandler(apiStaticHttpHandler, "/help/");
 URL swaggerDistLocation = loader.getResource("META-INF/resources/webjars/swagger-ui/2.2.2/");
 CLStaticHttpHandler swaggerDist = new CLStaticHttpHandler(new URLClassLoader(new URL[]{swaggerDistLocation}));
 httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

public void run() {
  int port = config.getProperty("port") != null ? Integer.parseInt(config.getProperty("port")) : DEFAULT_PORT;
  String addr = config.getProperty("bind-address") != null ? config.getProperty("bind-address") : DEFAULT_BIND_ADDRESS;
  LOG.info("Starting analyst broker on port {} of interface {}", port, addr);
  HttpServer httpServer = new HttpServer();
  NetworkListener networkListener = new NetworkListener("broker", addr, port);
  // We avoid blocking IO, and the following line allows us to see closed connections.
  networkListener.getTransport().setIOStrategy(SameThreadIOStrategy.getInstance());
  httpServer.addListener(networkListener);
  // Bypass Jersey etc. and add a low-level Grizzly handler.
  // As in servlets, * is needed in base path to identify the "rest" of the path.
  broker = new Broker(config, addr, port);
  httpServer.getServerConfiguration().addHttpHandler(new BrokerHttpHandler(broker), "/*");
  try {
    httpServer.start();
    LOG.info("Broker running.");
    broker.run(); // run queue broker task pump in this thread
    Thread.currentThread().join();
  } catch (BindException be) {
    LOG.error("Cannot bind to port {}. Is it already in use?", port);
  } catch (IOException ioe) {
    LOG.error("IO exception while starting server.");
  } catch (InterruptedException ie) {
    LOG.info("Interrupted, shutting down.");
  }
  httpServer.shutdown();
}

代码示例来源:origin: stackoverflow.com

URI uri = new URI("http://0.0.0.0:8080/");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri);
ServerConfiguration config = server.getServerConfiguration();
config.addHttpHandler(handler, "/");

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

public static HttpServer startServer(String webRootPath) {
  final HttpServer server = new HttpServer();
  Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    @Override
    public void run() {
      server.shutdownNow();
    }
  }));
  final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
  server.addListener(listener);
  final ServerConfiguration config = server.getServerConfiguration();
  // add handler for serving static content
  config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH);
  // add handler for serving JAX-RS resources
  config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class),
      APP_PATH);
  try {
    // Start the server.
    server.start();
  } catch (Exception ex) {
    throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
  }
  return server;
}

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

public static HttpServer startServer(String webRootPath) {
  final HttpServer server = new HttpServer();
  Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
    @Override
    public void run() {
      server.shutdownNow();
    }
  }));
  final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
  server.addListener(listener);
  final ServerConfiguration config = server.getServerConfiguration();
  // add handler for serving static content
  config.addHttpHandler(new CLStaticHttpHandler(Main.class.getClassLoader(), WEB_ROOT), APP_PATH);
  // add handler for serving JAX-RS resources
  config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class),
      APP_PATH);
  try {
    // Start the server.
    server.start();
  } catch (Exception ex) {
    throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
  }
  return server;
}

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

/**
 * Starts Grizzly HTTP server exposing static content, JAX-RS resources
 * and web sockets defined in this application.
 *
 * @param webRootPath static content root path.
 */
private static void startServer(String webRootPath) {
  final HttpServer server = new HttpServer();
  Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
  final NetworkListener listener = new NetworkListener("grizzly", "localhost", PORT);
  server.addListener(listener);
  final ServerConfiguration config = server.getServerConfiguration();
  // add handler for serving static content
  config.addHttpHandler(new StaticContentHandler(webRootPath),
      APP_PATH);
  // add handler for serving JAX-RS resources
  config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(createResourceConfig(), GrizzlyHttpContainer.class),
      API_PATH);
  try {
    // Start the server.
    server.start();
  } catch (Exception ex) {
    throw new ProcessingException("Exception thrown when trying to start grizzly server", ex);
  }
}

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

final ServerConfiguration config = server.getServerConfiguration();
if (handler != null) {
  final String path = uri.getPath().replaceAll("/{2,}", "/");

代码示例来源:origin: opentripplanner/OpenTripPlanner

httpServer.getServerConfiguration().addHttpHandler(dynamicHandler, "/otp/");
  staticHandler.setFileCacheEnabled(false);
httpServer.getServerConfiguration().addHttpHandler(staticHandler, "/");
      params.clientDirectory.getAbsolutePath());
  localHandler.setFileCacheEnabled(false);
  httpServer.getServerConfiguration().addHttpHandler(localHandler, "/local");

代码示例来源:origin: javaee/grizzly

/**
 *
 * @param server
 */
private void destoryServlets(HttpServer server) {
  if (servletHandlers != null && !servletHandlers.isEmpty()) {
    ServerConfiguration config = server.getServerConfiguration();
    for (final ServletHandler handler : servletHandlers) {
      config.removeHttpHandler(handler);
    }
  }
}

代码示例来源:origin: javaee/grizzly

/**
 *
 * @param server
 */
private void destoryServlets(HttpServer server) {
  if (servletHandlers != null && !servletHandlers.isEmpty()) {
    ServerConfiguration config = server.getServerConfiguration();
    for (final ServletHandler handler : servletHandlers) {
      config.removeHttpHandler(handler);
    }
  }
}

代码示例来源:origin: javaee/grizzly

/**
 *
 * @param server
 */
private void destoryServlets(HttpServer server) {
  if (servletHandlers != null && !servletHandlers.isEmpty()) {
    ServerConfiguration config = server.getServerConfiguration();
    for (final ServletHandler handler : servletHandlers) {
      config.removeHttpHandler(handler);
    }
  }
}

代码示例来源:origin: stackoverflow.com

ResourceConfig rc = new ResourceConfig();
rc.packages("com.danny.resources");
rc.registerInstances(new StatusModule(useFake), new NetworkModule(useFake));
GrizzlyHttpContainer resourceConfigContainer = ContainerFactory
  .createContainer(GrizzlyHttpContainer.class, rc);
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri);
server.getServerConfiguration().addHttpHandler(resourceConfigContainer, "/");

代码示例来源:origin: org.immutables/service

@Override
protected void startUp() throws Exception {
 httpServer = GrizzlyHttpServerFactory.createHttpServer(
   uri, createResourceConfig(), false);
 httpServer.getServerConfiguration().setDefaultErrorPageGenerator(ERROR_PAGE_GENERATOR);
 httpServer.start();
}

代码示例来源:origin: javaee/grizzly

private CometHttpHandler addHttpHandler(String alias, boolean resume) {
  final CometHttpHandler c = new CometHttpHandler(cometContext, resume);
  httpServer.getServerConfiguration().addHttpHandler(c, alias);
  return c;
}

代码示例来源:origin: sismics/reader

/**
 * Add a handler for temporaty files.
 *
 * Server Java temporary files on /temp
 */
private void addTempFileHandler() {
  StaticHttpHandler staticHttpHandler = new StaticHttpHandler(System.getProperty("java.io.tmpdir"));
  staticHttpHandler.setFileCacheEnabled(false);
  httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/temp");
}

代码示例来源:origin: javaee/grizzly

private void startServer(HttpHandler httpHandler) throws IOException {
  httpServer = new HttpServer();
  NetworkListener networkListener = new NetworkListener("jaxws-listener", "0.0.0.0", PORT);
  
  httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler(), "/add"); // make sure JAX-WS Handler is not default
  httpServer.getServerConfiguration().addHttpHandler(httpHandler,
      HttpHandlerRegistration.bulder()
        .contextPath("/add/a/b")
        .urlPattern("/")
        .build());
  httpServer.addListener(networkListener);
  
  httpServer.start();        
}

相关文章