io.javalin.Handler Java Examples

The following examples show how to use io.javalin.Handler. 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: BeakerXServerJavalin.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@NotNull
private Handler handleBackground(RESTAction restAction) {
  return ctx -> {
    restAction.run(new ContextJavalin(ctx));
    ctx.result("ok");
  };
}
 
Example #2
Source File: Server.java    From selenium-jupiter with Apache License 2.0 4 votes vote down vote up
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 #3
Source File: FileSystemViewHandler.java    From hudi with Apache License 2.0 4 votes vote down vote up
ViewHandler(Handler handler, boolean performRefreshCheck) {
  this.handler = handler;
  this.performRefreshCheck = performRefreshCheck;
}