Package org.vertx.java.core.http

Examples of org.vertx.java.core.http.RouteMatcher


    super.start();
    address = getOptionalStringConfig("address", Topic.STORE);
    JsonObject rest = getOptionalObjectConfig("rest", new JsonObject());
    String path = rest.getString("prefix", "/store");
    HttpServer server = vertx.createHttpServer().setCompressionSupported(true);
    RouteMatcher matcher = new RouteMatcher();

    String snapshot = path + "/:docType/:docId";
    String ops = path + "/:docType/:docId" + Topic.OPS;
    Handler<HttpServerRequest> handler = new Handler<HttpServerRequest>() {
      @Override
      public void handle(final HttpServerRequest req) {
        JsonObject message = parseRequest(req);
        eb.sendWithTimeout(address, message, StoreModule.REPLY_TIMEOUT,
            new Handler<AsyncResult<Message<Object>>>() {
              @Override
              public void handle(AsyncResult<Message<Object>> ar) {
                if (ar.failed()) {
                  req.response().setStatusCode(500).setStatusMessage(ar.cause().getMessage()).end();
                  return;
                }
                Object body = ar.result().body();
                if (body == null) {
                  req.response().setStatusCode(404).end();
                  return;
                }
                if ("HEAD".equals(req.method())) {
                  req.response().end(body.toString());
                } else {
                  req.response().headers().set("Content-Type", "application/json");
                  req.response().end(((JsonObject) body).encode());
                }
              }
            });
      }
    };
    matcher.get(snapshot, handler);
    matcher.head(snapshot, handler);
    matcher.post(snapshot, new Handler<HttpServerRequest>() {
      @Override
      public void handle(final HttpServerRequest req) {
        final JsonObject message = parseRequest(req);
        req.bodyHandler(new Handler<Buffer>() {
          @Override
          public void handle(Buffer body) {
            message.putObject(Key.OP_DATA, new JsonObject(body.toString()));
            eb.sendWithTimeout(address, message, StoreModule.REPLY_TIMEOUT,
                new Handler<AsyncResult<Message<JsonObject>>>() {
                  @Override
                  public void handle(AsyncResult<Message<JsonObject>> ar) {
                    if (ar.failed()) {
                      req.response().setStatusCode(500).setStatusMessage(ar.cause().getMessage())
                          .end();
                      return;
                    }
                    JsonObject body = ar.result().body();
                    req.response().headers().set("Content-Type", "application/json");
                    req.response().end(body.encode());
                  }
                });
          }
        });
      }
    });

    matcher.get(ops, new Handler<HttpServerRequest>() {
      @Override
      public void handle(final HttpServerRequest req) {
        final JsonObject message = parseRequest(req);
        Long from = null;
        Long to = null;
View Full Code Here


        // Init jersey handler
        jerseyHandler.init(configurator);

        // Set request handler for the baseUri
        RouteMatcher rm = new RouteMatcher();
        server.requestHandler(rm);
        // regex pattern will be: "^base_path/.*"
        String pattern = "^" + jerseyHandler.getBaseUri().getPath() + ".*";
        rm.all(pattern, jerseyHandler);

        // Add any additional routes if handler is provided
        if (routeMatcherHandler != null) {
            routeMatcherHandler.handle(rm);
        }
View Full Code Here

        // Set request handler, use route matcher if a route handler is provided.
        if (routeMatcherHandler == null) {
            server.requestHandler(jerseyHandler);
        } else {
            RouteMatcher rm = new RouteMatcher();
            String pattern = jerseyHandler.getBaseUri().getPath() + "*";
            rm.all(pattern, jerseyHandler);
            routeMatcherHandler.handle(rm);
        }

        final String host = configurator.getHost();
        final int port = configurator.getPort();
View Full Code Here

public class RouteMatchExample extends Verticle {

  public void start() {

    RouteMatcher rm = new RouteMatcher();

    rm.get("/details/:user/:id", new Handler<HttpServerRequest>() {
      public void handle(HttpServerRequest req) {
        req.response.end("User: " + req.params().get("user") + " ID: " + req.params().get("id"));
      }
    });

    // Catch all - serve the index page
    rm.getWithRegEx(".*", new Handler<HttpServerRequest>() {
      public void handle(HttpServerRequest req) {
        req.response.sendFile("route_match/index.html");
      }
    });

View Full Code Here

        // Set request handler, use route matcher if a route handler is provided.
        if (routeMatcherHandler == null) {
            server.requestHandler(jerseyHandler);
        } else {
            RouteMatcher rm = new RouteMatcher();
            String pattern = jerseyHandler.getBaseUri().getPath() + "*";
            rm.all(pattern, jerseyHandler);
            routeMatcherHandler.handle(rm);
        }

        // Start listening and log success/failure
        server.listen(port, host, new Handler<AsyncResult<HttpServer>>() {
View Full Code Here

TOP

Related Classes of org.vertx.java.core.http.RouteMatcher

Copyright © 2018 www.massapicom. 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.