WICKET: how to get client ip / address

I use wickets 1.5.1, I could not understand this.

public class MyPage extends WebPage { public MyPage() { String clientAddress = ...? 
+6
source share
3 answers
  WebRequest req = (WebRequest) RequestCycle.get().getRequest(); HttpServletRequest httpReq = (HttpServletRequest) req.getContainerRequest(); String clientAddress = httpReq.getRemoteHost(); 
+15
source

Subclass WebClientInfo , to provide a public method that delegates to secure WebClientInfo.getRemoteAddr() . Then create a method for the request in the custom class RequestCycle . In Wicket 1.3-1.4, I achieved this by subclassing RequestCycle , but since 1.5 it seems like everything is different: RequestCycle in Wicket 1.5

WebClientInfo has the advantage of requesting the X-Forwarded-For erquest parameter and returning the correct IP address if your server is behind a proxy / load balancer that uses XFF .

+3
source

Using Wicket 6 and 7, you can do the following:

 String remoteAddress = ((WebClientInfo)Session.get().getClientInfo()) .getProperties() .getRemoteAddress(); 
+2
source

Source: https://habr.com/ru/post/899303/


All Articles