Search in sources :

Example 21 with SessionContext

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

the class OriginTimeoutManagerTest method before.

@Before
public void before() {
    originTimeoutManager = new OriginTimeoutManager(origin);
    context = new SessionContext();
    when(request.getContext()).thenReturn(context);
    requestConfig = new DefaultClientConfigImpl();
    originConfig = new DefaultClientConfigImpl();
    context.put(CommonContextKeys.REST_CLIENT_CONFIG, requestConfig);
    when(origin.getClientConfig()).thenReturn(originConfig);
}
Also used : SessionContext(com.netflix.zuul.context.SessionContext) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Before(org.junit.Before)

Example 22 with SessionContext

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

the class ClientRequestReceiver method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof CompleteEvent) {
        final CompleteReason reason = ((CompleteEvent) evt).getReason();
        if (zuulRequest != null) {
            zuulRequest.getContext().cancel();
            zuulRequest.disposeBufferedBody();
            final CurrentPassport passport = CurrentPassport.fromSessionContext(zuulRequest.getContext());
            if ((passport != null) && (passport.findState(PassportState.OUT_RESP_LAST_CONTENT_SENT) == null)) {
                // Only log this state if the response does not seem to have completed normally.
                passport.add(PassportState.IN_REQ_CANCELLED);
            }
        }
        if (reason == CompleteReason.INACTIVE && zuulRequest != null) {
            // Client closed connection prematurely.
            StatusCategoryUtils.setStatusCategory(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_CANCELLED);
        }
        if (reason == CompleteReason.PIPELINE_REJECT && zuulRequest != null) {
            StatusCategoryUtils.setStatusCategory(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_PIPELINE_REJECT);
        }
        if (reason != SESSION_COMPLETE && zuulRequest != null) {
            final SessionContext zuulCtx = zuulRequest.getContext();
            if (clientRequest != null) {
                if (LOG.isInfoEnabled()) {
                    // thats ok, so don't log in that case.
                    if (!"HTTP/2".equals(zuulRequest.getProtocol())) {
                        LOG.debug("Client {} request UUID {} to {} completed with reason = {}, {}", clientRequest.method(), zuulCtx.getUUID(), clientRequest.uri(), reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
                    }
                }
            }
            if (zuulCtx.debugRequest()) {
                LOG.debug("Endpoint = {}", zuulCtx.getEndpoint());
                dumpDebugInfo(Debug.getRequestDebug(zuulCtx));
                dumpDebugInfo(Debug.getRoutingDebug(zuulCtx));
            }
        }
        if (zuulRequest == null) {
            Spectator.globalRegistry().counter("zuul.client.complete.null", "reason", String.valueOf(reason)).increment();
        }
        clientRequest = null;
        zuulRequest = null;
    }
    super.userEventTriggered(ctx, evt);
    if (evt instanceof CompleteEvent) {
        final Channel channel = ctx.channel();
        channel.attr(ATTR_ZUUL_REQ).set(null);
        channel.attr(ATTR_ZUUL_RESP).set(null);
        channel.attr(ATTR_LAST_CONTENT_RECEIVED).set(null);
    }
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) Channel(io.netty.channel.Channel) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) SessionContext(com.netflix.zuul.context.SessionContext) CompleteReason(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)

Example 23 with SessionContext

use of com.netflix.zuul.context.SessionContext 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)

Example 24 with SessionContext

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

the class ZuulMessageImplTest method testSetBodyGetBody.

@Test
public void testSetBodyGetBody() {
    final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
    msg.setBody(TEXT1.getBytes());
    final String body = new String(msg.getBody());
    assertEquals(TEXT1, body);
    assertEquals(1, msg.getHeaders().getAll("Content-Length").size());
    assertEquals(String.valueOf(TEXT1.length()), msg.getHeaders().getFirst("Content-Length"));
}
Also used : SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

Example 25 with SessionContext

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

the class ZuulMessageImplTest method testBufferBody2GetBody.

@Test
public void testBufferBody2GetBody() {
    final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
    msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("Hello ".getBytes())));
    msg.bufferBodyContents(new DefaultLastHttpContent(Unpooled.copiedBuffer("World!".getBytes())));
    final String body = new String(msg.getBody());
    assertTrue(msg.hasBody());
    assertTrue(msg.hasCompleteBody());
    assertEquals("Hello World!", body);
    assertEquals(0, msg.getHeaders().getAll("Content-Length").size());
}
Also used : DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) SessionContext(com.netflix.zuul.context.SessionContext) Test(org.junit.Test)

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