use of io.vertx.core.eventbus.ReplyException in project hono by eclipse.
the class EventBusAuthenticationService method authenticate.
@Override
public void authenticate(final JsonObject authRequest, final Handler<AsyncResult<HonoUser>> authenticationResultHandler) {
final DeliveryOptions options = new DeliveryOptions().setSendTimeout(AUTH_REQUEST_TIMEOUT_MILLIS);
vertx.eventBus().request(AuthenticationConstants.EVENT_BUS_ADDRESS_AUTHENTICATION_IN, authRequest, options, reply -> {
if (reply.succeeded()) {
final JsonObject result = (JsonObject) reply.result().body();
final String token = result.getString(AuthenticationConstants.FIELD_TOKEN);
log.debug("received token [length: {}] in response to authentication request", token.length());
try {
final Jws<Claims> expandedToken = tokenValidator.expand(result.getString(AuthenticationConstants.FIELD_TOKEN));
authenticationResultHandler.handle(Future.succeededFuture(new HonoUserImpl(expandedToken, token)));
} catch (final JwtException e) {
authenticationResultHandler.handle(Future.failedFuture(new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, e)));
}
} else {
final ServiceInvocationException resultException;
if (reply.cause() instanceof ReplyException) {
switch(((ReplyException) reply.cause()).failureType()) {
case TIMEOUT:
log.debug("timeout processing authentication request", reply.cause());
resultException = new ServerErrorException(HttpURLConnection.HTTP_UNAVAILABLE, reply.cause());
break;
case NO_HANDLERS:
log.debug("could not process authentication request", reply.cause());
resultException = new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, reply.cause());
break;
case RECIPIENT_FAILURE:
final int statusCode = ((ReplyException) reply.cause()).failureCode();
if (statusCode < 400 || statusCode >= 600) {
log.error("got illegal status code in authentication response exception: {}", statusCode);
resultException = new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, reply.cause().getMessage());
} else {
resultException = StatusCodeMapper.from(statusCode, reply.cause().getMessage());
}
break;
default:
resultException = new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, reply.cause());
}
} else {
resultException = new ServerErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, reply.cause());
}
authenticationResultHandler.handle(Future.failedFuture(resultException));
}
});
}
use of io.vertx.core.eventbus.ReplyException in project VX-API-Gateway by EliMirren.
the class ClientVerticle method deployAPP.
/**
* 启动应用
*
* @param rct
*/
public void deployAPP(RoutingContext rct) {
String name = rct.request().getParam("name");
LOG.info("执行启动应用-->" + name + "...");
HttpServerResponse response = rct.response().putHeader(CONTENT_TYPE, CONTENT_VALUE_JSON_UTF8);
if (StrUtil.isNullOrEmpty(name)) {
response.end(ResultFormat.formatAsZero(HTTPStatusCodeMsgEnum.C1404));
} else {
vertx.eventBus().<JsonObject>send(thisVertxName + VxApiEventBusAddressConstant.GET_APP, name, body -> {
if (body.succeeded()) {
if (body.result().body().isEmpty()) {
response.end(ResultFormat.formatAsZero(HTTPStatusCodeMsgEnum.C1404));
} else {
JsonObject app = new JsonObject(body.result().body().getString("content"));
JsonObject config = new JsonObject();
config.put("app", app);
config.put("appName", name);
vertx.eventBus().<String>send(thisVertxName + VxApiEventBusAddressConstant.DEPLOY_APP_DEPLOY, config, deploy -> {
if (deploy.succeeded()) {
LOG.info("启动应用-->" + name + ":成功!");
response.end(ResultFormat.formatAsOne(HTTPStatusCodeMsgEnum.C200));
if (vertx.isClustered()) {
vertx.eventBus().publish(VxApiEventBusAddressConstant.DEPLOY_APP_DEPLOY, config.copy().put("thisVertxName", thisVertxName));
LOG.info("广播告诉集群环境中启动应用:" + name);
}
} else {
LOG.error("启动应用-->" + name + " 失败:" + deploy.cause());
HTTPStatusCodeMsgEnum msgCode = HTTPStatusCodeMsgEnum.C500;
if (deploy.cause() != null && deploy.cause() instanceof ReplyException) {
ReplyException cause = (ReplyException) deploy.cause();
if (cause.failureCode() == 1111) {
msgCode = HTTPStatusCodeMsgEnum.C1111;
}
}
response.end(ResultFormat.formatAsZero(msgCode));
}
});
}
} else {
LOG.error("启动应用-->" + name + " 失败:" + body.cause());
System.out.println("启动应用-->" + name + " 失败:" + body.cause());
response.end(ResultFormat.formatAsZero(HTTPStatusCodeMsgEnum.C500));
}
});
}
}
Aggregations