I am using Spring annotations, I can pass the HttpRequestContext from the Controller to the Service.
I am looking for a static way or any better soluti
In response to @andrebrait comments above "Or the Java 8 way", the methods are present on the ServletRequestAttributes.class
public static Optional getCurrentHttpRequest() {
return
Optional.ofNullable(
RequestContextHolder.getRequestAttributes()
)
.filter(ServletRequestAttributes.class::isInstance)
.map(ServletRequestAttributes.class::cast)
.map(ServletRequestAttributes::getRequest);
}