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


Java ReplyException类代码示例

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


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

示例1: send

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
protected void send(Request request, String target) {
    DeliveryOptions options = new DeliveryOptions().setSendTimeout(request.timeout());

    core.bus().send(target, request.data(), options, send -> {
        if (send.succeeded()) {
            request.write(send.result().body());
        } else {
            Throwable exception = send.cause();

            if (exception instanceof ReplyException) {
                ReplyFailure status = ((ReplyException) exception).failureType();
                exceptionHandlers.get(status).accept(request);
            } else {
                request.error(send.cause());
            }
        }
    });
}
 
开发者ID:codingchili,项目名称:chili-core,代码行数:19,代码来源:BusRouter.java

示例2: testGetUndefinedApiEventbus

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Test
public void testGetUndefinedApiEventbus(TestContext testContext) {
  Async async = testContext.async();
  JsonObject event = new JsonObject().put("name", Randoms.randomAlphabet(10)).put("namespace",
                                                                                  namespace);
  vertx.eventBus().<JsonObject>send("api.get",
      event, ar-> {
        if (ar.succeeded()) {
          testContext.fail();
        } else {
          testContext.assertTrue(ar.cause() instanceof ReplyException);
          ReplyException ex = (ReplyException) ar.cause();
          testContext.assertEquals(DefaultErrorCode.RESOURCE_NOT_FOUND.getNumber(), ex.failureCode());
          async.complete();
        }
      });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:18,代码来源:ApiDefinitionVerticleTest.java

示例3: testMissNameShouldThrowValidationException

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Test
public void testMissNameShouldThrowValidationException(TestContext testContext) {
  AtomicBoolean check = new AtomicBoolean();
  vertx.eventBus().<JsonObject>send("api.delete", new JsonObject(), ar -> {
    if (ar.succeeded()) {
      testContext.fail();
    } else {
      ar.cause().printStackTrace();
      testContext.assertTrue(ar.cause() instanceof ReplyException);
      testContext.assertEquals(DefaultErrorCode.INVALID_ARGS.getNumber(),
                               ReplyException.class.cast(ar.cause()).failureCode());
      check.set(true);
    }
  });
  Awaitility.await().until(() -> check.get());

}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:18,代码来源:DeleteApiCmdTest.java

示例4: testGetApiByUndefinedNameShouldFailed

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Test
public void testGetApiByUndefinedNameShouldFailed(TestContext testContext) {
  JsonObject jsonObject = new JsonObject()
          .put("namespace", namespace)
          .put("name", UUID.randomUUID().toString());
  AtomicBoolean check1 = new AtomicBoolean();

  vertx.eventBus().<JsonObject>send("api.get", jsonObject, ar -> {
    if (ar.succeeded()) {
      testContext.fail();
    } else {
      ar.cause().printStackTrace();
      testContext.assertTrue(ar.cause() instanceof ReplyException);
      testContext.assertEquals(DefaultErrorCode.RESOURCE_NOT_FOUND.getNumber(),
                               ReplyException.class.cast(ar.cause()).failureCode());
      check1.set(true);
    }
  });
  Awaitility.await().until(() -> check1.get());
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:21,代码来源:GetApiCmdTest.java

示例5: testMissNameShouldThrowValidationException

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Test
public void testMissNameShouldThrowValidationException(TestContext testContext) {
  AtomicBoolean check = new AtomicBoolean();
  vertx.eventBus().<JsonObject>send("api.list", new JsonObject(), ar -> {
    if (ar.succeeded()) {
      testContext.fail();
    } else {
      ar.cause().printStackTrace();
      testContext.assertTrue(ar.cause() instanceof ReplyException);
      testContext.assertEquals(DefaultErrorCode.INVALID_ARGS.getNumber(),
                               ReplyException.class.cast(ar.cause()).failureCode());
      check.set(true);
    }
  });
  Awaitility.await().until(() -> check.get());

}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:18,代码来源:ListApiCmdTest.java

示例6: replyJson

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
private static JsonObject replyJson(ReplyException ex) {
  JsonObject jsonObject = new JsonObject();
  DefaultErrorCode errorCode = DefaultErrorCode.getCode(ex.failureCode());
  if (errorCode != null) {
    jsonObject.put("code", errorCode.getNumber())
            .put("message", errorCode.getMessage());
  } else {
    ReplyFailure replyFailure = ex.failureType();
    if (replyFailure == ReplyFailure.NO_HANDLERS) {
      jsonObject.put("code", DefaultErrorCode.SERVICE_UNAVAILABLE.getNumber())
              .put("message", DefaultErrorCode.SERVICE_UNAVAILABLE.getMessage());
    } else if (replyFailure == ReplyFailure.TIMEOUT) {
      jsonObject.put("code", DefaultErrorCode.TIME_OUT.getNumber())
              .put("message", DefaultErrorCode.TIME_OUT.getMessage());
    } else if (replyFailure == ReplyFailure.RECIPIENT_FAILURE) {
      jsonObject.put("code", ex.failureCode())
              .put("message", ex.getMessage());
    } else {
      jsonObject.put("code", DefaultErrorCode.UNKOWN.getNumber())
              .put("message", DefaultErrorCode.UNKOWN.getMessage());
    }
  }
  return jsonObject;
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:25,代码来源:FailureHandler.java

示例7: failed

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
private void failed(Future<RpcResponse> completed,
                    Throwable throwable) {
  if (throwable instanceof ReplyException) {
    ReplyException ex = (ReplyException) throwable;
    if (ex.failureType() == ReplyFailure.NO_HANDLERS) {
      SystemException resourceNotFoundEx =
              SystemException.create(DefaultErrorCode.SERVICE_UNAVAILABLE)
                      .set("details", "No handlers");
      completed.fail(resourceNotFoundEx);
    } else {
      ErrorCode errorCode = CustomErrorCode.create(ex.failureCode(), ex.getMessage(), 400);
      SystemException systemException
              = SystemException.create(errorCode);
      completed.fail(systemException);
    }
  } else {
    completed.fail(throwable);
  }
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:20,代码来源:EventbusRpcHandler.java

示例8: responseAnnotations

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Override
public Collection<KeyValueAnnotation> responseAnnotations() {
  final Collection<KeyValueAnnotation> annotations = new ArrayList<>(4);

  final HttpServerResponse resp = context.response();
  annotations.add(KeyValueAnnotation.create(TraceKeys.HTTP_STATUS_CODE, String.valueOf(resp.getStatusCode())));

  if (context.failed()) {
    if (context.failure() instanceof ReplyException) {
      final ReplyException err = (ReplyException) context.failure();
      annotations.add(KeyValueAnnotation.create(VertxKeys.ReplyFailureType.getName(), err.failureType().name()));
      annotations.add(KeyValueAnnotation.create(VertxKeys.ReplyFailureCode.getName(), Integer.valueOf(err.failureCode()).toString()));
    }
    final String msg = context.failure().getMessage();
    annotations.add(KeyValueAnnotation.create(VertxKeys.ReplyFailureMessage.getName(), msg != null ? msg : ""));
  }
  return annotations;
}
 
开发者ID:emmanuelidi,项目名称:vertx-zipkin,代码行数:19,代码来源:ZipkinWebServerResponseAdapter.java

示例9: errorResponse

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
/**
 * Generate the json error response for a failed request
 * @param throwable the cause of the error
 * @return the json string
 */
protected static String errorResponse(Throwable throwable) {
  String msg = throwableToMessage(throwable, "");

  try {
    return new JsonObject(msg).toString();
  } catch (Exception e) {
    if (throwable instanceof ReplyException) {
      return ServerAPIException.toJson(ServerAPIException.GENERIC_ERROR, msg)
        .toString();
    }

    if (throwable instanceof HttpException) {
      return ServerAPIException.toJson(ServerAPIException.HTTP_ERROR, msg)
        .toString();
    }

    return ServerAPIException.toJson(ServerAPIException.GENERIC_ERROR, msg)
      .toString();
  }
}
 
开发者ID:georocket,项目名称:georocket,代码行数:26,代码来源:AbstractEndpoint.java

示例10: delete

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Override
public void delete(String search, String path, Handler<AsyncResult<Void>> handler) {
  get(search, path, ar -> {
    if (ar.failed()) {
      Throwable cause = ar.cause();
      if (cause instanceof ReplyException) {
        // Cast to get access to the failure code
        ReplyException ex = (ReplyException)cause;

        if (ex.failureCode() == 404) {
          handler.handle(Future.succeededFuture());
          return;
        }
      }
      handler.handle(Future.failedFuture(ar.cause()));
    } else {
      StoreCursor cursor = ar.result();
      Queue<String> paths = new ArrayDeque<>();
      AtomicLong remaining = new AtomicLong(cursor.getInfo().getTotalHits());
      doDelete(cursor, paths, remaining, handler);
    }
  });
}
 
开发者ID:georocket,项目名称:georocket,代码行数:24,代码来源:IndexedStore.java

示例11: register

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
/**
 * Register the proxy handle on the event bus.
 *
 * @param eventBus the event bus
 * @param address the proxy address
 */
public MessageConsumer<JsonObject> register(EventBus eventBus, String address, List<Function<Message<JsonObject>, Future<Message<JsonObject>>>> interceptors) {
  Handler<Message<JsonObject>> handler = this::handle;
  if (interceptors != null) {
    for (Function<Message<JsonObject>, Future<Message<JsonObject>>> interceptor : interceptors) {
      Handler<Message<JsonObject>> prev = handler;
      handler = msg -> {
        Future<Message<JsonObject>> fut = interceptor.apply(msg);
        fut.setHandler(ar -> {
          if (ar.succeeded()) {
            prev.handle(msg);
          } else {
            ReplyException exception = (ReplyException) ar.cause();
            msg.fail(exception.failureCode(), exception.getMessage());
          }
        });
      };
    }
  }
  consumer = eventBus.consumer(address, handler);
  return consumer;
}
 
开发者ID:vert-x3,项目名称:vertx-service-proxy,代码行数:28,代码来源:ProxyHandler.java

示例12: testWithoutToken

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Test
public void testWithoutToken() {

  serviceProxyBuilder
    .setToken(null);

  proxy = serviceProxyBuilder.build(OKService.class);

  proxy.ok(res -> {
    assertTrue(res.failed());
    ReplyException t = (ReplyException) res.cause();
    assertEquals(401, t.failureCode());
    testComplete();
  });
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-service-proxy,代码行数:17,代码来源:SecureServiceBinderTest.java

示例13: testCallWithMessageParamWrongType

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
@Test
public void testCallWithMessageParamWrongType() {
  JsonObject message = new JsonObject();
  message.put("object", new JsonObject().put("foo", "bar"));
  message.put("str", 76523);
  message.put("i", 1234);
  message.put("char", (int)'X'); // chars are mapped to ints
  message.put("enum", SomeEnum.BAR.toString()); // enums are mapped to strings
  vertx.eventBus().send("someaddress", message, new DeliveryOptions().addHeader("action", "invokeWithMessage").setSendTimeout(500), onFailure(t -> {
    assertTrue(t instanceof ReplyException);
    ReplyException re = (ReplyException) t;
    // This will as operation will fail to be invoked
    assertEquals(ReplyFailure.RECIPIENT_FAILURE, re.failureType());
    testComplete();
  }));
  await();
}
 
开发者ID:vert-x3,项目名称:vertx-service-proxy,代码行数:18,代码来源:ServiceProxyTest.java

示例14: sendErrFrame

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
public static void sendErrFrame(String address, String replyAddress, ReplyException failure, WriteStream<Buffer> handler) {
  final JsonObject payload = new JsonObject()
      .put("type", "err")
      .put("address", replyAddress)
      .put("sourceAddress", address)
      .put("failureCode", failure.failureCode())
      .put("failureType", failure.failureType().name())
      .put("message", failure.getMessage());

  writeFrame(payload, handler);
}
 
开发者ID:zzqfsy,项目名称:spring-vertx-tcp,代码行数:12,代码来源:FrameHelper.java

示例15: shutdownHandler

import io.vertx.core.eventbus.ReplyException; //导入依赖的package包/类
/**
 *  Use to terminate the application using a HTTP Post
 *  It requires an AdminKey header to work
 */
private void shutdownHandler(final RoutingContext ctx) {
	// check for AdminKey header
	String adminKey = this.config().getString("AdminKey");
	if (adminKey == null || adminKey.equals(ctx.request().getHeader("AdminKey"))) {
		// TODO: check the body for the right credentials
		this.shutdownExecution(ctx.response());
	} else {
		ctx.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 401, "Sucker nice try!"));
	}
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:15,代码来源:ApplicationStarter.java


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