code:
--------------------------------------------------------------------------------
I'm trying to get " HttpServletRequest" object and then "remoteAddr()" method.
How can I get access to my HttpServletRequest, form within a normal
java class, not in
servlet class itself.
Here is the code I tried to use,
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest();
String rhost = request.getRemoteHost();
String raddr = request.getRemoteAddr();
int rport = request.getRemotePort();
String lhost = request.getLocalName();
String laddr = request.getLocalAddr();
int lport = request.getLocalPort();
}
I am using
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
but here the
ServletRequestAttributes.getRequest(); is protected!
I need some guidance here!
thanks!
--------------------------------------------------------------------------------