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; }
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/"); }
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/"); }
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/"); }
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; }
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; }
CLStaticHttpHandler staticHandler = new CLStaticHttpHandler(GrizzlyServer.class.getClassLoader(), "/client/"); if (params.disableFileCache) { LOG.info("Disabling HTTP server static file cache.");
StaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(YourApp.class.getClassLoader()); server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
httpServer.getServerConfiguration().addHttpHandler( new CLStaticHttpHandler(new URLClassLoader(new URL[] {new URL("file:///home/username/staticfiles.jar")})), "/www");
StaticHttpHandler staticHttpHandler = new CLStaticHttpHandler(new URLClassLoader(new URL[] {new URL("file:///www/static.jar")})); server.getServerConfiguration().addHttpHandler(staticHttpHandler, "/");
server.getServerConfiguration().addHttpHandler( new CLStaticHttpHandler(new URLClassLoader(new URL[] { new File("/home/myname/myjarfile.jar").toURI().toURL()}), // Path to the jar file "my/jar/staticfiles-insider-jar/"), // the static files path inside the jar file "/jarstatic"); // context-path
ClassLoader loader = Main.class.getClassLoader(); CLStaticHttpHandler docsHandler = new CLStaticHttpHandler(loader, "swagger/"); docsHandler.setFileCacheEnabled(false); ServerConfiguration cfg = server.getServerConfiguration() cfg.addHttpHandler(docsHandler, "/docs/");
/** * add a httphandler at the given path * * @param context * - document root or classpath * @param path * @param staticHandler */ public void addHttpHandler(String context, String path, boolean staticHandler) { HttpHandler handler = null; String type = ""; if (staticHandler) { handler = new StaticHttpHandler(context); type = "static"; } else { handler = new CLStaticHttpHandler(this.getClass().getClassLoader(), context); type = "classpath"; } if (!path.endsWith("/")) { path += "/"; } LOGGER.log(Level.INFO, "adding " + type + " httphandler " + context + "->" + path); httpServer.getServerConfiguration().addHttpHandler(handler, path); }
server.addListener(new NetworkListener("transport_network_visualizer", INTERFACE, PORT)); server.getServerConfiguration().addHttpHandler(new TransportNetworkHandler(network), "/api/*"); server.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(ClassLoader.getSystemClassLoader(), "/visualization/")); try { server.start();
server.addListener(new NetworkListener("transport_network_visualizer", INTERFACE, PORT)); server.getServerConfiguration().addHttpHandler(new TransportNetworkHandler(network), "/api/*"); server.getServerConfiguration().addHttpHandler(new CLStaticHttpHandler(ClassLoader.getSystemClassLoader(), "/visualization/")); try { server.start();
new CLStaticHttpHandler(new URLClassLoader(new URL[] { new File("target/jersey1-grizzly2-spring-1.0-SNAPSHOT.jar").toURI().toURL()}), "webapp/static2/"), "/jarstatic");
CLStaticHttpHandler webjarsHandler = new CLStaticHttpHandler(loader, "META-INF/resources/webjars/"); httpServer.getServerConfiguration().addHttpHandler(webjarsHandler, "/webjars/"); httpServer.start();