Issue
We have a Web application with following technologies: Java, SpringBoot, Docker, Microservices, Jhipster. The port number for the frontend container is 80.
I am trying to disable keep alive option for the frontend microservice because SSO Authentication Server requires this parameter set to be false.
I tried to create the front container with maven : mvn -Pqpm,no-liquibase -Dhttp.keepAlive=false clean verify jib:dockerBuild
I also tried to disable in pom.xml of the front container :
<http.keepAlive>false</http.keepAlive>
<https.keepAlive>false</https.keepAlive>
But the keep-alive option remains enabled when I send a http request :
Connecting to qwerty.xyz|10.10.219.200|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Date: Mon, 06 Apr 2020 21:14:50 GMT
Server: Apache
Last-Modified: Fri, 21 Oct 2016 08:42:15 GMT
ETag: "4107-84-53f5c04e1c7c0"
Accept-Ranges: bytes
Content-Length: 132
Cache-Control: max-age=0, no-store
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
Length: 132 [text/html]
Saving to: `/dev/null'
0K 100% 15.7M=0s
2020-04-06 23:14:50 (15.7 MB/s) - `/dev/null' saved [132/132]
My Springboot config:
<!-- Dependency versions -->
<jhipster-dependencies.version>3.0.1</jhipster-dependencies.version>
<!-- The spring-boot version should match the one managed by
https://mvnrepository.com/artifact/io.github.jhipster/jhipster-dependencies/${jhipster-dependencies.version} -->
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
Could you please help me to disable it ?
Solution
I finally found a solution. The way we did this was to implement a filter and add this filter to SecurityConfig.config method.
KeepAliveFilter.java
public class KeepAliveFilter implements Filter {
public void init(final FilterConfig filterConfig) { }
public void destroy() { }
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Connection", "close");
chain.doFilter(request, response);
}
}
SecurityConfiguration.java
private final KeepAliveFilter keepAliveFilter;
public SecurityConfiguration(final KeepAliveFilter keepAliveFilter, ...)
{
this.keepAliveFilter = keepAliveFilter;
...
// other property
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.addFilterBefore(corsFilter, CsrfFilter.class)
.addFilterBefore(keepAliveFilter, CsrfFilter.class)
;
}
Answered By - Deev Laupper