Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get remote ip and location on liferay porlets

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()
like image 733
IConfused Avatar asked Nov 12 '22 11:11

IConfused


1 Answers

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

like image 157
Miroslav Ligas Avatar answered Nov 24 '22 00:11

Miroslav Ligas