Refine search
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; }
final HttpServer server = new HttpServer(); server.addListener(listener); final ServerConfiguration config = server.getServerConfiguration(); if (handler != null) { final String path = uri.getPath().replaceAll("/{2,}", "/"); config.addHttpHandler(handler, HttpHandlerRegistration.bulder().contextPath(contextPath).build()); config.setPassTraceRequest(true); config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);
shutdownFuture = null; configureAuxThreadPool(); configureListener(listener); if (serverConfig.isJmxEnabled()) { enableJMX(); setupHttpHandler(); if (serverConfig.isJmxEnabled()) { for (final JmxEventListener l : serverConfig.getJmxEventListeners()) { l.jmxEnabled(); LOGGER.log(Level.INFO, "[{0}] Started.", getServerConfiguration().getName());
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; }
URI uri = new URI("http://0.0.0.0:8080/"); HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri); ServerConfiguration config = server.getServerConfiguration(); config.addHttpHandler(handler, "/"); server.start(); System.in.read();
if (serverConfig.isJmxEnabled()) { for (final JmxEventListener l : serverConfig.getJmxEventListeners()) { l.jmxDisabled(); tearDownHttpHandler(); removeListener(name); delayedExecutor = null; stopAuxThreadPool(); if (serverConfig.isJmxEnabled()) { disableJMX();
listener.getMaxResponseHeaders()); final Set<ContentEncoding> contentEncodings = configureCompressionEncodings(listener); for (ContentEncoding contentEncoding : contentEncodings) { httpServerCodecFilter.addContentEncoding(contentEncoding); serverConfig.isAllowPayloadForUndefinedHttpMethods()); httpServerCodecFilter.setMaxPayloadRemainderToSkip( serverConfig.getMaxPayloadRemainderToSkip()); serverConfig.getMonitoringConfig().getHttpConfig().getProbes()); builder.add(httpServerCodecFilter); final FileCacheFilter fileCacheFilter = new FileCacheFilter(fileCache); fileCache.getMonitoringConfig().addProbes( serverConfig.getMonitoringConfig().getFileCacheConfig().getProbes()); builder.add(fileCacheFilter); serverConfig.getMonitoringConfig().getWebServerConfig().getProbes()); configureMonitoring(listener);
/** * Adds the specified {@link HttpHandler} as a root handler. * * @param httpHandler a {@link HttpHandler} */ public void addHttpHandler(final HttpHandler httpHandler) { addHttpHandler(httpHandler, ROOT_MAPPING); }
protected void enableJMX() { if (jmxManager == null) { synchronized (serverConfig) { if (jmxManager == null) { jmxManager= GrizzlyJmxManager.instance(); } } } jmxManager.registerAtRoot(getManagementObject(false), serverConfig.getName()); }
/** * Build an {@link AccessLogProbe} instance and directly instrument it in an * {@link HttpServer}'s {@linkplain HttpServerMonitoringConfig monitoring * configuration} to provide access logging. * * @param serverConfiguration The {@link ServerConfiguration} to instrument. */ public ServerConfiguration instrument(ServerConfiguration serverConfiguration) { serverConfiguration.getMonitoringConfig() .getWebServerConfig() .addProbes(build()); return serverConfiguration; }
private void setupHttpHandler() { serverConfig.addJmxEventListener(httpHandlerChain); synchronized (serverConfig.handlersSync) { for (final HttpHandler httpHandler : serverConfig.orderedHandlers) { httpHandlerChain.addHandler(httpHandler, serverConfig.handlers.get(httpHandler)); } } httpHandlerChain.start(); }
@Override public Thread newThread(Runnable r) { final Thread newThread = new DefaultWorkerThread( AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER, serverConfig.getName() + "-" + threadCounter.getAndIncrement(), null, r); newThread.setDaemon(true); return newThread; } });
shutdownFuture = null; configureAuxThreadPool(); configureListener(listener); if (serverConfig.isJmxEnabled()) { enableJMX(); setupHttpHandler(); if (serverConfig.isJmxEnabled()) { for (final JmxEventListener l : serverConfig.getJmxEventListeners()) { l.jmxEnabled(); LOGGER.log(Level.INFO, "[{0}] Started.", getServerConfiguration().getName());
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/"); }
if (serverConfig.isJmxEnabled()) { for (final JmxEventListener l : serverConfig.getJmxEventListeners()) { l.jmxDisabled(); tearDownHttpHandler(); removeListener(name); delayedExecutor = null; stopAuxThreadPool(); if (serverConfig.isJmxEnabled()) { disableJMX();
listener.getMaxResponseHeaders()); final Set<ContentEncoding> contentEncodings = configureCompressionEncodings(listener); for (ContentEncoding contentEncoding : contentEncodings) { httpServerCodecFilter.addContentEncoding(contentEncoding); serverConfig.isAllowPayloadForUndefinedHttpMethods()); httpServerCodecFilter.setMaxPayloadRemainderToSkip( serverConfig.getMaxPayloadRemainderToSkip()); serverConfig.getMonitoringConfig().getHttpConfig().getProbes()); builder.add(httpServerCodecFilter); final FileCacheFilter fileCacheFilter = new FileCacheFilter(fileCache); fileCache.getMonitoringConfig().addProbes( serverConfig.getMonitoringConfig().getFileCacheConfig().getProbes()); builder.add(fileCacheFilter); serverConfig.getMonitoringConfig().getWebServerConfig().getProbes()); configureMonitoring(listener);
/** * Adds the specified {@link HttpHandler} as a root handler. * * @param httpHandler a {@link HttpHandler} */ public void addHttpHandler(final HttpHandler httpHandler) { addHttpHandler(httpHandler, ROOT_MAPPING); }
protected void enableJMX() { if (jmxManager == null) { synchronized (serverConfig) { if (jmxManager == null) { jmxManager= GrizzlyJmxManager.instance(); } } } jmxManager.registerAtRoot(getManagementObject(false), serverConfig.getName()); }
/** * Build an {@link AccessLogProbe} instance and directly instrument it in an * {@link HttpServer}'s {@linkplain HttpServerMonitoringConfig monitoring * configuration} to provide access logging. * * @param serverConfiguration The {@link ServerConfiguration} to instrument. */ public ServerConfiguration instrument(ServerConfiguration serverConfiguration) { serverConfiguration.getMonitoringConfig() .getWebServerConfig() .addProbes(build()); return serverConfiguration; }
private void setupHttpHandler() { serverConfig.addJmxEventListener(httpHandlerChain); synchronized (serverConfig.handlersSync) { for (final HttpHandler httpHandler : serverConfig.orderedHandlers) { httpHandlerChain.addHandler(httpHandler, serverConfig.handlers.get(httpHandler)); } } httpHandlerChain.start(); }