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


Java DecodeException类代码示例

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


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

示例1: decodeBodyToObject

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
public static <T> T decodeBodyToObject(RoutingContext routingContext, Class<T> clazz) {
  try {
    return Json.decodeValue(routingContext.getBodyAsString("UTF-8"), clazz);
  } catch (DecodeException exception) {
    routingContext.fail(exception);
    return null;
  }
}
 
开发者ID:BillyYccc,项目名称:vertx-postgresql-starter,代码行数:9,代码来源:RestApiUtil.java

示例2: testDeploymentDescriptor1

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
@Test
public void testDeploymentDescriptor1() {
  int fail = 0;
  final String docSampleDeployment = "{" + LS
    + "  \"srvcId\" : \"sample-module-1\"," + LS
    + "  \"descriptor\" : {" + LS
    + "    \"exec\" : "
    + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"," + LS
    + "    \"env\" : [ {" + LS
    + "      \"name\" : \"helloGreeting\"," + LS
    + "      \"value\" : \"hej\"" + LS
    + "    } ]" + LS
    + "  }" + LS
    + "}";

  try {
    final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment,
      DeploymentDescriptor.class);
    String pretty = Json.encodePrettily(md);
    assertEquals(docSampleDeployment, pretty);
  } catch (DecodeException ex) {
    ex.printStackTrace();
    fail = 400;
  }
  assertEquals(0, fail);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:27,代码来源:BeanTest.java

示例3: from

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
@Override
public Object from(final Class<?> paramType,
                   final String literal) {
    return Fn.get(() ->
                    Fn.getSemi(this.isValid(paramType), this.getLogger(),
                            () -> {
                                try {
                                    return this.getFun().apply(literal);
                                } catch (final DecodeException ex) {
                                    // Do not do anything
                                    // getLogger().jvm(ex);
                                    throw new _400ParameterFromStringException(this.getClass(), paramType, literal);
                                }
                            }, Fn::nil),
            paramType, literal);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:JsonSaber.java

示例4: start

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
    configureJsonMapper();
    Router router = Router.router(vertx);

    router.route().handler(BodyHandler.create());
    router.route().failureHandler(one.valuelogic.vertx.web.problem.reactivex.ProblemHandler.create());
    router.get("/test-get").handler(context -> context.response().end("ok"));
    router.get("/test-error").handler(context -> { throw new DecodeException("testing decode error"); });
    router.route().last().handler(one.valuelogic.vertx.web.problem.reactivex.NotFoundHandler.create());

    vertx.createHttpServer()
            .requestHandler(router::accept)
            .rxListen(HTTP_PORT)
            .subscribe(s -> startFuture.complete(), startFuture::fail);
}
 
开发者ID:valuelogic,项目名称:vertx-web-problem,代码行数:17,代码来源:ExampleVerticle.java

示例5: reply

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
@Override
public void reply(Object message) {
    JsonObject data = new JsonObject();

    if (message instanceof JsonObject) {
        data = (JsonObject) message;
    } else if (message instanceof Buffer) {
        // normally buffers passed directly, for testing purposes
        // its wrapped in a json object.
        try {
            data = ((Buffer) message).toJsonObject();

            if (!data.containsKey(PROTOCOL_STATUS)) {
                data.put(PROTOCOL_STATUS, ACCEPTED);
            }
        } catch (DecodeException e) {
            data.put(ID_BUFFER, message.toString());
            data.put(PROTOCOL_STATUS, ACCEPTED);
        }
    }
    listener.handle(data, responseStatusFromJson(data));
}
 
开发者ID:codingchili,项目名称:chili-core,代码行数:23,代码来源:RequestMock.java

示例6: extract

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
@Override
public Object extract(String name, Parameter parameter, RoutingContext context) {
    BodyParameter bodyParam = (BodyParameter) parameter;
    if ("".equals(context.getBodyAsString())) {
        if (bodyParam.getRequired())
            throw new IllegalArgumentException("Missing required parameter: " + name);
        else
            return null;
    }

    try {
        if(bodyParam.getSchema() instanceof ArrayModel) {
            return context.getBodyAsJsonArray();
        } else {
            return context.getBodyAsJson();
        }
    } catch (DecodeException e) {
        return context.getBodyAsString();  
    }
}
 
开发者ID:phiz71,项目名称:vertx-swagger,代码行数:21,代码来源:BodyParameterExtractor.java

示例7: login

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
public void login(RoutingContext ctx) {
  final String json = ctx.getBodyAsString();
  if (json.length() == 0) {
    logger.debug("test-auth: accept OK in login");
    responseText(ctx, 202).end("Auth accept in /authn/login");
    return;
  }
  LoginParameters p;
  try {
    p = Json.decodeValue(json, LoginParameters.class);
  } catch (DecodeException ex) {
    responseText(ctx, 400).end("Error in decoding parameters: " + ex);
    return;
  }

  // Simple password validation: "peter" has a password "peter-password", etc.
  String u = p.getUsername();
  String correctpw = u + "-password";
  if (!p.getPassword().equals(correctpw)) {
    logger.warn("test-auth: Bad passwd for '" + u + "'. "
            + "Got '" + p.getPassword() + "' expected '" + correctpw + "'");
    responseText(ctx, 401).end("Wrong username or password");
    return;
  }
  String tok;
  tok = token(p.getTenant(), p.getUsername());
  logger.info("test-auth: Ok login for " + u + ": " + tok);
  responseJson(ctx, 200).putHeader(XOkapiHeaders.TOKEN, tok).end(json);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:30,代码来源:Auth.java

示例8: createTenant

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void createTenant(ProxyContext pc, String body,
  Handler<ExtendedAsyncResult<String>> fut) {
  try {
    final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
    if (td.getId() == null || td.getId().isEmpty()) {
      td.setId(UUID.randomUUID().toString());
    }
    final String id = td.getId();
    if (!id.matches("^[a-z0-9_-]+$")) {
      fut.handle(new Failure<>(USER, "Invalid tenant id '" + id + "'"));
      return;
    }
    Tenant t = new Tenant(td);
    tenantManager.insert(t, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
        return;
      }
      location(pc, id, null, Json.encodePrettily(t.getDescriptor()), fut);
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:25,代码来源:InternalModule.java

示例9: updateTenant

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void updateTenant(String id, String body,
  Handler<ExtendedAsyncResult<String>> fut) {
  try {
    final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
    if (!id.equals(td.getId())) {
      fut.handle(new Failure<>(USER, "Tenant.id=" + td.getId() + " id=" + id));
      return;
    }
    Tenant t = new Tenant(td);
    tenantManager.updateDescriptor(td, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
        return;
      }
      final String s = Json.encodePrettily(t.getDescriptor());
      fut.handle(new Success<>(s));
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:22,代码来源:InternalModule.java

示例10: enableModuleForTenant

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void enableModuleForTenant(ProxyContext pc, String id, String body,
  Handler<ExtendedAsyncResult<String>> fut) {
  try {
    final TenantModuleDescriptor td = Json.decodeValue(body,
      TenantModuleDescriptor.class);
    String moduleTo = td.getId();
    tenantManager.enableAndDisableModule(id, null, moduleTo, pc, eres -> {
      if (eres.failed()) {
        fut.handle(new Failure<>(eres.getType(), eres.cause()));
        return;
      }
      td.setId(eres.result());
      location(pc, td.getId(), null, Json.encodePrettily(td), fut);
    });

  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:20,代码来源:InternalModule.java

示例11: installModulesForTenant

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void installModulesForTenant(ProxyContext pc, String id,
  String body, Handler<ExtendedAsyncResult<String>> fut) {

  try {
    TenantInstallOptions options = createTenantOptions(pc.getCtx());

    final TenantModuleDescriptor[] tml = Json.decodeValue(body,
      TenantModuleDescriptor[].class);
    List<TenantModuleDescriptor> tm = new LinkedList<>();
    Collections.addAll(tm, tml);
    tenantManager.installUpgradeModules(id, pc, options, tm, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
      } else {
        logger.info("installUpgradeModules returns:\n" + Json.encodePrettily(res.result()));
        fut.handle(new Success<>(Json.encodePrettily(res.result())));
      }
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:23,代码来源:InternalModule.java

示例12: upgradeModulesForTenant

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void upgradeModulesForTenant(ProxyContext pc, String id,
  Handler<ExtendedAsyncResult<String>> fut) {

  try {
    TenantInstallOptions options = createTenantOptions(pc.getCtx());

    tenantManager.installUpgradeModules(id, pc, options, null, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
      } else {
        logger.info("installUpgradeModules returns:\n" + Json.encodePrettily(res.result()));
        fut.handle(new Success<>(Json.encodePrettily(res.result())));
      }
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:19,代码来源:InternalModule.java

示例13: upgradeModuleForTenant

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void upgradeModuleForTenant(ProxyContext pc, String id, String mod,
  String body, Handler<ExtendedAsyncResult<String>> fut) {
  try {
    final String module_from = mod;
    final TenantModuleDescriptor td = Json.decodeValue(body,
      TenantModuleDescriptor.class);
    final String module_to = td.getId();
    tenantManager.enableAndDisableModule(id, module_from, module_to, pc, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
        return;
      }
      td.setId(res.result());
      final String uri = pc.getCtx().request().uri();
      final String regex = "^(.*)/" + module_from + "$";
      final String newuri = uri.replaceAll(regex, "$1");
      location(pc, td.getId(), newuri, Json.encodePrettily(td), fut);
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:23,代码来源:InternalModule.java

示例14: createModule

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void createModule(ProxyContext pc, String body,
  Handler<ExtendedAsyncResult<String>> fut) {
  try {
    final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
    String validerr = md.validate(pc);
    if (!validerr.isEmpty()) {
      fut.handle(new Failure<>(USER, validerr));
      return;
    }
    moduleManager.create(md, cres -> {
      if (cres.failed()) {
        fut.handle(new Failure<>(cres.getType(), cres.cause()));
        return;
      }
      location(pc, md.getId(), null, Json.encodePrettily(md), fut);
    });
  } catch (DecodeException ex) {
    pc.debug("Failed to decode md: " + pc.getCtx().getBodyAsString());
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:22,代码来源:InternalModule.java

示例15: updateModule

import io.vertx.core.json.DecodeException; //导入依赖的package包/类
private void updateModule(ProxyContext pc, String id, String body,
  Handler<ExtendedAsyncResult<String>> fut) {
  try {
    final ModuleDescriptor md = Json.decodeValue(body, ModuleDescriptor.class);
    if (!id.equals(md.getId())) {
      fut.handle(new Failure<>(USER, "Module.id=" + md.getId() + " id=" + id));
      return;
    }
    String validerr = md.validate(pc);
    if (!validerr.isEmpty()) {
      fut.handle(new Failure<>(USER, validerr));
      return;
    }
    moduleManager.update(md, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
        return;
      }
      final String s = Json.encodePrettily(md);
      fut.handle(new Success<>(s));
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:26,代码来源:InternalModule.java


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