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; }
CLStaticHttpHandler staticHandler = new CLStaticHttpHandler(GrizzlyServer.class.getClassLoader(), "/client/"); if (params.disableFileCache) { LOG.info("Disabling HTTP server static file cache."); staticHandler.setFileCacheEnabled(false);
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive) { if (isFileCacheEnabled()) { final FilterChainContext fcContext = req.getContext(); final FileCacheFilter fileCacheFilter = lookupFileCache(fcContext); if (fileCacheFilter != null) { final FileCache fileCache = fileCacheFilter.getFileCache(); if (fileCache.isEnabled()) { if (res != null) { addCachingHeaders(res, archive); } fileCache.add(req.getRequest(), archive.lastModified()); return true; } } } return false; }
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive) { if (isFileCacheEnabled()) { final FilterChainContext fcContext = req.getContext(); final FileCacheFilter fileCacheFilter = lookupFileCache(fcContext); if (fileCacheFilter != null) { final FileCache fileCache = fileCacheFilter.getFileCache(); if (fileCache.isEnabled()) { if (res != null) { addCachingHeaders(res, archive); } fileCache.add(req.getRequest(), archive.lastModified()); return true; } } } return false; }
ClassLoader loader = Main.class.getClassLoader(); CLStaticHttpHandler docsHandler = new CLStaticHttpHandler(loader, "swagger/"); docsHandler.setFileCacheEnabled(false); ServerConfiguration cfg = server.getServerConfiguration() cfg.addHttpHandler(docsHandler, "/docs/");
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive) { if (isFileCacheEnabled()) { final FilterChainContext fcContext = req.getContext(); final FileCacheFilter fileCacheFilter = lookupFileCache(fcContext); if (fileCacheFilter != null) { final FileCache fileCache = fileCacheFilter.getFileCache(); if (fileCache.isEnabled()) { if (res != null) { addCachingHeaders(res, archive); } fileCache.add(req.getRequest(), archive.lastModified()); return true; } } } return false; }
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/"); }
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive) { if (isFileCacheEnabled()) { final FilterChainContext fcContext = req.getContext(); final FileCacheFilter fileCacheFilter = lookupFileCache(fcContext); if (fileCacheFilter != null) { final FileCache fileCache = fileCacheFilter.getFileCache(); if (fileCache.isEnabled()) { if (res != null) { addCachingHeaders(res, archive); } fileCache.add(req.getRequest(), archive.lastModified()); return true; } } } return false; }
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/"); }
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive) { if (isFileCacheEnabled()) { final FilterChainContext fcContext = req.getContext(); final FileCacheFilter fileCacheFilter = lookupFileCache(fcContext); if (fileCacheFilter != null) { final FileCache fileCache = fileCacheFilter.getFileCache(); if (fileCache.isEnabled()) { if (res != null) { addCachingHeaders(res, archive); } fileCache.add(req.getRequest(), archive.lastModified()); return true; } } } return false; }
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/"); }
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :
private boolean addTimeStampEntryToFileCache(final Request req, final Response res, final File archive) { if (isFileCacheEnabled()) { final FilterChainContext fcContext = req.getContext(); final FileCacheFilter fileCacheFilter = lookupFileCache(fcContext); if (fileCacheFilter != null) { final FileCache fileCache = fileCacheFilter.getFileCache(); if (fileCache.isEnabled()) { if (res != null) { addCachingHeaders(res, archive); } fileCache.add(req.getRequest(), archive.lastModified()); return true; } } } return false; }
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; }
URL url = lookupResource(resourcePath); url = lookupResource(resourcePath + "/index.html"); mayBeFolder = false; found = true; } else { closeJarFileIfNeeded(jarUrlConnection, jarFile); pickupContentType(response, filePath != null ? filePath : url.getPath()); addToFileCache(request, response, fileResource); sendFile(response, fileResource); } else { assert urlConnection != null; final File jarFile = getJarFile( ); addTimeStampEntryToFileCache(request, response, jarFile); sendResource(response, urlInputStream != null ? urlInputStream :