gpt4 book ai didi

com.netflix.zuul.exception.ZuulException.()方法的使用及代码示例

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

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

ZuulException.<init>介绍

[英]error message, status code and info about the cause
[中]错误消息、状态代码和有关原因的信息

代码示例

代码示例来源: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

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

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

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

@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: 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));
  }
}

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

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
  if (msg instanceof HttpResponse) {
    promise.addListener((future) -> {
      if (! future.isSuccess()) {
        fireWriteError("response headers", future.cause(), ctx);
      }
    });
    super.write(ctx, msg, promise);
  }
  else if (msg instanceof HttpContent) {
    promise.addListener((future) -> {
      if (! future.isSuccess())  {
        fireWriteError("response content", future.cause(), ctx);
      }
    });
    super.write(ctx, msg, promise);
  }
  else {
    //should never happen
    ReferenceCountUtil.release(msg);
    throw new ZuulException("Attempt to write invalid content type to client: "+msg.getClass().getSimpleName(), true);
  }
}

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

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
  if (!ctx.channel().isActive()) {
    ReferenceCountUtil.release(msg);
    return;
  }
  if (msg instanceof HttpRequestMessage) {
    promise.addListener((future) -> {
      if (!future.isSuccess()) {
        fireWriteError("request headers", future.cause(), ctx);
      }
    });
    HttpRequestMessage zuulReq = (HttpRequestMessage) msg;
    preWriteHook(ctx, zuulReq);
    super.write(ctx, buildOriginHttpRequest(zuulReq), promise);
  }
  else if (msg instanceof HttpContent) {
    promise.addListener((future) -> {
      if (!future.isSuccess()) {
        fireWriteError("request content chunk", future.cause(), ctx);
      }
    });
    super.write(ctx, msg, promise);
  }
  else {
    //should never happen
    ReferenceCountUtil.release(msg);
    throw new ZuulException("Received invalid message from client", true);
  }
}

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

private void fireWriteError(String requestPart, Throwable cause, ChannelHandlerContext ctx) throws Exception {
  String errMesg = "Error while proxying " + requestPart + " to origin ";
  if (edgeProxy != null) {
    final ProxyEndpoint ep = edgeProxy;
    edgeProxy = null;
    errMesg += ep.getOrigin().getName();
    ep.errorFromOrigin(cause);
  }
  ctx.fireExceptionCaught(new ZuulException(cause, errMesg, true));
}

代码示例来源: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

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

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

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));
  }
}

代码示例来源: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: Netflix/zuul

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
  if (msg instanceof HttpResponse) {
    promise.addListener((future) -> {
      if (! future.isSuccess()) {
        fireWriteError("response headers", future.cause(), ctx);
      }
    });
    super.write(ctx, msg, promise);
  }
  else if (msg instanceof HttpContent) {
    promise.addListener((future) -> {
      if (! future.isSuccess())  {
        fireWriteError("response content", future.cause(), ctx);
      }
    });
    super.write(ctx, msg, promise);
  }
  else {
    //should never happen
    ReferenceCountUtil.release(msg);
    throw new ZuulException("Attempt to write invalid content type to client: "+msg.getClass().getSimpleName(), true);
  }
}

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

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
  if (evt instanceof CompleteEvent) {
    final CompleteReason reason = ((CompleteEvent) evt).getReason();
    if ((reason != SESSION_COMPLETE) && (edgeProxy != null)) {
      LOG.error("Origin request completed with reason other than COMPLETE: {}, {}",
          reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
      final ZuulException ze = new ZuulException("CompleteEvent", reason.name(), true);
      edgeProxy.errorFromOrigin(ze);
    }
    // First let this event propagate along the pipeline, before cleaning vars from the channel.
    // See channelWrite() where these vars are first set onto the channel.
    try {
      super.userEventTriggered(ctx, evt);
    }
    finally {
      postCompleteHook(ctx, evt);
    }
  }
  else if (evt instanceof IdleStateEvent) {
    if (edgeProxy != null) {
      LOG.error("Origin request received IDLE event: {}", ChannelUtils.channelInfoForLogging(ctx.channel()));
      edgeProxy.errorFromOrigin(new OutboundException(READ_TIMEOUT, edgeProxy.getRequestAttempts()));
    }
    super.userEventTriggered(ctx, evt);
  }
  else {
    super.userEventTriggered(ctx, evt);
  }
}

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

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
  if (!ctx.channel().isActive()) {
    ReferenceCountUtil.release(msg);
    return;
  }
  if (msg instanceof HttpRequestMessage) {
    promise.addListener((future) -> {
      if (!future.isSuccess()) {
        fireWriteError("request headers", future.cause(), ctx);
      }
    });
    HttpRequestMessage zuulReq = (HttpRequestMessage) msg;
    preWriteHook(ctx, zuulReq);
    super.write(ctx, buildOriginHttpRequest(zuulReq), promise);
  }
  else if (msg instanceof HttpContent) {
    promise.addListener((future) -> {
      if (!future.isSuccess()) {
        fireWriteError("request content chunk", future.cause(), ctx);
      }
    });
    super.write(ctx, msg, promise);
  }
  else {
    //should never happen
    ReferenceCountUtil.release(msg);
    throw new ZuulException("Received invalid message from client", true);
  }
}

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

private void fireWriteError(String requestPart, Throwable cause, ChannelHandlerContext ctx) throws Exception {
  String errMesg = "Error while proxying " + requestPart + " to origin ";
  if (edgeProxy != null) {
    final ProxyEndpoint ep = edgeProxy;
    edgeProxy = null;
    errMesg += ep.getOrigin().getName();
    ep.errorFromOrigin(cause);
  }
  ctx.fireExceptionCaught(new ZuulException(cause, errMesg, true));
}

代码示例来源: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 userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
  if (evt instanceof CompleteEvent) {
    final CompleteReason reason = ((CompleteEvent) evt).getReason();
    if ((reason != SESSION_COMPLETE) && (edgeProxy != null)) {
      LOG.error("Origin request completed with reason other than COMPLETE: {}, {}",
          reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
      final ZuulException ze = new ZuulException("CompleteEvent", reason.name(), true);
      edgeProxy.errorFromOrigin(ze);
    }
    // First let this event propagate along the pipeline, before cleaning vars from the channel.
    // See channelWrite() where these vars are first set onto the channel.
    try {
      super.userEventTriggered(ctx, evt);
    }
    finally {
      postCompleteHook(ctx, evt);
    }
  }
  else if (evt instanceof IdleStateEvent) {
    if (edgeProxy != null) {
      LOG.error("Origin request received IDLE event: {}", ChannelUtils.channelInfoForLogging(ctx.channel()));
      edgeProxy.errorFromOrigin(new OutboundException(READ_TIMEOUT, edgeProxy.getRequestAttempts()));
    }
    super.userEventTriggered(ctx, evt);
  }
  else {
    super.userEventTriggered(ctx, evt);
  }
}

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