io.vertx.rxjava.ext.web.Router Java Examples

The following examples show how to use io.vertx.rxjava.ext.web.Router. 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: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 6 votes vote down vote up
protected void enableCorsSupport(Router router) {
  Set<String> allowHeaders = new HashSet<>();
  allowHeaders.add("x-requested-with");
  allowHeaders.add("Access-Control-Allow-Origin");
  allowHeaders.add("origin");
  allowHeaders.add("Content-Type");
  allowHeaders.add("accept");
  router.route().handler(CorsHandler.create("*")
    .allowedHeaders(allowHeaders)
    .allowedMethod(HttpMethod.GET)
    .allowedMethod(HttpMethod.POST)
    .allowedMethod(HttpMethod.PUT)
    .allowedMethod(HttpMethod.DELETE)
    .allowedMethod(HttpMethod.PATCH)
    .allowedMethod(HttpMethod.OPTIONS)
  );
}
 
Example #2
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
public void start(Future<Void> startFuture) {
    this.name = this.getClass().getSimpleName() + "(" + Thread.currentThread().getName() + ", localhost:" + port + ")";
    Router router = Router.router(vertx);
    router.get("/some/path/:name/:address/:anotherParam").handler(this::processGetSomePath);
    router.post("/some/path/send").handler(this::processPostSomePathSend);
    router.post("/some/path/publish").handler(this::processPostSomePathPublish);
    vertx.createHttpServer().requestHandler(router::handle).rxListen(port).subscribe();
    System.out.println(name + " is waiting...");
}
 
Example #3
Source File: SwaggerRouter.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
public static Router swaggerRouter(Router baseRouter, Swagger swagger, EventBus eventBus, ServiceIdResolver serviceIdResolver, Function<RoutingContext, DeliveryOptions> configureMessage) {
    final io.vertx.ext.web.Router baseRouterDelegate = baseRouter.getDelegate();
    final io.vertx.core.eventbus.EventBus eventBusDelegate = eventBus.getDelegate();

    Function<io.vertx.ext.web.RoutingContext, DeliveryOptions> configureMessageDelegate = null;

    if (configureMessage != null) {
        configureMessageDelegate = rc -> configureMessage.apply(new RoutingContext(rc));
    }

    return new Router(com.github.phiz71.vertx.swagger.router.SwaggerRouter.swaggerRouter(baseRouterDelegate, swagger, eventBusDelegate, serviceIdResolver, configureMessageDelegate));
}
 
Example #4
Source File: AuditVerticle.java    From vertx-microservices-workshop with Apache License 2.0 5 votes vote down vote up
private Single<HttpServer> configureTheHTTPServer() {
  //----
  // Use a Vert.x Web router for this REST API.
  Router router = Router.router(vertx);
  router.get("/").handler(this::retrieveOperations);
  HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
  Integer port = config().getInteger("http.port", 0);
  return server.rxListen(port);
  //----
}
 
Example #5
Source File: SwaggerRouter.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
public static Router swaggerRouter(Router baseRouter, Swagger swagger, EventBus eventBus) {
    return swaggerRouter(baseRouter, swagger, eventBus, new DefaultServiceIdResolver(), null);
}
 
Example #6
Source File: SwaggerRouter.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
public static Router swaggerRouter(Router baseRouter, Swagger swagger, EventBus eventBus, ServiceIdResolver serviceIdResolver) {
    return swaggerRouter(baseRouter, swagger, eventBus, serviceIdResolver, null);
}
 
Example #7
Source File: SwaggerRouterTest.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testIllegalPathParameterName() {
    String definition = definitions.getJsonObject(0).encode();
    Swagger swagger = new SwaggerParser().parse(definition);
    SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, eventBus);
}
 
Example #8
Source File: SwaggerRouterTest.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testEmptyPathParameterName() {
    String definition = definitions.getJsonObject(1).encode();
    Swagger swagger = new SwaggerParser().parse(definition);
    SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, eventBus);
}
 
Example #9
Source File: SwaggerRouterTest.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testNumericPathParameterName() {
    String definition = definitions.getJsonObject(2).encode();
    Swagger swagger = new SwaggerParser().parse(definition);
    SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, eventBus);
}
 
Example #10
Source File: SwaggerRouterTest.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testPathParameterNameStartsWithNumber() {
    String definition = definitions.getJsonObject(3).encode();
    Swagger swagger = new SwaggerParser().parse(definition);
    SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, eventBus);
}
 
Example #11
Source File: SwaggerRouterTest.java    From vertx-swagger with Apache License 2.0 4 votes vote down vote up
@Test
public void testAlphaNumericPathParameterName() {
    String definition = definitions.getJsonObject(4).encode();
    Swagger swagger = new SwaggerParser().parse(definition);
    SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, eventBus);
}
 
Example #12
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected Single<Void> createHttpServer(Router router, String host, int port) {
  return vertx.createHttpServer()
    .requestHandler(router::accept)
    .rxListen(port, host)
    .map(r -> null);
}
 
Example #13
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void enableLocalSession(Router router, String name) {
  Objects.requireNonNull(name);
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx, name)));
}
 
Example #14
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void enableClusteredSession(Router router, String name) {
  Objects.requireNonNull(name);
  router.route().handler(CookieHandler.create());
  router.route().handler(SessionHandler.create(ClusteredSessionStore.create(vertx, name)));
}