io.javalin.Javalin Java Examples
The following examples show how to use
io.javalin.Javalin.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReposiliteHttpServer.java From reposilite with Apache License 2.0 | 6 votes |
void start(Configuration configuration, Runnable onStart) { LookupService lookupService = new LookupService(reposilite); LookupController lookupController = new LookupController(reposilite.getFrontend(), lookupService); DeployController deployController = new DeployController(reposilite); this.javalin = Javalin.create(config -> config(configuration, config)) .get("/api/auth", new AuthApiController(configuration, reposilite.getAuthenticator())) .get("/api/configuration", new ConfigurationApiController(reposilite.getConfiguration())) .ws("/api/cli", new CliController(reposilite)) .get("/api/*", new IndexApiController(reposilite)) .get("/js/app.js", new FrontendController(reposilite)) .get("/*", lookupController) .head("/*", lookupController) .put("/*", deployController) .post("/*", deployController) .before(ctx -> reposilite.getStatsService().record(ctx.req.getRequestURI())) .exception(Exception.class, (exception, ctx) -> reposilite.throwException(ctx.req.getRequestURI(), exception)) .start(configuration.getHostname(), configuration.getPort()); onStart.run(); }
Example #2
Source File: Main.java From javalin-website-example with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // Instantiate your dependencies bookDao = new BookDao(); userDao = new UserDao(); Javalin app = Javalin.create(config -> { config.addStaticFiles("/public"); config.registerPlugin(new RouteOverviewPlugin("/routes")); }).start(HerokuUtil.getHerokuAssignedPort()); app.routes(() -> { before(Filters.handleLocaleChange); before(LoginController.ensureLoginBeforeViewingBooks); get(Path.Web.INDEX, IndexController.serveIndexPage); get(Path.Web.BOOKS, BookController.fetchAllBooks); get(Path.Web.ONE_BOOK, BookController.fetchOneBook); get(Path.Web.LOGIN, LoginController.serveLoginPage); post(Path.Web.LOGIN, LoginController.handleLoginPost); post(Path.Web.LOGOUT, LoginController.handleLogoutPost); }); app.error(404, ViewUtil.notFound); }
Example #3
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 6 votes |
public WorkerHandler(Javalin app, StatsLogger statsLogger) { this.localWorker = new LocalWorker(statsLogger); app.post("/initialize-driver", this::handleInitializeDriver); app.post("/create-topics", this::handleCreateTopics); app.post("/create-producers", this::handleCreateProducers); app.post("/probe-producers", this::handleProbeProducers); app.post("/create-consumers", this::handleCreateConsumers); app.post("/pause-consumers", this::handlePauseConsumers); app.post("/resume-consumers", this::handleResumeConsumers); app.post("/start-load", this::handleStartLoad); app.post("/adjust-publish-rate", this::handleAdjustPublishRate); app.post("/stop-all", this::handleStopAll); app.get("/period-stats", this::handlePeriodStats); app.get("/cumulative-latencies", this::handleCumulativeLatencies); app.get("/counters-stats", this::handleCountersStats); app.post("/reset-stats", this::handleResetStats); }
Example #4
Source File: FileSystemViewHandler.java From hudi with Apache License 2.0 | 5 votes |
public FileSystemViewHandler(Javalin app, Configuration conf, FileSystemViewManager viewManager) throws IOException { this.viewManager = viewManager; this.app = app; this.instantHandler = new TimelineHandler(conf, viewManager); this.sliceHandler = new FileSliceHandler(conf, viewManager); this.dataFileHandler = new BaseFileHandler(conf, viewManager); }
Example #5
Source File: BenchmarkWorker.java From openmessaging-benchmark with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { final Arguments arguments = new Arguments(); JCommander jc = new JCommander(arguments); jc.setProgramName("benchmark-worker"); try { jc.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); jc.usage(); System.exit(-1); } if (arguments.help) { jc.usage(); System.exit(-1); } Configuration conf = new CompositeConfiguration(); conf.setProperty(Stats.STATS_PROVIDER_CLASS, PrometheusMetricsProvider.class.getName()); conf.setProperty("prometheusStatsHttpPort", arguments.statsPort); Stats.loadStatsProvider(conf); StatsProvider provider = Stats.get(); provider.start(conf); Runtime.getRuntime().addShutdownHook(new Thread( () -> provider.stop(), "benchmark-worker-shutdown-thread")); // Dump configuration variables log.info("Starting benchmark with config: {}", writer.writeValueAsString(arguments)); // Start web server Javalin app = Javalin.start(arguments.httpPort); new WorkerHandler(app, provider.getStatsLogger("benchmark")); }
Example #6
Source File: PrometheusSample.java From micrometer with Apache License 2.0 | 5 votes |
@Override public void apply(@NonNull Javalin app) { Server server = app.server().server(); app.exception(Exception.class, EXCEPTION_HANDLER); server.insertHandler(new TimedHandler(registry, tags, new DefaultHttpServletRequestTagsProvider() { @Override public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response) { String exceptionName = response.getHeader(EXCEPTION_HEADER); response.setHeader(EXCEPTION_HEADER, null); String uri = app.servlet().getMatcher() .findEntries(HandlerType.valueOf(request.getMethod()), request.getPathInfo()) .stream() .findAny() .map(HandlerEntry::getPath) .map(path -> path.equals("/") || StringUtils.isBlank(path) ? "root" : path) .map(path -> response.getStatus() >= 300 && response.getStatus() < 400 ? "REDIRECTION" : path) .map(path -> response.getStatus() == 404 ? "NOT_FOUND" : path) .orElse("unknown"); return Tags.concat( super.getTags(request, response), "uri", uri, "exception", exceptionName == null ? "None" : exceptionName ); } })); new JettyServerThreadPoolMetrics(server.getThreadPool(), tags).bindTo(registry); new JettyConnectionMetrics(registry, tags); }
Example #7
Source File: DefaultReportsServer.java From maestro-java with Apache License 2.0 | 5 votes |
protected void registerUris(final Javalin app) { logger.warn("Registering reports server URIs"); app.get("/api/live", ctx -> ctx.result("Hello World")); // Common usage app.get("/api/report/", new AllReportsController()); // Common usage app.get("/api/report/aggregated", new AllAggregatedReportsController()); // For the report/node specific view app.get("/api/report/report/:id", new ReportController()); app.get("/api/report/report/:id/properties", new ReportPropertiesController()); app.get("/api/report/latency/all/report/:id", new LatencyReportController()); app.get("/api/report/latency/statistics/report/:id", new LatencyStatisticsReportController()); app.get("/api/report/rate/report/:id", new RateReportController()); app.get("/api/report/rate/statistics/report/:id", new RateStatisticsReportController()); // For all tests ... context needs to be adjusted app.get("/api/report/test/:test/number/:number/properties", new TestPropertiesController()); app.get("/api/report/test/:test/sut/node", new SutNodeInfoController()); // Aggregated app.get("/api/report/latency/aggregated/test/:id/number/:number", new AggregatedLatencyReportController()); app.get("/api/report/latency/aggregated/statistics/test/:id/number/:number", new AggregatedLatencyStatisticsReportController()); app.get("/api/report/rate/:role/aggregated/test/:id/number/:number", new AggregatedRateReportController()); app.get("/api/report/rate/:role/aggregated/statistics/test/:id/number/:number", new AggregatedRateStatisticsReportController()); app.get("/api/report/:id/files", new FileListController()); app.get("/raw/report/:id/files/:name", new RawFileController()); }
Example #8
Source File: TimelineService.java From hudi with Apache License 2.0 | 5 votes |
public int startService() throws IOException { app = Javalin.create(); FileSystemViewHandler router = new FileSystemViewHandler(app, conf, fsViewsManager); app.get("/", ctx -> ctx.result("Hello World")); router.register(); app.start(serverPort); // If port = 0, a dynamic port is assigned. Store it. serverPort = app.port(); LOG.info("Starting Timeline server on port :" + serverPort); return serverPort; }
Example #9
Source File: DefaultReportsServer.java From maestro-java with Apache License 2.0 | 5 votes |
protected void configure(final Javalin app) { final int port = config.getInteger("maestro.reports.server", 6500); app.port(port) .enableStaticFiles("/site") .enableCorsForAllOrigins() .disableStartupBanner(); }
Example #10
Source File: WdmServer.java From webdrivermanager with Apache License 2.0 | 5 votes |
public WdmServer(int port) { Javalin app = Javalin.create().start(port); Handler handler = this::handleRequest; app.get("/chromedriver", handler); app.get("/firefoxdriver", handler); app.get("/edgedriver", handler); app.get("/iedriver", handler); app.get("/operadriver", handler); app.get("/phantomjs", handler); app.get("/selenium-server-standalone", handler); log.info("WebDriverManager server listening on port {}", port); }
Example #11
Source File: BeaconRestApi.java From teku with Apache License 2.0 | 5 votes |
public BeaconRestApi(final DataProvider dataProvider, final TekuConfiguration configuration) { this.app = Javalin.create( config -> { config.registerPlugin( new OpenApiPlugin(getOpenApiOptions(jsonProvider, configuration))); config.defaultContentType = "application/json"; config.logIfServerNotStarted = false; config.showJavalinBanner = false; }); initialize(dataProvider, configuration); }
Example #12
Source File: RestHandler.java From openmessaging-connect-runtime with Apache License 2.0 | 5 votes |
public RestHandler(ConnectController connectController){ this.connectController = connectController; Javalin app = Javalin.start(connectController.getConnectConfig().getHttpPort()); app.get("/connectors/:connectorName", this::handleCreateConnector); app.get("/connectors/:connectorName/config", this::handleQueryConnectorConfig); app.get("/connectors/:connectorName/status", this::handleQueryConnectorStatus); app.get("/connectors/:connectorName/stop", this::handleStopConnector); app.get("/getClusterInfo", this::getClusterInfo); app.get("/getConfigInfo", this::getConfigInfo); app.get("/getAllocatedInfo", this::getAllocatedInfo); }
Example #13
Source File: ValidatorGui.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public static void start(CliContext currentContext, ValidationEngine validationEngine, boolean bootBrowser) { app = Javalin.create(); new RestEndpoints().initRestEndpoints(app, currentContext, validationEngine); app.config.addStaticFiles(WEB_APP_FILE_LOCATION); app.start(GUI_FRONTEND_PORT); if (bootBrowser) { openBrowser(); } }
Example #14
Source File: JavalinApp.java From tutorials with MIT License | 5 votes |
public static void main(String[] args) { Javalin app = Javalin.create() .port(7000) .start(); app.get("/hello", ctx -> ctx.html("Hello, Javalin!")); app.get("/users", UserController.fetchAllUsernames); app.get("/users/:id", UserController.fetchById); }
Example #15
Source File: BeakerXServerJavalin.java From beakerx with Apache License 2.0 | 5 votes |
private Javalin createServer(KernelFunctionality kernel) { this.freePort = MagicKernelManager.findFreePort(); Javalin server = Javalin.create() .disableStartupBanner() .port(this.freePort) .start(); doCreateMapping(server, kernel); return server; }
Example #16
Source File: ScalaBeakerXServer.java From beakerx with Apache License 2.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #17
Source File: BeakerXServerJavalin.java From beakerx with Apache License 2.0 | 4 votes |
private void doCreateMapping(Javalin server, KernelFunctionality kernel) { mappingsForAllKernels(server, kernel); createMapping(server, kernel); }
Example #18
Source File: JavaBeakerXServer.java From beakerx with Apache License 2.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #19
Source File: SymjaMMABeakerXServer.java From symja_android_library with GNU General Public License v3.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #20
Source File: GroovyBeakerXServer.java From beakerx with Apache License 2.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #21
Source File: SQLBeakerXServer.java From beakerx with Apache License 2.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #22
Source File: KotlinBeakerXServer.java From beakerx with Apache License 2.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #23
Source File: ClojureBeakerXServer.java From beakerx with Apache License 2.0 | 4 votes |
@Override public void createMapping(Javalin app, KernelFunctionality kernel) { }
Example #24
Source File: Endpoint.java From schedge with MIT License | 4 votes |
public final void addTo(Javalin app) { app.get(getPath(), OpenApiBuilder.documented(configureDocs(OpenApiBuilder.document()), getHandler())); }
Example #25
Source File: HoodieWithTimelineServer.java From hudi with Apache License 2.0 | 4 votes |
public void startService() { Javalin app = Javalin.create().start(cfg.serverPort); app.get("/", ctx -> ctx.result("Hello World")); }
Example #26
Source File: Server.java From selenium-jupiter with Apache License 2.0 | 4 votes |
public Server(int port) { Javalin app = Javalin.create().start(port); Config config = new Config(); AnnotationsReader annotationsReader = new AnnotationsReader(); InternalPreferences preferences = new InternalPreferences(config); Gson gson = new Gson(); final String[] hubUrl = new String[1]; final DockerDriverHandler[] dockerDriverHandler = new DockerDriverHandler[1]; String path = config.getServerPath(); final String serverPath = path.endsWith("/") ? path.substring(0, path.length() - 1) : path; final int timeoutSec = config.getServerTimeoutSec(); Handler handler = ctx -> { String requestMethod = ctx.method(); String requestPath = ctx.path(); String requestBody = ctx.body(); log.info("Server request: {} {}", requestMethod, requestPath); log.debug("body: {} ", requestBody); Session session = gson.fromJson(requestBody, Session.class); // POST /session if (session != null && session.getDesiredCapabilities() != null) { String browserName = session.getDesiredCapabilities() .getBrowserName(); String version = session.getDesiredCapabilities().getVersion(); BrowserType browserType = getBrowserType(browserName); BrowserInstance browserInstance = new BrowserInstance(config, annotationsReader, browserType, NONE, empty(), empty()); dockerDriverHandler[0] = new DockerDriverHandler(config, browserInstance, version, preferences); dockerDriverHandler[0].resolve(browserInstance, version, "", "", false); hubUrl[0] = dockerDriverHandler[0].getHubUrl().toString(); log.info("Hub URL {}", hubUrl[0]); } // exchange request-response String response = exchange( hubUrl[0] + requestPath.replace(serverPath, ""), requestMethod, requestBody, timeoutSec); log.info("Server response: {}", response); ctx.result(response); // DELETE /session/sessionId if (requestMethod.equalsIgnoreCase(DELETE) && requestPath.startsWith(serverPath + SESSION + "/")) { dockerDriverHandler[0].cleanup(); } }; app.post(serverPath + SESSION, handler); app.post(serverPath + SESSION + "/*", handler); app.get(serverPath + SESSION + "/*", handler); app.delete(serverPath + SESSION + "/*", handler); String serverUrl = String.format("http://localhost:%d%s", port, serverPath); log.info("Selenium-Jupiter server listening on {}", serverUrl); }
Example #27
Source File: PrometheusSample.java From micrometer with Apache License 2.0 | 4 votes |
public static void main(String[] args) { PrometheusMeterRegistry meterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT); // add any tags here that will apply to all metrics streaming from this app // (e.g. EC2 region, stack, instance id, server group) meterRegistry.config().commonTags("app", "javalin-sample"); new JvmGcMetrics().bindTo(meterRegistry); new JvmHeapPressureMetrics().bindTo(meterRegistry); new JvmMemoryMetrics().bindTo(meterRegistry); new ProcessorMetrics().bindTo(meterRegistry); new FileDescriptorMetrics().bindTo(meterRegistry); Javalin app = Javalin.create(config -> config.registerPlugin(new MicrometerPlugin(meterRegistry))).start(8080); // must manually delegate to Micrometer exception handler for excepton tags to be correct app.exception(IllegalArgumentException.class, (e, ctx) -> { MicrometerPlugin.EXCEPTION_HANDLER.handle(e, ctx); e.printStackTrace(); }); app.get("/", ctx -> ctx.result("Hello World")); app.get("/hello/:name", ctx -> ctx.result("Hello: " + ctx.pathParam("name"))); app.get("/boom", ctx -> { throw new IllegalArgumentException("boom"); }); app.routes(() -> { path("hi", () -> { get(":name", ctx -> ctx.result("Hello: " + ctx.pathParam("name"))); }); }); app.after("/hello/*", ctx -> { System.out.println("hello"); }); app.get("/prometheus", ctx -> ctx .contentType(TextFormat.CONTENT_TYPE_004) .result(meterRegistry.scrape())); }
Example #28
Source File: DefaultReportsServer.java From maestro-java with Apache License 2.0 | 4 votes |
protected Javalin getServerInstance() { return app; }
Example #29
Source File: JavalinService.java From elepy with Apache License 2.0 | 4 votes |
public JavalinService() { this.javalin = Javalin.create(); this.port = 1337; }
Example #30
Source File: BeaconRestApi.java From teku with Apache License 2.0 | 4 votes |
BeaconRestApi( final DataProvider dataProvider, final TekuConfiguration configuration, final Javalin app) { this.app = app; initialize(dataProvider, configuration); }