Java Code Examples for io.vertx.core.eventbus.Message#fail()
The following examples show how to use
io.vertx.core.eventbus.Message#fail() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DATAVerticle.java From VX-API-Gateway with MIT License | 6 votes |
/** * 删除一个API,接收应用程序的字符串名字 * * @param msg */ public void delAPI(Message<JsonObject> msg) { if (msg.body() == null) { msg.fail(411, "the msg body is null"); } else { String appName = msg.body().getString("appName"); String apiName = msg.body().getString("apiName"); if (StrUtil.isNullOrEmpty(appName, apiName)) { msg.fail(411, "the appName or apiName is null"); return; } String sql = MessageFormat.format("delete from {0} where {1} = ? and {2} = ? ", APITN, API_APPIC, APIIC); JsonArray params = new JsonArray(); params.add(appName); params.add(apiName); jdbcClient.updateWithParams(sql, params, res -> { if (res.succeeded()) { int result = res.result().getUpdated(); msg.reply(result); } else { msg.fail(500, res.cause().toString()); LOG.error("执行删除API-->失败:" + res.cause().toString()); } }); } }
Example 2
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 6 votes |
/** * 更新一个路由 * * @param msg */ public void updtRoute(Message<JsonObject> msg) { if (msg.body() == null) { msg.fail(1400, "参数不能为空"); return; } VxApisDTO dto = VxApisDTO.fromJson(msg.body()); if (dto == null) { msg.fail(1405, "参数不能为空"); return; } String apiName = dto.getApiName(); if (httpRouteMaps.get(apiName) != null) { httpRouteMaps.get(apiName).forEach(r -> r.disable().remove()); } if (httpsRouteMaps.get(apiName) != null) { httpsRouteMaps.get(apiName).forEach(r -> r.disable().remove()); } addRoute(msg); }
Example 3
Source File: CqApiVerticle.java From swagger-aem with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 4
Source File: StoreApiVerticle.java From openapi-generator with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 5
Source File: ConsoleApiVerticle.java From swagger-aem with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 6
Source File: CustomApiVerticle.java From swagger-aem with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 7
Source File: SlingApiVerticle.java From swagger-aem with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 8
Source File: UsersReadFromMongo.java From kube_vertx_demo with Apache License 2.0 | 5 votes |
private void getResultAndReply(Message<Object> handler, AsyncResult<JsonObject> lookup) { if (lookup.failed()) { handler.fail(500, "lookup failed"); return; } JsonObject user = lookup.result(); if (user == null) { handler.fail(404, "no user found"); } else { handler.reply(user.encode()); } }
Example 9
Source File: BaseRemoteAccessApiVerticle.java From swaggy-jenkins with MIT License | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 10
Source File: RemoteAccessApiVerticle.java From swaggy-jenkins with MIT License | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 11
Source File: BlueOceanApiVerticle.java From swaggy-jenkins with MIT License | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 12
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 5 votes |
/** * 删除一个路由 * * @param msg */ public void delRoute(Message<String> msg) { if (StrUtil.isNullOrEmpty(msg.body())) { msg.fail(1400, "参数:API名字不能为空"); return; } String apiName = msg.body(); if (httpRouteMaps.get(apiName) != null) { httpRouteMaps.get(apiName).forEach(r -> r.disable().remove()); } if (httpsRouteMaps.get(apiName) != null) { httpsRouteMaps.get(apiName).forEach(r -> r.disable().remove()); } msg.reply(1); }
Example 13
Source File: DATAVerticle.java From VX-API-Gateway with MIT License | 5 votes |
/** * 查看所有API * * @param msg */ public void findAPI(Message<JsonObject> msg) { if (msg.body() == null || msg.body().getString("appName") == null) { msg.fail(411, "the application name is null"); } else { String sql = MessageFormat.format("select {0} AS {1},{2} AS {3},{4} AS {5} from {6} where {2} = ? ", APIIC, APIIN, API_APPIC, API_APPIN, APICC, APICN, APITN); // 添加从请求中获取添加值并添加到查询条件中 JsonArray params = new JsonArray(); params.add(msg.body().getString("appName")); jdbcClient.queryWithParams(sql, params, res -> { if (res.succeeded()) { List<JsonObject> rows = res.result().getRows(); JsonArray array = new JsonArray(); rows.forEach(va -> { if (va.getValue(APICN) instanceof String) { array.add(new JsonObject(va.getString(APICN))); } else if (va.getValue(APICN) instanceof JsonObject) { array.add(va.getJsonObject(APICN)); } }); msg.reply(array); } else { msg.fail(500, res.cause().toString()); LOG.error("执行查看所有API-->失败:" + res.cause().toString()); } }); } }
Example 14
Source File: DATAVerticle.java From VX-API-Gateway with MIT License | 5 votes |
/** * 删除一个应用程序,接收应用程序的字符串名字 * * @param msg */ public void delApplication(Message<String> msg) { if (msg.body() == null) { msg.fail(411, "the application name is null"); } else { String isql = MessageFormat.format("delete from {0} where {1} = ?", APITN, API_APPIC); JsonArray iparams = new JsonArray(); iparams.add(msg.body()); jdbcClient.updateWithParams(isql, iparams, ires -> { if (ires.succeeded()) { String sql = MessageFormat.format("delete from {0} where {1} = ?", APPTN, APPIC); JsonArray params = new JsonArray(); params.add(msg.body()); jdbcClient.updateWithParams(sql, params, res -> { if (res.succeeded()) { int result = res.result().getUpdated(); msg.reply(result); } else { msg.fail(500, res.cause().toString()); LOG.error("执行删除应用程序-->失败:" + ires.cause().toString()); } }); } else { msg.fail(500, ires.cause().toString()); LOG.error("执行删除应用程序-->失败:" + ires.cause().toString()); } }); } }
Example 15
Source File: UserApiVerticle.java From openapi-generator with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 16
Source File: PetApiVerticle.java From openapi-generator with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 17
Source File: StoreApiVerticle.java From openapi-generator with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 18
Source File: UserApiVerticle.java From openapi-generator with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 19
Source File: CrxApiVerticle.java From swagger-aem with Apache License 2.0 | 5 votes |
private void manageError(Message<JsonObject> message, Throwable cause, String serviceName) { int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); if (cause instanceof MainApiException) { code = ((MainApiException)cause).getStatusCode(); statusMessage = ((MainApiException)cause).getStatusMessage(); } else { logUnexpectedError(serviceName, cause); } message.fail(code, statusMessage); }
Example 20
Source File: VxApiApplication.java From VX-API-Gateway with MIT License | 4 votes |
/** * 添加一个路由 * * @param msg */ public void addRoute(Message<JsonObject> msg) { JsonObject body = msg.body().getJsonObject("api"); VxApisDTO dto = VxApisDTO.fromJson(body); if (dto != null) { VxApis api = new VxApis(dto); // 是否代理启动API到当前应用 boolean otherRouteAdd = msg.body().getBoolean("elseRouteToThis", false); if (otherRouteAdd) { // 服务器的类型1=http,2=https,3=webSocket int type = msg.body().getInteger("serverType", 0); if (type == 1) { addHttpRouter(api, res -> { if (res.succeeded()) { msg.reply(1); } else { msg.fail(500, res.cause().getMessage()); } }); } else if (type == 2) { addHttpsRouter(api, res -> { if (res.succeeded()) { msg.reply(1); } else { msg.fail(500, res.cause().getMessage()); res.cause().printStackTrace(); } }); } else { msg.fail(500, "不存在的服务"); } } else { // 本应用添加API,既属于自己的网关应用添加API if (httpRouter != null && httpsRouter != null) { Future<Boolean> httpFuture = Future.future(http -> addHttpRouter(api, http)); Future<Boolean> httpsFuture = Future.<Boolean>future(https -> addHttpsRouter(api, https)); CompositeFuture.all(httpFuture, httpsFuture).setHandler(res -> { if (res.succeeded()) { msg.reply(1); } else { msg.fail(500, res.cause().getMessage()); } }); } else if (httpRouter != null) { addHttpRouter(api, res -> { if (res.succeeded()) { msg.reply(1); } else { msg.fail(500, res.cause().getMessage()); } }); } else if (httpsRouter != null) { addHttpsRouter(api, res -> { if (res.succeeded()) { msg.reply(1); } else { msg.fail(500, res.cause().getMessage()); } }); } else { msg.fail(404, "找不到的服务器可以加载API"); } } } else { msg.fail(1400, "API参数不能为null,请检查APIDTO需要实例化的JSON编写是否正确"); } }