本文整理汇总了Java中io.vertx.ext.web.RoutingContext.failure方法的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext.failure方法的具体用法?Java RoutingContext.failure怎么用?Java RoutingContext.failure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.RoutingContext
的用法示例。
在下文中一共展示了RoutingContext.failure方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: failureHandler
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void failureHandler(RoutingContext context) {
LOGGER.error("http server failed.", context.failure());
AbstractRestInvocation restProducerInvocation = context.get(RestConst.REST_PRODUCER_INVOCATION);
Throwable e = context.failure();
if (ErrorDataDecoderException.class.isInstance(e)) {
Throwable cause = e.getCause();
if (InvocationException.class.isInstance(cause)) {
e = cause;
}
}
restProducerInvocation.sendFailResponse(e);
// 走到这里,应该都是不可控制的异常,直接关闭连接
context.response().close();
}
示例2: failureHandlerNormal
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Test
public void failureHandlerNormal(@Mocked RoutingContext context) {
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Exception e = new Exception();
new Expectations() {
{
context.get(RestConst.REST_PRODUCER_INVOCATION);
result = restProducerInvocation;
context.failure();
returns(e, e);
}
};
Deencapsulation.invoke(dispatcher, "failureHandler", context);
Assert.assertSame(e, this.throwable);
}
示例3: failureHandlerErrorDataWithInvocation
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Test
public void failureHandlerErrorDataWithInvocation(@Mocked RoutingContext context, @Mocked InvocationException e) {
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
ErrorDataDecoderException edde = new ErrorDataDecoderException(e);
new Expectations() {
{
context.get(RestConst.REST_PRODUCER_INVOCATION);
result = restProducerInvocation;
context.failure();
returns(edde, edde);
}
};
Deencapsulation.invoke(dispatcher, "failureHandler", context);
Assert.assertSame(e, this.throwable);
}
示例4: failureHandlerErrorDataWithNormal
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Test
public void failureHandlerErrorDataWithNormal(@Mocked RoutingContext context) {
RestProducerInvocation restProducerInvocation = new RestProducerInvocation();
Exception e = new Exception();
ErrorDataDecoderException edde = new ErrorDataDecoderException(e);
new Expectations() {
{
context.get(RestConst.REST_PRODUCER_INVOCATION);
result = restProducerInvocation;
context.failure();
returns(edde, edde);
}
};
Deencapsulation.invoke(dispatcher, "failureHandler", context);
Assert.assertSame(edde, this.throwable);
}
示例5: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(final RoutingContext context) {
if (LOG.isErrorEnabled()) {
LOG.error("Unhandled server exception statusCode={} responseEnded={} uri={}", context.statusCode(), context.response().ended(), context.request().uri(), context.failure());
}
if (!context.response().ended()) {
if (context.failure() instanceof ConnectException) {
context.response().setStatusCode(504)
.setStatusMessage(GATEWAY_TIMEOUT)
.putHeader(CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
.end(Errors.serverError(GATEWAY_TIMEOUT).toBuffer());
} else if (context.failure() instanceof UnknownHostException) {
context.response().setStatusCode(503)
.setStatusMessage(GATEWAY_ERROR)
.putHeader(CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
.end(Errors.serverError(GATEWAY_ERROR).toBuffer());
} else {
context.response().setStatusCode(context.statusCode() == -1 ? 500 : context.statusCode())
.setStatusMessage(INTERNAL_SERVER_ERROR)
.putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
.end(Errors.serverError(INTERNAL_SERVER_ERROR).toBuffer());
}
}
}
示例6: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(final RoutingContext event) {
if (event.failed()) {
final Throwable ex = event.failure();
if (ex instanceof WebException) {
final WebException error = (WebException) ex;
Answer.reply(event, Envelop.failure(error));
} else {
// Other exception found
event.fail(ex);
}
} else {
// Success, do not throw, continue to request
event.next();
}
}
示例7: onFailure
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Test
public void onFailure(@Mocked RoutingContext context) {
Map<String, Object> map = new HashMap<>();
HttpServerResponse response = new MockUp<HttpServerResponse>() {
@Mock
HttpServerResponse setStatusCode(int statusCode) {
map.put("code", statusCode);
return null;
}
@Mock
HttpServerResponse setStatusMessage(String statusMessage) {
map.put("msg", statusMessage);
return null;
}
}.getMockInstance();
new Expectations() {
{
context.failure();
returns(new Error("failed"), null);
context.response();
result = response;
}
};
AbstractEdgeDispatcherForTest dispatcher = new AbstractEdgeDispatcherForTest();
dispatcher.onFailure(context);
Assert.assertEquals(502, map.get("code"));
Assert.assertEquals("Bad Gateway", map.get("msg"));
}
示例8: error
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
public static void error(RoutingContext routingContext) {
Exception exception = (Exception) routingContext.failure();
if (exception != null) {
error(routingContext, exception);
} else {
// this is odd
logger.warn(
"Routing context is failed but it does not contain an exception: {}!", routingContext);
}
}