jakartaee / servlet

Jakarta Servlet
https://eclipse.org/ee4j/servlet
Other
253 stars 81 forks source link

HttpServletRequest Has method newPushBuilder giving null #552

Closed rakesh-sahani closed 9 months ago

rakesh-sahani commented 9 months ago

I found the one bug while working with Jakarta servlet or web. When will try to access the HttpServletRequest has the newPushBuilder method always gives null object. If you will satisfied the condition but object remains the null

I did the same either using filter or interceptor as well and also tomcat but still fails .Please share the example or implementation ways so I will try this

Sharing the code I want to attach a header to the request whenever it comes to the system. I found out that the pushBuilder interface can be used to achieve this requirement.

Therefore to do a poc, I created a springboot app using java 17 and tomcat version 10.1.14 as embedded server.

I create a rest api as below

@GetMapping("/hello") public String getGreetings() { return "hello world"; }

To filter the request coming on this endpoint, I registered a filter component as @Component public class CustomFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) servletRequest; PushBuilder pushBuilder = req.newPushBuilder();

    if(pushBuilder != null) {
        pushBuilder.path("hello");
        pushBuilder.setHeader("system_id", "123");
        pushBuilder.push();
    }

    filterChain.doFilter(servletRequest, servletResponse);
}

} As per the documentation, We enabled the http2 and used the coyote protocol and a self-signed SSL certificate. below are the properties overridden in application.properties

server.http2.enabled=true server.tomcat.protocol=org.apache.coyote.http2.Http2Protocol server.port=8443 server.ssl.key-store=keystore.pfx server.ssl.key-store-password=password server.ssl.key-password=password security.require-ssl=true

After doing all this I am still unable to create a pushBuilder object whenever I hit the api

P.S please share the correct implementation or guide

markt-asf commented 9 months ago

Again, you need to raise this with the provider of the Servlet container (Tomcat) you are using.