io.spotnext.spring.web.util.RequestUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spot-spring-web-support Show documentation
Show all versions of spot-spring-web-support Show documentation
The spOt microservice framework.
package io.spotnext.spring.web.util;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
/**
* RequestUtil class.
*
* @author mojo2012
* @version 1.0
* @since 1.0
*/
public class RequestUtil {
/**
* Returns the current spring {@link javax.servlet.http.HttpServletRequest} or null.
*
* @return a {@link javax.servlet.http.HttpServletRequest} object.
*/
public static HttpServletRequest getCurrentHttpRequest() {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
final HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
return request;
}
return null;
}
}