Package com.darylteo.deploy.web

Source Code of com.darylteo.deploy.web.WebAdmin

package com.darylteo.deploy.web;

import java.nio.file.Path;
import java.nio.file.Paths;

import org.vertx.java.core.Handler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.http.HttpServer;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.json.JsonArray;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.sockjs.SockJSServer;
import org.vertx.java.deploy.Verticle;

public class WebAdmin {

  private static ServeFileHandler fileHandler = new ServeFileHandler();
  private static ServeApiHandler apiHandler = new ServeApiHandler();

  public WebAdmin(final Verticle verticle) {
    final Vertx vertx = verticle.getVertx();

    HttpServer server = vertx.createHttpServer();
    server.requestHandler(new Handler<HttpServerRequest>() {

      @Override
      public void handle(HttpServerRequest request) {
        Path path = Paths.get(request.uri);

        if (path.startsWith("/api")) {
          apiHandler.handle(request);
          return;
        }

        fileHandler.handle(request);
      }
    });

    SockJSServer sockjsServer = vertx.createSockJSServer(server);

    JsonObject config = new JsonObject().putString("prefix", "/eventbus");
    JsonArray inbound = new JsonArray();
    inbound.addObject(new JsonObject().putString("address_re",
        "deployment-manager\\.server\\..+"));
    JsonArray outbound = new JsonArray();
    outbound.addObject(new JsonObject().putString("address_re",
        "deployment-manager\\.client\\..+"));

    sockjsServer.bridge(config, inbound, outbound);

    server.listen(8080, "localhost");
  }
}
TOP

Related Classes of com.darylteo.deploy.web.WebAdmin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.