gpt4 book ai didi

com.netflix.zuul.exception.ZuulException类的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 03:52:49 27 4
gpt4 key购买 nike

本文整理了Java中com.netflix.zuul.exception.ZuulException类的一些代码示例,展示了ZuulException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZuulException类的具体详情如下:
包路径:com.netflix.zuul.exception.ZuulException
类名称:ZuulException

ZuulException介绍

[英]All handled exceptions in Zuul are ZuulExceptions
[中]Zuul中处理的所有异常都是ZuuleException

代码示例

代码示例来源:origin: Netflix/zuul

public void finish() throws RuntimeException {
  try {
    gzos.finish();
    gzos.flush();
    gzos.close();
  }
  catch (IOException ioEx) {
    throw new ZuulException(ioEx, "Error finalizing the GzipOutputStream", true);
  }
}

代码示例来源:origin: Netflix/zuul

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  int status = 500;
  final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " +
      ChannelUtils.channelInfoForLogging(ctx.channel());
  if (cause instanceof ZuulException) {
    final ZuulException ze = (ZuulException) cause;
    status = ze.getStatusCode();
    LOG.error(errorMsg, cause);
  }
  else if (cause instanceof ReadTimeoutException) {
    LOG.error(errorMsg + ", Read timeout fired");
    status = 504;
  }
  else {
    LOG.error(errorMsg, cause);
  }
  if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) {
    final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status));
    ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE);
    startedSendingResponseToClient = true;
  }
  else {
    ctx.close();
  }
}

代码示例来源:origin: Netflix/zuul

private void verifyOrigin(SessionContext context, HttpRequestMessage request, String restClientName, Origin primaryOrigin) {
  if (primaryOrigin == null) {
    // If no origin found then add specific error-cause metric tag, and throw an exception with 404 status.
    context.set(CommonContextKeys.STATUS_CATGEORY, SUCCESS_LOCAL_NO_ROUTE);
    String causeName = "RESTCLIENT_NOTFOUND";
    originNotFound(context, causeName);
    ZuulException ze = new ZuulException("No origin found for request. name=" + restClientName
        + ", uri=" + request.reconstructURI(), causeName);
    ze.setStatusCode(404);
    throw ze;
  }
}

代码示例来源:origin: Netflix/zuul

protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) {
  // Add a log statement for this exception.
  final String errorMsg = "Filter Exception: filter=" + filter.filterName() +
      ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage());
  if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) {
    LOG.warn(errorMsg);
  }
  else {
    LOG.error(errorMsg, t);
  }
  // Store this filter error for possible future use. But we still continue with next filter in the chain.
  final SessionContext zuulCtx = inMesg.getContext();
  zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t));
  if (zuulCtx.debugRouting()) {
    Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" +
        filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage());
  }
}

代码示例来源:origin: getheimdall/heimdall

if (exception.getCause() != null) {
  log.error("Error catched", exception.getCause());
} else {
  log.error("Error during filtering", exception);
if (exception.getCause() != null && StringUtils.hasText(exception.getCause().getMessage())) {
  message = exception.getCause().getMessage();
  errorAttributes.put("message", exception.getMessage());

代码示例来源:origin: Netflix/zuul

protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) {
  // Add a log statement for this exception.
  final String errorMsg = "Filter Exception: filter=" + filter.filterName() +
      ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage());
  if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) {
    LOG.warn(errorMsg);
  }
  else {
    LOG.error(errorMsg, t);
  }
  // Store this filter error for possible future use. But we still continue with next filter in the chain.
  final SessionContext zuulCtx = inMesg.getContext();
  zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t));
  if (zuulCtx.debugRouting()) {
    Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" +
        filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage());
  }
}

代码示例来源:origin: Netflix/zuul

private void handleExpect100Continue(ChannelHandlerContext ctx, HttpRequest req) {
  if (HttpUtil.is100ContinueExpected(req)) {
    final ChannelFuture f = ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
    f.addListener((s) -> {
      if (! s.isSuccess()) {
        throw new ZuulException( s.cause(), "Failed while writing 100-continue response", true);
      }
    });
    // Remove the Expect: 100-Continue header from request as we don't want to proxy it downstream.
    req.headers().remove(HttpHeaderNames.EXPECT);
    zuulRequest.getHeaders().remove(HttpHeaderNames.EXPECT.toString());
  }
}

代码示例来源:origin: Netflix/zuul

private void verifyOrigin(SessionContext context, HttpRequestMessage request, String restClientName, Origin primaryOrigin) {
  if (primaryOrigin == null) {
    // If no origin found then add specific error-cause metric tag, and throw an exception with 404 status.
    context.set(CommonContextKeys.STATUS_CATGEORY, SUCCESS_LOCAL_NO_ROUTE);
    String causeName = "RESTCLIENT_NOTFOUND";
    originNotFound(context, causeName);
    ZuulException ze = new ZuulException("No origin found for request. name=" + restClientName
        + ", uri=" + request.reconstructURI(), causeName);
    ze.setStatusCode(404);
    throw ze;
  }
}

代码示例来源:origin: Netflix/zuul

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  int status = 500;
  final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " +
      ChannelUtils.channelInfoForLogging(ctx.channel());
  if (cause instanceof ZuulException) {
    final ZuulException ze = (ZuulException) cause;
    status = ze.getStatusCode();
    LOG.error(errorMsg, cause);
  }
  else if (cause instanceof ReadTimeoutException) {
    LOG.error(errorMsg + ", Read timeout fired");
    status = 504;
  }
  else {
    LOG.error(errorMsg, cause);
  }
  if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) {
    final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status));
    ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE);
    startedSendingResponseToClient = true;
  }
  else {
    ctx.close();
  }
}

代码示例来源:origin: com.netflix.zuul/zuul-core

protected void recordFilterError(final I inMesg, final ZuulFilter<I, O> filter, final Throwable t) {
  // Add a log statement for this exception.
  final String errorMsg = "Filter Exception: filter=" + filter.filterName() +
      ", request-info=" + inMesg.getInfoForLogging() + ", msg=" + String.valueOf(t.getMessage());
  if (t instanceof ZuulException && !((ZuulException) t).shouldLogAsError()) {
    LOG.warn(errorMsg);
  }
  else {
    LOG.error(errorMsg, t);
  }
  // Store this filter error for possible future use. But we still continue with next filter in the chain.
  final SessionContext zuulCtx = inMesg.getContext();
  zuulCtx.getFilterErrors().add(new FilterError(filter.filterName(), filter.filterType().toString(), t));
  if (zuulCtx.debugRouting()) {
    Debug.addRoutingDebug(zuulCtx, "Running Filter failed " + filter.filterName() + " type:" +
        filter.filterType() + " order:" + filter.filterOrder() + " " + t.getMessage());
  }
}

代码示例来源:origin: Netflix/zuul

public void finish() throws RuntimeException {
  try {
    gzos.finish();
    gzos.flush();
    gzos.close();
  }
  catch (IOException ioEx) {
    throw new ZuulException(ioEx, "Error finalizing the GzipOutputStream", true);
  }
}

代码示例来源:origin: Netflix/zuul

+ ", info = " + ChannelUtils.channelInfoForLogging(ctx.channel());
String causeMsg = String.valueOf(clientRequest.decoderResult().cause());
final ZuulException ze = new ZuulException(errorMsg, causeMsg, true);
ze.setStatusCode(400);

代码示例来源:origin: Netflix/zuul

private void handleError(final Throwable cause) {
  final ZuulException ze = (cause instanceof  ZuulException) ?
      (ZuulException) cause : requestAttemptFactory.mapNettyToOutboundException(cause, context);
  LOG.debug("Proxy endpoint failed.", cause);
  if (! startedSendingResponseToClient) {
    startedSendingResponseToClient = true;
    zuulResponse = new HttpResponseMessageImpl(context, zuulRequest, ze.getStatusCode());
    zuulResponse.getHeaders().add("Connection", "close");   // TODO - why close the connection? maybe don't always want this to happen ...
    zuulResponse.finishBufferedBodyIfIncomplete();
    invokeNext(zuulResponse);
  } else {
    channelCtx.fireExceptionCaught(ze);
  }
}

代码示例来源:origin: Netflix/zuul

public void write(final HttpContent chunk) {
  try {
    write(chunk.content());
    gzos.flush();
  }
  catch(IOException ioEx) {
    throw new ZuulException(ioEx, "Error Gzipping response content chunk", true);
  }
  finally {
    chunk.release();
  }
}

代码示例来源:origin: Netflix/zuul

+ ", info = " + ChannelUtils.channelInfoForLogging(ctx.channel());
String causeMsg = String.valueOf(clientRequest.decoderResult().cause());
final ZuulException ze = new ZuulException(errorMsg, causeMsg, true);
ze.setStatusCode(400);

代码示例来源:origin: Netflix/zuul

private void handleError(final Throwable cause) {
  final ZuulException ze = (cause instanceof  ZuulException) ?
      (ZuulException) cause : requestAttemptFactory.mapNettyToOutboundException(cause, context);
  LOG.debug("Proxy endpoint failed.", cause);
  if (! startedSendingResponseToClient) {
    startedSendingResponseToClient = true;
    zuulResponse = new HttpResponseMessageImpl(context, zuulRequest, ze.getStatusCode());
    zuulResponse.getHeaders().add("Connection", "close");   // TODO - why close the connection? maybe don't always want this to happen ...
    zuulResponse.finishBufferedBodyIfIncomplete();
    invokeNext(zuulResponse);
  } else {
    channelCtx.fireExceptionCaught(ze);
  }
}

代码示例来源:origin: Netflix/zuul

@Override
public HttpResponseMessage apply(HttpRequestMessage request) {
  final SessionContext zuulCtx = request.getContext();
  zuulCtx.setErrorResponseSent(true);
  final String errMesg = "Missing Endpoint filter, name = " + name;
  zuulCtx.setError(new ZuulException(errMesg, true));
  LOG.error(errMesg);
  return new HttpResponseMessageImpl(zuulCtx, request, 500);
}

代码示例来源:origin: com.netflix.zuul/zuul-core

private void verifyOrigin(SessionContext context, HttpRequestMessage request, String restClientName, Origin primaryOrigin) {
  if (primaryOrigin == null) {
    // If no origin found then add specific error-cause metric tag, and throw an exception with 404 status.
    context.set(CommonContextKeys.STATUS_CATGEORY, SUCCESS_LOCAL_NO_ROUTE);
    String causeName = "RESTCLIENT_NOTFOUND";
    originNotFound(context, causeName);
    ZuulException ze = new ZuulException("No origin found for request. name=" + restClientName
        + ", uri=" + request.reconstructURI(), causeName);
    ze.setStatusCode(404);
    throw ze;
  }
}

代码示例来源:origin: com.netflix.zuul/zuul-core

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  int status = 500;
  final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " +
      ChannelUtils.channelInfoForLogging(ctx.channel());
  if (cause instanceof ZuulException) {
    final ZuulException ze = (ZuulException) cause;
    status = ze.getStatusCode();
    LOG.error(errorMsg, cause);
  }
  else if (cause instanceof ReadTimeoutException) {
    LOG.error(errorMsg + ", Read timeout fired");
    status = 504;
  }
  else {
    LOG.error(errorMsg, cause);
  }
  if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) {
    final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status));
    ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE);
    startedSendingResponseToClient = true;
  }
  else {
    ctx.close();
  }
}

代码示例来源:origin: Netflix/zuul

private void fireWriteError(String requestPart, Throwable cause, ChannelHandlerContext ctx) throws Exception {
  final String errMesg = String.format("Error writing %s to client", requestPart);
  if (cause instanceof java.nio.channels.ClosedChannelException ||
      cause instanceof Errors.NativeIoException) {
    LOG.info(errMesg + " - client connection is closed.");
    if (zuulRequest != null) {
      zuulRequest.getContext().cancel();
      StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_CANCELLED);
    }
  }
  else {
    LOG.error(errMesg, cause);
    ctx.fireExceptionCaught(new ZuulException(cause, errMesg, true));
  }
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com