Skip to content

Instantly share code, notes, and snippets.

@cnmoro
Created November 8, 2018 22:16
Show Gist options
  • Save cnmoro/c0070779f2acc6f8bda0544fcee56b44 to your computer and use it in GitHub Desktop.
Save cnmoro/c0070779f2acc6f8bda0544fcee56b44 to your computer and use it in GitHub Desktop.
Java WS Get Client IP
Import:
import javax.servlet.http.HttpServletRequest;
Maven dependency:
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Endpoint method - Annotation param:
public String method(@Context HttpServletRequest req)
Get ip:
req.getRemoteAddr();
Get port:
req.getRemotePort();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment