Search in sources :

Example 16 with ZuulException

use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.

the class ClientRequestReceiver method write.

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    try (TaskCloseable ignored = PerfMark.traceTask("CRR.write")) {
        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);
        }
    }
}
Also used : AttributeKey(io.netty.util.AttributeKey) SocketAddress(java.net.SocketAddress) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) LoggerFactory(org.slf4j.LoggerFactory) SslHandshakeInfo(com.netflix.netty.common.ssl.SslHandshakeInfo) Debug(com.netflix.zuul.context.Debug) CurrentPassport(com.netflix.zuul.passport.CurrentPassport) Matcher(java.util.regex.Matcher) ChannelPromise(io.netty.channel.ChannelPromise) Spectator(com.netflix.spectator.api.Spectator) Map(java.util.Map) TaskCloseable(io.perfmark.TaskCloseable) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) InetSocketAddress(java.net.InetSocketAddress) PerfMark(io.perfmark.PerfMark) ZuulException(com.netflix.zuul.exception.ZuulException) List(java.util.List) HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) PassportState(com.netflix.zuul.passport.PassportState) ReferenceCountUtil(io.netty.util.ReferenceCountUtil) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) CommonContextKeys(com.netflix.zuul.context.CommonContextKeys) HttpResponse(io.netty.handler.codec.http.HttpResponse) SessionContextDecorator(com.netflix.zuul.context.SessionContextDecorator) Pattern(java.util.regex.Pattern) SslHandshakeInfoHandler(com.netflix.zuul.netty.server.ssl.SslHandshakeInfoHandler) ChannelUtils(com.netflix.zuul.netty.ChannelUtils) StatusCategoryUtils(com.netflix.zuul.stats.status.StatusCategoryUtils) RejectionUtils(com.netflix.netty.common.throttle.RejectionUtils) HttpVersion(io.netty.handler.codec.http.HttpVersion) Errors(io.netty.channel.unix.Errors) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ZuulStatusCategory(com.netflix.zuul.stats.status.ZuulStatusCategory) ByteBuf(io.netty.buffer.ByteBuf) PROTOCOL_NAME(com.netflix.zuul.netty.server.http2.Http2OrHttpHandler.PROTOCOL_NAME) HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) Headers(com.netflix.zuul.message.Headers) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) SourceAddressChannelHandler(com.netflix.netty.common.SourceAddressChannelHandler) HttpContent(io.netty.handler.codec.http.HttpContent) Logger(org.slf4j.Logger) HttpUtils(com.netflix.zuul.util.HttpUtils) HttpRequestMessageImpl(com.netflix.zuul.message.http.HttpRequestMessageImpl) SessionContext(com.netflix.zuul.context.SessionContext) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) HAProxyMessage(io.netty.handler.codec.haproxy.HAProxyMessage) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) CompleteReason(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) SESSION_COMPLETE(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason.SESSION_COMPLETE) HttpUtil(io.netty.handler.codec.http.HttpUtil) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) ZuulException(com.netflix.zuul.exception.ZuulException) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) TaskCloseable(io.perfmark.TaskCloseable)

Example 17 with ZuulException

use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.

the class OriginResponseReceiver method fireWriteError.

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));
}
Also used : ZuulException(com.netflix.zuul.exception.ZuulException) ProxyEndpoint(com.netflix.zuul.filters.endpoint.ProxyEndpoint)

Example 18 with ZuulException

use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.

the class Gzipper method write.

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();
    }
}
Also used : ZuulException(com.netflix.zuul.exception.ZuulException) IOException(java.io.IOException)

Example 19 with ZuulException

use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.

the class Gzipper method finish.

public void finish() throws RuntimeException {
    try {
        gzos.finish();
        gzos.flush();
        gzos.close();
    } catch (IOException ioEx) {
        throw new ZuulException(ioEx, "Error finalizing the GzipOutputStream", true);
    }
}
Also used : ZuulException(com.netflix.zuul.exception.ZuulException) IOException(java.io.IOException)

Example 20 with ZuulException

use of com.netflix.zuul.exception.ZuulException in project zuul by Netflix.

the class MissingEndpointHandlingFilter method apply.

@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);
}
Also used : HttpResponseMessageImpl(com.netflix.zuul.message.http.HttpResponseMessageImpl) SessionContext(com.netflix.zuul.context.SessionContext) ZuulException(com.netflix.zuul.exception.ZuulException)

Aggregations

ZuulException (com.netflix.zuul.exception.ZuulException)22 RequestContext (com.netflix.zuul.context.RequestContext)5 IOException (java.io.IOException)4 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)3 CompleteReason (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)3 SessionContext (com.netflix.zuul.context.SessionContext)3 HttpContent (io.netty.handler.codec.http.HttpContent)3 ClientException (com.netflix.client.ClientException)2 SESSION_COMPLETE (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason.SESSION_COMPLETE)2 OutboundException (com.netflix.zuul.exception.OutboundException)2 ProxyEndpoint (com.netflix.zuul.filters.endpoint.ProxyEndpoint)2 HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)2 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)2 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)2 HttpResponseMessageImpl (com.netflix.zuul.message.http.HttpResponseMessageImpl)2 ChannelUtils (com.netflix.zuul.netty.ChannelUtils)2 PassportState (com.netflix.zuul.passport.PassportState)2 ZuulStatusCategory (com.netflix.zuul.stats.status.ZuulStatusCategory)2 Channel (io.netty.channel.Channel)2 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)2