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


Java RoutingContext.failure方法代码示例

本文整理汇总了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();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:VertxRestDispatcher.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestVertxRestDispatcher.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestVertxRestDispatcher.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:TestVertxRestDispatcher.java

示例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());
        }
    }

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:27,代码来源:GlobalFailureHandler.java

示例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();
    }
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:AuthenticateEndurer.java

示例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"));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:33,代码来源:TestAbstractEdgeDispatcher.java

示例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);
  }
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:12,代码来源:GlobalExceptionHandler.java


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