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


Java RoutingContext.getBodyAsJson方法代码示例

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


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

示例1: apiCreatePage

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void apiCreatePage(RoutingContext context) {
  JsonObject page = context.getBodyAsJson();
  if (!validateJsonPageDocument(context, page, "name", "markdown")) {
    return;
  }
  dbService.createPage(page.getString("name"), page.getString("markdown"), reply -> {
    if (reply.succeeded()) {
      context.response().setStatusCode(201);
      context.response().putHeader("Content-Type", "application/json");
      context.response().end(new JsonObject().put("success", true).encode());
    } else {
      context.response().setStatusCode(500);
      context.response().putHeader("Content-Type", "application/json");
      context.response().end(new JsonObject()
        .put("success", false)
        .put("error", reply.cause().getMessage()).encode());
    }
  });
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:20,代码来源:HttpServerVerticle.java

示例2: apiCreatePage

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void apiCreatePage(RoutingContext context) {
  if (context.user().principal().getBoolean("canCreate", false)) {
    JsonObject page = context.getBodyAsJson();
    if (!validateJsonPageDocument(context, page, "name", "markdown")) {
      return;
    }
    dbService.createPage(page.getString("name"), page.getString("markdown"), reply -> {
      if (reply.succeeded()) {
        context.response().setStatusCode(201);
        context.response().putHeader("Content-Type", "application/json");
        context.response().end(new JsonObject().put("success", true).encode());
      } else {
        context.response().setStatusCode(500);
        context.response().putHeader("Content-Type", "application/json");
        context.response().end(new JsonObject()
          .put("success", false)
          .put("error", reply.cause().getMessage()).encode());
      }
    });
  } else {
    context.fail(401);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:24,代码来源:HttpServerVerticle.java

示例3: updateOne

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void updateOne(RoutingContext routingContext) {
    String id = routingContext.request().getParam("id");
    try {
        Integer idAsInteger = Integer.valueOf(id);
        Article article = products.get(idAsInteger);
        if (article == null) {
            // Not found
            routingContext.response().setStatusCode(404).end();
        } else {
            JsonObject body = routingContext.getBodyAsJson();
            article.setTitle(body.getString("title")).setUrl(body.getString("url"));
            products.put(idAsInteger, article);
            routingContext.response()
                .setStatusCode(200)
                .putHeader("content-type", "application/json; charset=utf-8")
                .end(Json.encodePrettily(article));
        }
    } catch (NumberFormatException e) {
        routingContext.response().setStatusCode(400).end();
    }

}
 
开发者ID:cescoffier,项目名称:introduction-to-vert.x,代码行数:23,代码来源:MyFirstVerticle.java

示例4: computeResponse

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void computeResponse(RoutingContext rc) {
    JsonObject json = rc.getBodyAsJson();
    String name = json.getString("name");
    Double price = prices.computeIfAbsent(name, k -> (double) random.nextInt(50));
    Integer q = Integer.parseInt(json.getString("quantity", "1"));
    rc.response().end(new JsonObject()
        .put("name", name)
        .put("price", price)
        .put("quantity", json.getString("quantity", "1"))
        .put("total", "" + (price * q))
        .encodePrettily());
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:13,代码来源:PricerVerticle.java

示例5: addToList

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void addToList(RoutingContext rc) {
    JsonObject json = rc.getBodyAsJson();
    String name = json.getString("name");
    Integer quantity = json
        .getInteger("quantity", 1);

    client.hset(KEY, name, quantity.toString(), x -> {
        getList(rc);
    });
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:11,代码来源:ShoppingBackend.java

示例6: sendCustomerServiceMessage

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
 * 发送客服消息
 */
private void sendCustomerServiceMessage(RoutingContext rc) {
    if (refuseNonLanAccess(rc)) return;
    JsonObject params = rc.getBodyAsJson();
    String openId = params.getString("openId");
    String content = params.getString("content");
    int eid = params.getInteger("eid");
    vertx.eventBus().<JsonObject>send(ADDR_ACCOUNT_DB.get(), makeMessage(COMMAND_GET_ACCOUNT_BY_ID, eid), ar -> {
        HttpServerResponse response = rc.response();
        if (ar.succeeded()) {
            JsonObject acc = ar.result().body();
            vertx.executeBlocking(future -> {
                future.complete(null);//TODO 支付宝客服消息的实现
            }, res -> {
                if (res.succeeded()) {
                    response.putHeader("content-type", "application/json;charset=UTF-8").end(res.result().toString());
                } else {
                    log.error("向公众号" + acc.getString(NAME) + "的粉丝" + openId + "发送客服消息时抛出异常", res.cause());
                    response.setStatusCode(500).end(res.cause().getMessage());
                }
            });
        } else {
            log.error("EventBus消息响应错误", ar.cause());
            response.setStatusCode(500).end("EventBus error!");
        }
    });
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:30,代码来源:AlipayMessageSubRouter.java

示例7: addToList

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void addToList(RoutingContext rc) {
    JsonObject json = rc.getBodyAsJson();
    String name = json.getString("name");
    Integer quantity = json.getInteger("quantity", 1);

    client.hset(KEY, name, quantity.toString(), l -> {
        getList(rc);
    });
}
 
开发者ID:cescoffier,项目名称:vertx-rhsummit-2017,代码行数:10,代码来源:ShoppingListVerticle.java

示例8: handle

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
	JsonObject jsonObject = routingContext.getBodyAsJson();
	// TODO process request
	HttpServerResponse response = routingContext.response();
	response.putHeader("Content-Type", "application/json").setChunked(true);
	response.write("");
	response.end();
}
 
开发者ID:redhat-developer,项目名称:che-vertx-server,代码行数:10,代码来源:CreateServerHandler.java

示例9: addToList

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void addToList(RoutingContext rc) {
    JsonObject json = rc.getBodyAsJson();
    String name = json.getString("name");
    Integer quantity = json.getInteger("quantity", 1);

    redis.hset(KEY, name, quantity.toString(), x -> {
        getList(rc);
    });
}
 
开发者ID:cescoffier,项目名称:vertx-reactive-summit-2017,代码行数:10,代码来源:ShoppingBackendVerticle.java

示例10: addToList

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void addToList(RoutingContext rc) {
    JsonObject json = rc.getBodyAsJson();
    String name = json.getString("name");
    Integer quantity = json.getInteger("quantity", 1);
    redis.hset(KEY, name, quantity.toString(), x -> {
        getList(rc);
    });
}
 
开发者ID:cescoffier,项目名称:vertx-kubernetes-live-coding-devoxx-ma,代码行数:9,代码来源:ShoppingBackendVerticle.java

示例11: apiUpdatePage

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void apiUpdatePage(RoutingContext context) {
  if (context.user().principal().getBoolean("canUpdate", false)) {
    int id = Integer.valueOf(context.request().getParam("id"));
    JsonObject page = context.getBodyAsJson();
    if (!validateJsonPageDocument(context, page, "markdown")) {
      return;
    }
    dbService.savePage(id, page.getString("markdown"), reply -> {
      handleSimpleDbReply(context, reply);
    });
  } else {
    context.fail(401);
  }
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:15,代码来源:HttpServerVerticle.java

示例12: apiUpdatePage

import io.vertx.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, "markdown")) {
    return;
  }
  dbService.savePage(id, page.getString("markdown"), reply -> {
    handleSimpleDbReply(context, reply);
  });
}
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:11,代码来源:HttpServerVerticle.java

示例13: ingest

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public Epsilon<T> ingest(final RoutingContext context,
                         final Epsilon<T> income)
        throws WebException {
    Object returnValue = null;
    final Class<?> paramType = income.getArgType();
    if (is(Session.class, paramType)) {
        // Session Object
        returnValue = context.session();
    } else if (is(HttpServerRequest.class, paramType)) {
        // Request Object
        returnValue = context.request();
    } else if (is(HttpServerResponse.class, paramType)) {
        // Response Object
        returnValue = context.response();
    } else if (is(Vertx.class, paramType)) {
        // Vertx Object
        returnValue = context.vertx();
    } else if (is(EventBus.class, paramType)) {
        // Eventbus Object
        returnValue = context.vertx().eventBus();
    } else if (is(User.class, paramType)) {
        // User Objbect
        returnValue = context.user();
    } else if (is(Set.class, paramType)) {
        // FileUpload
        final Class<?> type = paramType.getComponentType();
        if (is(FileUpload.class, type)) {
            returnValue = context.fileUploads();
        }
    } else if (is(JsonArray.class, paramType)) {
        // JsonArray
        returnValue = context.getBodyAsJsonArray();
    } else if (is(JsonObject.class, paramType)) {
        // JsonObject
        returnValue = context.getBodyAsJson();
    } else if (is(Buffer.class, paramType)) {
        // Buffer
        returnValue = context.getBody();
    }
    return null == returnValue ? income.setValue(null) : income.setValue((T) returnValue);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:43,代码来源:TypedAtomic.java

示例14: createDataset

import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void createDataset(RoutingContext routingContext) {
  String user = getUserId(routingContext);

  JsonObject body = routingContext.getBodyAsJson();
  body.put("owner", user);

  Dataset dataset = datasetDao.write(viewTransformer.transform(Dataset.class, body.encode()));

  routingContext.response().end(viewTransformer.transform(dataset));
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:11,代码来源:DatasetResource.java


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