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

The following examples show how to use io.vertx.rxjava.ext.web.RoutingContext. 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: TestResourceRxJava1.java    From redpipe with Apache License 2.0 6 votes vote down vote up
@Path("inject")
@GET
public String inject(@Context Vertx vertx,
		@Context RoutingContext routingContext,
		@Context HttpServerRequest request,
		@Context HttpServerResponse response,
		@Context AuthProvider authProvider,
		@Context User user,
		@Context Session session) {
	if(vertx == null
			|| routingContext == null
			|| request == null
			|| response == null
			|| session == null)
		throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
	return "ok";
}
 
Example #2
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
private void processPostSomePathSend(RoutingContext ctx){
    ctx.request().bodyHandler(buffer -> {
        System.out.println("\n" + name + ": got payload\n    " + buffer);
        JsonObject payload = new JsonObject(buffer.toString());
        String caller = payload.getString("name");
        String address = payload.getString("address");
        String value = payload.getString("anotherParam");
        vertx.eventBus().rxSend(address, caller + " called with value " + value).toObservable()
            .subscribe(reply -> {
                System.out.println(name + ": got message\n    " + reply.body());
                ctx.response().setStatusCode(200).end(reply.body().toString() + "\n");
            }, Throwable::printStackTrace);
    });
}
 
Example #3
Source File: AuditVerticle.java    From vertx-microservices-workshop with Apache License 2.0 5 votes vote down vote up
private void retrieveOperations(RoutingContext context) {
  // We retrieve the operation using the following process:
  // 1. Get the connection
  // 2. When done, execute the query
  // 3. When done, iterate over the result to build a list
  // 4. close the connection
  // 5. return this list in the response

  //TODO
  // ----

  // ----
}
 
Example #4
Source File: AuditVerticle.java    From vertx-microservices-workshop with Apache License 2.0 5 votes vote down vote up
private void retrieveOperations(RoutingContext context) {
  // We retrieve the operation using the following process:
  // 1. Get the connection
  // 2. When done, execute the query
  // 3. When done, iterate over the result to build a list
  // 4. close the connection
  // 5. return this list in the response

  // ----
  // 1 - we retrieve the connection
  Single<List<JsonObject>> result = jdbc.rxGetConnection().flatMap(
      conn -> conn
          // 2. we execute the query
          .rxQuery(SELECT_STATEMENT)
          // 3. Build the list of operations
          .map(set -> set.getRows()
              .stream()
              .map(json -> new JsonObject(json.getString("OPERATION")))
              .collect(Collectors.toList()))
          // 4. Close the connection
          .doAfterTerminate(conn::close));

  result.subscribe(operations -> {
    // 5. Send the list to the response
    context.response()
        .setStatusCode(200)
        .end(Json.encodePrettily(operations));
  }, context::fail);
  // ----
}
 
Example #5
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 5 votes vote down vote up
protected void badGateway(Throwable ex, RoutingContext context) {
  ex.printStackTrace();
  context.response()
    .setStatusCode(502)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("error", "bad_gateway")
      //.put("message", ex.getMessage())
      .encodePrettily());
}
 
Example #6
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 5 votes vote down vote up
protected void requireLogin(RoutingContext context, BiConsumer<RoutingContext, JsonObject> biHandler) {
  Optional<JsonObject> principal = Optional.ofNullable(context.request().getHeader("user-principal"))
    .map(JsonObject::new);
  if (principal.isPresent()) {
    biHandler.accept(context, principal.get());
  } else {
    context.response()
      .setStatusCode(401)
      .end(new JsonObject().put("message", "need_auth").encode());
  }
}
 
Example #7
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 #8
Source File: PermissionInjector.java    From redpipe with Apache License 2.0 5 votes vote down vote up
@Override
public Single<Boolean> resolve(Class<? extends Single<Boolean>> rawType, Type genericType,
		Annotation[] annotations) {
	for (Annotation annotation : annotations) {
		if(annotation.annotationType() == HasPermission.class) {
			RoutingContext ctx = ResteasyProviderFactory.getContextData(RoutingContext.class);
			User user = ctx.user();
			if(user == null)
				return Single.just(false);
			return user.rxIsAuthorised(((HasPermission) annotation).value());
		}
	}
	return null;
}
 
Example #9
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
private void processPostSomePathPublish(RoutingContext ctx){
    ctx.request().bodyHandler(buffer -> {
        System.out.println("\n" + name + ": got payload\n    " + buffer);
        JsonObject payload = new JsonObject(buffer.toString());
        String caller = payload.getString("name");
        String address = payload.getString("address");
        String value = payload.getString("anotherParam");
        vertx.eventBus().publish(address, caller + " called with value " + value);
        ctx.response().setStatusCode(202).end("The message was published to address " + address + ".\n");
    });
}
 
Example #10
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
private void processGetSomePath(RoutingContext ctx){
    String caller = ctx.pathParam("name");
    String address = ctx.pathParam("address");
    String value = ctx.pathParam("anotherParam");
    System.out.println("\n" + name + ": " + caller + " called.");
    vertx.eventBus().rxSend(address, caller + " called with value " + value).toObservable()
        .subscribe(reply -> {
            System.out.println(name + ": got message\n    " + reply.body());
            ctx.response().setStatusCode(200).end(reply.body().toString() + "\n");
        }, Throwable::printStackTrace);
}
 
Example #11
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 4 votes vote down vote up
private void processPostSomePathPublish1(RoutingContext ctx){
    ctx.response().setStatusCode(200).end("Got into processPostSomePathPublish using " + ctx.normalisedPath() + "\n");
}
 
Example #12
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 4 votes vote down vote up
private void processPostSomePathSend1(RoutingContext ctx){
    ctx.response().setStatusCode(200).end("Got into processPostSomePathSend using " + ctx.normalisedPath() + "\n");
}
 
Example #13
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void badRequest(RoutingContext context, Throwable ex) {
  context.response().setStatusCode(400)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("error", ex.getMessage()).encodePrettily());
}
 
Example #14
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void notFound(RoutingContext context) {
  context.response().setStatusCode(404)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("message", "not_found").encodePrettily());
}
 
Example #15
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void internalError(RoutingContext context, Throwable ex) {
  context.response().setStatusCode(500)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("error", ex.getMessage()).encodePrettily());
}
 
Example #16
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void notImplemented(RoutingContext context) {
  context.response().setStatusCode(501)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("message", "not_implemented").encodePrettily());
}
 
Example #17
Source File: HttpServerVert.java    From Learn-Java-12-Programming with MIT License 4 votes vote down vote up
private void processGetSomePath1(RoutingContext ctx){
    ctx.response().setStatusCode(200).end("Got into processGetSomePath using " + ctx.normalisedPath() + "\n");
}
 
Example #18
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void serviceUnavailable(RoutingContext context) {
  context.fail(503);
}
 
Example #19
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void serviceUnavailable(RoutingContext context, Throwable ex) {
  context.response().setStatusCode(503)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("error", ex.getMessage()).encodePrettily());
}
 
Example #20
Source File: RestAPIRxVerticle.java    From vertx-blueprint-microservice with Apache License 2.0 4 votes vote down vote up
protected void serviceUnavailable(RoutingContext context, String cause) {
  context.response().setStatusCode(503)
    .putHeader("content-type", "application/json")
    .end(new JsonObject().put("error", cause).encodePrettily());
}