I have a REST Service that receives an HttpServletRequest and I need to load the session cookies for this object. If there is no change, I can load by the name which is JSESSIONID, but this name can be changed in the context.xml as it is in the example.
<Context sessionCookieName="CUSTOMSESSIONID">
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>
public List<Cookie> collectCookies(HttpServletRequest request) {
if (request.getCookies() != null) {
final List<Cookie> cookiesList = Arrays.asList(request.getCookies());
return cookiesList.stream()
.filter(
cookie ->
"JSESSIONID".equals(cookie.getName())
|| "ApplicationGatewayAffinity".equals(cookie.getName()))
.collect(Collectors.toList());
}
return new ArrayList<>();
}
What service can / should I use in order to know what name is being used for the session cookie?
Thanks for your help.