Search in sources :

Example 41 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class ProxyEndpoint method massageRequestURI.

private static HttpRequestMessage massageRequestURI(HttpRequestMessage request) {
    final SessionContext context = request.getContext();
    String modifiedPath;
    HttpQueryParams modifiedQueryParams = null;
    String uri = null;
    if (context.get("requestURI") != null) {
        uri = (String) context.get("requestURI");
    }
    // If another filter has specified an overrideURI, then use that instead of requested URI.
    final Object override = context.get("overrideURI");
    if (override != null) {
        uri = override.toString();
    }
    if (null != uri) {
        int index = uri.indexOf('?');
        if (index != -1) {
            // Strip the query string off of the URI.
            String paramString = uri.substring(index + 1);
            modifiedPath = uri.substring(0, index);
            try {
                paramString = URLDecoder.decode(paramString, "UTF-8");
                modifiedQueryParams = new HttpQueryParams();
                StringTokenizer stk = new StringTokenizer(paramString, "&");
                while (stk.hasMoreTokens()) {
                    String token = stk.nextToken();
                    int idx = token.indexOf("=");
                    if (idx != -1) {
                        String key = token.substring(0, idx);
                        String val = token.substring(idx + 1);
                        modifiedQueryParams.add(key, val);
                    }
                }
            } catch (UnsupportedEncodingException e) {
                LOG.error("Error decoding url query param - " + paramString, e);
            }
        } else {
            modifiedPath = uri;
        }
        request.setPath(modifiedPath);
        if (null != modifiedQueryParams) {
            request.setQueryParams(modifiedQueryParams);
        }
    }
    return request;
}
Also used : StringTokenizer(java.util.StringTokenizer) HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) SessionContext(com.netflix.zuul.context.SessionContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 42 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class ZuulFilterChainHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOG.error("zuul filter chain handler caught exception. cause=" + String.valueOf(cause), cause);
    if (zuulRequest != null && !isClientChannelClosed(cause)) {
        final SessionContext zuulCtx = zuulRequest.getContext();
        zuulCtx.setError(cause);
        zuulCtx.setShouldSendErrorResponse(true);
        sendResponse(FAILURE_LOCAL, 500, ctx);
    } else {
        fireEndpointFinish(true);
        ctx.close();
    }
}
Also used : SessionContext(com.netflix.zuul.context.SessionContext)

Example 43 with SessionContext

use of com.netflix.zuul.context.SessionContext in project zuul by Netflix.

the class ZuulFilterChainHandler method sendResponse.

private void sendResponse(final StatusCategory statusCategory, final int status, ChannelHandlerContext ctx) {
    if (zuulRequest == null) {
        ctx.close();
    } else {
        final SessionContext zuulCtx = zuulRequest.getContext();
        StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulCtx, statusCategory);
        final HttpResponseMessage zuulResponse = new HttpResponseMessageImpl(zuulCtx, zuulRequest, status);
        final Headers headers = zuulResponse.getHeaders();
        headers.add("Connection", "close");
        headers.add("Content-Length", "0");
        zuulResponse.finishBufferedBodyIfIncomplete();
        responseFilterChain.filter(zuulResponse);
        fireEndpointFinish(true);
    }
}
Also used : HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) Headers(com.netflix.zuul.message.Headers) HttpResponseMessageImpl(com.netflix.zuul.message.http.HttpResponseMessageImpl) SessionContext(com.netflix.zuul.context.SessionContext)

Aggregations

SessionContext (com.netflix.zuul.context.SessionContext)43 Test (org.junit.Test)23 Headers (com.netflix.zuul.message.Headers)16 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)6 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)5 HttpResponseMessageImpl (com.netflix.zuul.message.http.HttpResponseMessageImpl)5 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)5 HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)4 InetSocketAddress (java.net.InetSocketAddress)4 ClientException (com.netflix.client.ClientException)3 ZuulException (com.netflix.zuul.exception.ZuulException)3 HttpRequestMessageImpl (com.netflix.zuul.message.http.HttpRequestMessageImpl)3 StatusCategory (com.netflix.zuul.stats.status.StatusCategory)3 ByteBuf (io.netty.buffer.ByteBuf)3 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)3 ErrorType (com.netflix.zuul.exception.ErrorType)2 OutboundException (com.netflix.zuul.exception.OutboundException)2 ZuulMessage (com.netflix.zuul.message.ZuulMessage)2 ZuulMessageImpl (com.netflix.zuul.message.ZuulMessageImpl)2 CurrentPassport (com.netflix.zuul.passport.CurrentPassport)2