Netflix / zuul

Zuul is a gateway service that provides dynamic routing, monitoring, resiliency, security, and more.
Apache License 2.0
13.52k stars 2.38k forks source link

needsBodyBuffered() causes NullPointerException #520

Closed danesavot closed 1 week ago

danesavot commented 6 years ago

I've got NulPointerException thrown when enabling needsBodyBufferred() with the following stack trace:

java.lang.NullPointerException
    at com.netflix.zuul.netty.filter.BaseZuulFilterRunner.initRunningFilterIndex(BaseZuulFilterRunner.java:88)
    at com.netflix.zuul.netty.filter.ZuulFilterChainRunner.filter(ZuulFilterChainRunner.java:52)
    at com.netflix.zuul.netty.filter.BaseZuulFilterRunner.invokeNextStage(BaseZuulFilterRunner.java:122)
    at com.netflix.zuul.netty.filter.ZuulEndPointRunner.filter(ZuulEndPointRunner.java:137)
    at com.netflix.zuul.netty.filter.ZuulEndPointRunner.filter(ZuulEndPointRunner.java:49)
    at com.netflix.zuul.netty.filter.BaseZuulFilterRunner.invokeNextStage(BaseZuulFilterRunner.java:112)
    at com.netflix.zuul.netty.filter.ZuulFilterChainRunner.filter(ZuulFilterChainRunner.java:115)
    at com.netflix.zuul.netty.filter.ZuulFilterChainHandler.channelRead(ZuulFilterChainHandler.java:84)

Ex:

public class GitHubEndpoint extends HttpAsyncEndpoint {

    @Override
    public Observable<HttpResponseMessage> applyAsync(HttpRequestMessage request) {

        return GitHubService.listRepos("danesavot");

    @Override
    public boolean needsBodyBuffered(HttpRequestMessage input) {
        return true;
    }
}
artgon commented 6 years ago

You can't buffer a body on an Endpoint filter. What are you trying to do on that endpoint?

rafaelGuerreiro commented 4 years ago

I'm having the exact same problem.

I needed an Async endpoint, which I think Zuul2 doesn't provide, and it needs to read the body of the request.

I also tried copying the workflow from Zuul's HttpSyncEndpoint, but they still cause the body to be unavailable to my endpoint.

@danesavot do you have any workaround that you implemented? As this issue is almost 2 years old, now.

danesavot commented 4 years ago

Yeah, i think I have. You need to create an InBoundFilter and override needsBodyBuffered() there so that Zull will buffer the body for the Endpoint and avoid above NPE. Let me know if you need further clarification :)

rafaelGuerreiro commented 4 years ago

Thank you @danesavot, it works like a charm.

Just to provide more context to Zuul's team of why this is needed: I have a framework that I made it use Observable to be able to use it in the filters. But some of the Proxy operations require the Proxy itself to access and persist the information, and I'd love to see it using the same framework.

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 week ago

This issue was closed because it has been stalled for 7 days with no activity.