I am using ubuntu 12.04, liferay version 6.0.1, open jdk 6 on my system. I was trying to get remote ip and location in java. For this I have found Host Ip service by which using apache http get method we can get the location. I have executed this successfully on my local system. But On the actual server the liferay portlet is not running and its hard to find the error as multiple instances are running at the same time. The server is a Window based. I am using this method in a doView() of a MVC Portlet to get ip
com.liferay.portal.util.PortalUtil.getHttpServletRequest(renderRequest).getRemoteAddr()
When I wan't to access http header info I use:
HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest);
HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(httpServletRequest);
originalServletRequest.getRemoteAddr();
Usually you cant find the real header information in the httpServletRequest but they are available in the originalServletRequest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With