-2

If I run Tomcat 7 with Java 6, the HttpServletRequest.getRemoteAddr() method returns the IP address as I would expect.

If I run Tomcat 8 with Java 8, the same method returns an empty string.

The X-Forwarded-For header is also null in both scenarios.

The messages are sent via websockets with Atmosphere.

Also, remoteHost() and remoteUser() are both empty as well.

Zack
  • 21
  • 1
  • 4
  • You have not provided enough information. Also, if you had bothered to type `HttpServletRequest.getRemoteAddr returns null` into a search engine you would have seen lots of hits. – Jim Garrison Mar 21 '16 at 21:47
  • Yea I searched for like an hour and none of them answer my question about the only difference being tomcat/java version. So thanks, you've been so helpful. – Zack Mar 22 '16 at 13:34

1 Answers1

1

JSR-356 Websocket specification does not expose the client IP which is why HttpServletRequest.getRemoteAddr() returns null.

This also explains why HttpServletRequest.getRemoteAddr() returns an empty string or 0.0.0.0 depending on the version of Atmosphere you are using because Atmosphere alters the HttpServletRequest.

Although the Tomcat 7 documentation on Websockets states "Tomcat implements the Java WebSocket 1.1 API defined by JSR-356", when I run Tomcat version 7.0.68, which is the current Tomcat 7 version, HttpServletRequest.getRemoteAddr() still returns the client IP address via websocket. This is true when I run Tomcat with Java 6, 7, or 8.

The Tomcat 8 documentation on Websockets also states "Tomcat implements the Java WebSocket 1.1 API defined by JSR-356" and when running the same application on Tomcat 8 that I ran on 7, HttpServletRequest.getRemoteAddr() returns an empty string.

Zack
  • 21
  • 1
  • 4