I have this function to get the HostAddress from my request (HttpServletRequest) on Java. But using Jetty 7.x and my IP is ipV6 I have always this error with iPv6 address.
My function:
xxxx.getIP(request, false);
public static String getIP(HttpServletRequest request, boolean proxy) {
String ip = "";
log.debug("X-getHeaderNames ["+ request.getHeaderNames()+"]");
if (proxy) {
ip = XFordwardedInetAddressUtil.getAddressFromRequest(request);
} else {
String _ip = request.getRemoteAddr();
ip = InetAddresses.forString(_ip).getHostAddress();
}
return ip;
}
The error:
DEBUG: org.encuestame.core.exception.EnMeMappingExceptionResolver - Resolving exception from handler [org.encuestame.mvc.controller.TweetPollController@4fc23996]: java.lang.IllegalArgumentException: '0:0:0:0:0:0:0:1%0' is not an IP string literal. java.lang.IllegalArgumentException: '0:0:0:0:0:0:0:1%0' is not an IP string literal. at org.encuestame.utils.net.InetAddresses.forString(InetAddresses.java:59) at org.encuestame.core.util.EnMeUtils.getIP(EnMeUtils.java:210) at org.encuestame.mvc.controller.AbstractBaseOperations.getIpClient(AbstractBaseOperations.java:262) at org.encuestame.mvc.controller.TweetPollController.detailTweetPollController(TweetPollController.java:332) at org.encuestame.mvc.controller.TweetPollController$$FastClassByCGLIB$$6990b004.invoke() at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedIntercepto
I know the iPv6 localhost format should be '0:0:0:0:0:0:0:1' but my request always return this string '0:0:0:0:0:0:0:1%0'
Anyone can help me?