public void sendAsyncResultFailure(ReplyFailure failure, String msg) { unregister(); asyncResultHandler.handle(Future.failedFuture(new ReplyException(failure, msg))); }
@Override public void fail(int failureCode, String message) { if (replyAddress != null) { sendReply(bus.createMessage(true, replyAddress, null, new ReplyException(ReplyFailure.RECIPIENT_FAILURE, failureCode, message), null), null, null); } }
@Override public ReplyException decodeFromWire(int pos, Buffer buffer) { int i = (int) buffer.getByte(pos); ReplyFailure rf = ReplyFailure.fromInt(i); pos++; int failureCode = buffer.getInt(pos); pos += 4; boolean isNull = buffer.getByte(pos) == (byte)0; String message; if (!isNull) { pos++; int strLength = buffer.getInt(pos); pos += 4; byte[] bytes = buffer.getBytes(pos, pos + strLength); message = new String(bytes, CharsetUtil.UTF_8); } else { message = null; } return new ReplyException(rf, failureCode, message); }
public void sendAsyncResultFailure(ReplyFailure failure, String msg) { unregister(); asyncResultHandler.handle(Future.failedFuture(new ReplyException(failure, msg))); }
/** * @param obj base64 加密后的图片 * @return Buffer 流 */ public static Future<Buffer> getImageFromBase64(String obj) { Future<Buffer> result = Future.future(); if (obj == null) { result.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 500, "图片读取失败")); return result; } Base64.Decoder decoder = Base64.getDecoder(); byte[] bs; bs = decoder.decode(obj); Buffer buffer = Buffer.buffer(bs); result.complete(buffer); return result; }
/** * @param categories 用户请求的类别 [img, shenghuo ,buyi] * @return 返回一个随机类别的 key (set) */ private Future<String> checkAndGetKey(JsonArray categories) { Future<String> result = Future.future(); List<String> toRandom = keysInRedis.getKeys(categories); if (toRandom.size() >= 1) { result.complete(toRandom.get(random.nextInt(toRandom.size()))); } else { result.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 404, "没有结果,请检查API")); } return result; } }
@Override public void fail(int failureCode, String message) { if (replyAddress != null) { sendReply(bus.createMessage(true, replyAddress, null, new ReplyException(ReplyFailure.RECIPIENT_FAILURE, failureCode, message), null), null, null); } }
@Override public ReplyException decodeFromWire(int pos, Buffer buffer) { int i = (int) buffer.getByte(pos); ReplyFailure rf = ReplyFailure.fromInt(i); pos++; int failureCode = buffer.getInt(pos); pos += 4; boolean isNull = buffer.getByte(pos) == (byte)0; String message; if (!isNull) { pos++; int strLength = buffer.getInt(pos); pos += 4; byte[] bytes = buffer.getBytes(pos, pos + strLength); message = new String(bytes, CharsetUtil.UTF_8); } else { message = null; } return new ReplyException(rf, failureCode, message); }
routingContext.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 400, "参数错误"));
return Future.failedFuture(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 401, "Unauthorized")); fut.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 500, authenticate.cause().getMessage())); return; fut.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 403, "Forbidden")); return; fut.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 403, "Forbidden")); fut.fail(new ReplyException(ReplyFailure.RECIPIENT_FAILURE, 500, res.cause().getMessage()));
/** * Test code of {@link ReplyException} */ @Test public void testThrowableToCodeReplyException() { int expectedCode = 505; Throwable throwable = new ReplyException(ReplyFailure.NO_HANDLERS, expectedCode, "Message"); int statusCode = ThrowableHelper.throwableToCode(throwable); assertEquals(expectedCode, statusCode); }