当前位置: 首页>>代码示例>>Java>>正文


Java RoutingContext类代码示例

本文整理汇总了Java中io.vertx.rxjava.ext.web.RoutingContext的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext类的具体用法?Java RoutingContext怎么用?Java RoutingContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RoutingContext类属于io.vertx.rxjava.ext.web包,在下文中一共展示了RoutingContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getShoppingList

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void getShoppingList(RoutingContext rc) {
    Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();

    HttpServerResponse serverResponse = rc.response()
        .setChunked(true);

    list.subscribe(
        response -> {
            JsonObject body = response.bodyAsJsonObject();
            Observable.from(body)
                .flatMap(entry ->
                    retrievePrice(pricer, entry).toObservable())
                .subscribe(
                    product -> writeProductLine(serverResponse, product),
                    rc::fail,
                    serverResponse::end
                );
        },
        rc::fail);
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:21,代码来源:MyShoppingList.java

示例2: getShoppingListWithCB

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void getShoppingListWithCB(RoutingContext rc) {
    Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();

    HttpServerResponse serverResponse = rc.response()
        .setChunked(true);

    list.subscribe(
        response -> {
            JsonObject body = response.bodyAsJsonObject();
            Observable.from(body)
                .flatMap(entry ->
                    circuit.executeWithFallback(
                        future -> retrievePrice(pricer, entry, future),
                        t -> getFallbackPrice(entry)
                    )
                        .rxSetHandler().toObservable())
                .subscribe(
                    product -> writeProductLine(serverResponse, product),
                    rc::fail,
                    serverResponse::end
                );
        },
        rc::fail);
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:25,代码来源:MyShoppingList.java

示例3: apiUpdatePage

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void apiUpdatePage(RoutingContext context) {
  int id = Integer.valueOf(context.request().getParam("id"));
  JsonObject page = context.getBodyAsJson();
  if (!validateJsonPageDocument(context, page, "client", "markdown")) {
    return;
  }
  // tag::publish-on-page-updated[]
  dbService.rxSavePage(id, page.getString("markdown"))
    .doOnSuccess(v -> { // <1>
      JsonObject event = new JsonObject()
        .put("id", id) // <2>
        .put("client", page.getString("client")); // <3>
      vertx.eventBus().publish("page.saved", event); // <4>
    })
    .subscribe(v -> apiResponse(context, 200, null, null), t -> apiFailure(context, t));
  // end::publish-on-page-updated[]
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:18,代码来源:HttpServerVerticle.java

示例4: apiGetPage

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void apiGetPage(RoutingContext context) {
  int id = Integer.valueOf(context.request().getParam("id"));
  dbService.rxFetchPageById(id)
    .subscribe(dbObject -> {
      if (dbObject.getBoolean("found")) {
        JsonObject payload = new JsonObject()
          .put("name", dbObject.getString("name"))
          .put("id", dbObject.getInteger("id"))
          .put("markdown", dbObject.getString("content"))
          .put("html", Processor.process(dbObject.getString("content")));
        apiResponse(context, 200, "page", payload);
      } else {
        apiFailure(context, 404, "There is no page with ID " + id);
      }
    }, t -> apiFailure(context, t));
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:17,代码来源:HttpServerVerticle.java

示例5: indexHandler

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void indexHandler(RoutingContext context) {
  context.user().rxIsAuthorised("create")
    .flatMap(canCreatePage -> {
      context.put("canCreatePage", canCreatePage);
      return dbService.rxFetchAllPages();
    })
    .flatMap(result -> {
      context.put("title", "Wiki home");
      context.put("pages", result.getList());
      context.put("username", context.user().principal().getString("username"));
      return templateEngine.rxRender(context, "templates", "/index.ftl");
    })
    .subscribe(markup -> {
      context.response().putHeader("Content-Type", "text/html");
      context.response().end(markup);
    }, context::fail);
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:18,代码来源:HttpServerVerticle.java

示例6: pageUpdateHandler

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void pageUpdateHandler(RoutingContext context) {
  String title = context.request().getParam("title");
  boolean pageCreation = "yes".equals(context.request().getParam("newPage"));
  String markdown = context.request().getParam("markdown");
  checkAuthorised(context, pageCreation ? "create" : "update")
    .flatMap(v -> {
      if (pageCreation) {
        return dbService.rxCreatePage(title, markdown);
      } else {
        return dbService.rxSavePage(Integer.valueOf(context.request().getParam("id")), markdown);
      }
    })
    .subscribe(v -> {
      context.response().setStatusCode(303);
      context.response().putHeader("Location", "/wiki/" + title);
      context.response().end();
    }, t -> onError(context, t));
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:19,代码来源:HttpServerVerticle.java

示例7: updateOne

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void updateOne(RoutingContext ctx) {
  JsonObject item;
  try {
    item = ctx.getBodyAsJson();
  } catch (RuntimeException e) {
    error(ctx, 415, "invalid payload");
    return;
  }

  if (item == null) {
    error(ctx, 415, "invalid payload");
    return;
  }

  store.update(ctx.get("fruitId"), item)
    .subscribe(
      () ->
        ctx.response()
          .putHeader("Content-Type", "application/json")
          .setStatusCode(200)
          .end(item.put("id", ctx.<Long>get("fruitId")).encodePrettily()),
      err -> writeError(ctx, err)
    );
}
 
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:25,代码来源:CrudApplication.java

示例8: deleteOne

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void deleteOne(RoutingContext ctx) {
  store.delete(ctx.get("fruitId"))
    .subscribe(
      () ->
        ctx.response()
          .setStatusCode(204)
          .end(),
      err -> {
        if (err instanceof NoSuchElementException) {
          error(ctx, 404, err);
        } else {
          error(ctx, 415, err);
        }
      }
    );
}
 
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:17,代码来源:CrudApplication.java

示例9: handleApiCreatePaymentSolution

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void handleApiCreatePaymentSolution(RoutingContext ctx){ // handleb makselahenduse loomist
    String payment_name = ctx.getBodyAsJson().getString("name"); // Our company
    String payment_description = ctx.getBodyAsJson().getString("description"); // can be optional (purpose of the solution)
    String account_owner = ctx.getBodyAsJson().getString("account_owner"); // We, the developers
    String account_nr = ctx.getBodyAsJson().getString("account_nr"); // Our account where client's payments are received

    if (contains("", payment_name, account_owner, account_nr)){
        serviceUnavailable(ctx, new Throwable("Fields Payment name, Account owner, Account number must be filled!"));
    }

    JsonObject jso = new JsonObject()
            .put("type",BANK_TYPE)
            .put("name", vk_name)
            .put("description", vk_msg)
            .put("account_owner", vk_name)
            .put("account_nr", vk_acc)
            .put("return url", vk_return);

    bankLink.createPaymentSolution(jso)
            .setHandler(resultHandler(ctx, jsonResponse(ctx)));
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:22,代码来源:BankLinkRouter.java

示例10: doDispatch

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void doDispatch(RoutingContext ctx, String path, ServiceReference ref) {
  HttpClientRequest req = ref.getAs(HttpClient.class).request(ctx.request().method(), path,
      res -> res.bodyHandler(body -> check(res.statusCode() >= 500,
          () -> serviceUnavailable(ctx, res.statusMessage()),
          () -> chain(ctx.response(), r -> res.headers().addAll(r.headers()))
              .setStatusCode(res.statusCode())
              .end(body),
          () -> discovery.release(ref))));
  req.headers().addAll(ctx.request().headers());
  // TODO: 24.08.2017 pass user auth data to service?, (in header)
  if (ctx.getBody() != null) {
    req.end(ctx.getBody());
    return;
  }
  req.end();
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:17,代码来源:GatewayVerticle.java

示例11: sendVerificationEmail

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
/**
 * Sends verification mail to user.
 */
@Override
public Future<JsonObject> sendVerificationEmail(RoutingContext ctx, String userEmail) {
    // TODO: 19.04.2017 rewrite with singles
    String unique = genString();
    MailMessage email = new MailMessage()
            .setFrom(FROM)
            .setTo(userEmail)
            .setSubject(getString("MAIL_REGISTER_TITLE", ctx))
            .setHtml(createContent(ctx, userEmail, unique));
    Map<Column, String> data = createDataMap(userEmail); // TODO: 19.04.2017 map builder?
    data.put(Column.VERIFIED, unique);
    return future(fut -> database.update(Table.SETTINGS, data).setHandler(ar -> check(ar.succeeded(),
            () -> client.sendMail(email, result -> check(result.succeeded(),
                    () -> fut.complete(result.result().toJson()),
                    () -> fut.fail("Failed to send email to user: " + result.cause()))),
            () -> fut.fail("Could not set unique verification string DB: " + ar.cause()))));
    /*return future(fut -> database.update(Table.SETTINGS, data)
            .rxSetHandler()
            .doOnError(err -> fut.fail("Could not set unique verification string DB: " + err))
            .toCompletable()
            .andThen(client.rxSendMail(email))
            .doOnError(err -> fut.fail("Failed to send email to user: " + err))
            .map(MailResult::toJson)
            .subscribe(fut::complete));*/
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:29,代码来源:MailServiceImpl.java

示例12: handleLogin

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
/**
 * Renders login page.
 * Changes users language if user pressed any of language buttons.
 * Displays message if one is specified.
 */
private void handleLogin(RoutingContext ctx) {
  LoginTemplate template = getSafe(ctx, TEMPL_LOGIN, LoginTemplate.class);
  String lang = ctx.request().getParam(LANGUAGE);
  if (lang != null) {
    ctx.removeCookie(LANGUAGE);
    ctx.addCookie(cookie(LANGUAGE, lang).setMaxAge(DAYS.toSeconds(30)));
    template.setLang(lang);
  }
  String key = ctx.request().getParam(DISPLAY_MESSAGE);
  engine.render(template.setDisplayMessage(getString(key, ctx))
      .setFormUrl(UI_HOME + FORM.getClientNamePrefixed())
      .setFacebookUrl(UI_HOME + FACEBOOK.getClientNamePrefixed())
      .setGoogleUrl(UI_HOME + GOOGLE.getClientNamePrefixed())
      .setIdCardUrl(UI_HOME + IDCARD.getClientNamePrefixed())
      .setRecommenderUrl(UI_RECOMMENDER)
      .setDescToGenreUrl(UI_DESC_TO_GENRE), endHandler(ctx));
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:23,代码来源:UiRouter.java

示例13: handleIdCardLogin

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
private void handleIdCardLogin(RoutingContext ctx) {
  String state = ctx.request().getHeader(CLIENT_VERIFIED_STATE);
  String cert = ctx.request().getHeader(CLIENT_CERTIFICATE);
  String url = "https://movies.kyngas.eu" + addParameter(UI_LOGIN, DISPLAY_MESSAGE, UNAUTHORIZED);
  check("NONE".equals(state) || cert == null,
      () -> redirect(ctx, url),
      () -> engine.render(getSafe(ctx, TEMPL_IDCARDLOGIN, IdCardLoginTemplate.class)
          .setClientVerifiedHeader(CLIENT_VERIFIED_STATE)
          .setClientCertificateHeader(CLIENT_CERTIFICATE)
          .setClientVerifiedState(state)
          .setClientCertificate(cert)
          .setCallbackUrl(securityConfig.getPac4jConfig()
              .getClients()
              .findClient(IdCardClient.class)
              .getCallbackUrl()), endHandler(ctx)));
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:17,代码来源:UiRouter.java

示例14: render

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
@Override
public Single<Response> render(String name, Map<String, Object> variables) {
    RoutingContext context = ResteasyProviderFactory.getContextData(RoutingContext.class);
    for (Entry<String, Object> entry : variables.entrySet()) {
        context.put(entry.getKey(), entry.getValue());
    }
    context.put("route", new RouterFunction());
    return templateEngine.rxRender(context, name)
            // FIXME: other media types perhaps?
            .map(buffer -> Response.ok(buffer, MediaType.TEXT_HTML).build());
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:12,代码来源:FreeMarkerTemplateRenderer.java

示例15: loginAuth

import io.vertx.rxjava.ext.web.RoutingContext; //导入依赖的package包/类
@POST
@Path("/loginAuth")
public Single<Response> loginAuth(@FormParam("username") String username, @FormParam("password") String password,
        @FormParam("return_url") String returnUrl, @Context Session session, @Context RoutingContext ctx,
        @Context AuthProvider auth) throws URISyntaxException {
    if (username == null || username.isEmpty() || password == null || password.isEmpty())
        return Single.just(Response.status(Status.BAD_REQUEST).build());

    JsonObject authInfo = new JsonObject().put("username", username).put("password", password);
    return auth.rxAuthenticate(authInfo).map(user -> {
        ctx.setUser(user);
        if (session != null) {
            // the user has upgraded from unauthenticated to authenticated
            // session should be upgraded as recommended by owasp
            session.regenerateId();
        }
        String redirectUrl = session.remove(REDIRECT_KEY);
        if (redirectUrl == null)
            redirectUrl = returnUrl;
        if (redirectUrl == null)
            redirectUrl = "/";

        try {
            return Response.status(Status.FOUND).location(new URI(redirectUrl)).build();
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }).onErrorReturn(t -> {
        t.printStackTrace();
        return Response.status(Status.FORBIDDEN).build();
    });
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:33,代码来源:BaseSecurityResource.java


注:本文中的io.vertx.rxjava.ext.web.RoutingContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。