Announcement Announcement Module
Collapse
No announcement yet.
CLIENT IP address from spring webservices? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • CLIENT IP address from spring webservices?

    Dear team,

    How to retrieve client ip address from @RequestPayload in spring webservice?



    Thanks,
    selva

  • #2
    You can do it only using
    Code:
    ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpServletRequest request = attrs.getgetRequest();
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
     if (ipAddress == null)  {    
           ipAddress = request.getRemoteAddr();
       }
    There is no hooks to get deal with transport specific options from @RequestPayload

    Comment


    • #3
      Thanks for your reply. i have return below code to get client ip address.

      protected HttpServletRequest getHttpServletRequest() {
      TransportContext ctx = TransportContextHolder.getTransportContext();
      return ( null != ctx ) ? ((HttpServletConnection ) ctx.getConnection()).getHttpServletRequest() : null;
      }

      Comment

      Working...
      X