atmosphere icon indicating copy to clipboard operation
atmosphere copied to clipboard

[websocket][tomcat] org.atmosphere.cpr.AtmosphereRequest.getRemoteAddr() returns empty string

Open hapali opened this issue 13 years ago • 9 comments

org.atmosphere.cpr.AtmosphereRequest.getRemoteAddr() returns empty string instead of correct address.

atmosphere-runtime 1.0.4

hapali avatar Dec 07 '12 10:12 hapali

@hapali Which server? I suspect you are using Tomcat behind Apache, and that's a known issue (see Tomcat site)

jfarcand avatar Dec 07 '12 14:12 jfarcand

no apache, just tomcat 7.0.33 with blocking io connector

hapali avatar Dec 07 '12 22:12 hapali

Using WebSocket?

jfarcand avatar Dec 07 '12 22:12 jfarcand

yes, websockets

hapali avatar Dec 07 '12 22:12 hapali

apache-tomcat-8.0.21 & atmosphere-websockethandler-pubsub-2.3.0

@WebSocketHandlerService (path ="/pubsub", broadcaster = SimpleBroadcaster.class)
public class WebSocketPubSub extends WebSocketHandlerAdapter {
public void onOpen(WebSocket webSocket) throws IOException {
        System.out.println(webSocket.resource().getRequest().getRemoteAddr());
}
}

getRemoteAddr() return "0.0.0.0", cannot get the correct ip...

KeymanHuang avatar May 08 '15 11:05 KeymanHuang

Tomcat doesn't expose those values, here it won't work with Tomcat. Works with Jetty.

jfarcand avatar May 08 '15 12:05 jfarcand

Hi Jeanfrancois!

We ran into the same problem but we can't switch to Jetty or something else. We need to log the ip addresses, so what is the best way to do it? All @ Ready events need to be logged and we use a @ ManagedService.

tomcat version: 8.0.23 atmosphere version: 2.3.0

d03090 avatar Sep 01 '15 14:09 d03090

@d03090 You will need to write a Tomcat's valve, log the ip from there and retrieve it as a request's attributes in Atmosphere. That's the kind of work Async-IO is doing...it will requires a couples of hours of work to 'fix' Tomcat. The alternative is you file a bug in Tomcat so they fix it, event if the spec is unclear about it. Butthe Valve approach is the easiest and fastest IMO.

jfarcand avatar Sep 01 '15 14:09 jfarcand

@jfarcand I have the same problem with Atmosphere 2.4.2 and Tomcat 8.0.22. When I do:

resource.getRequest().getRemoteAddr()

I always get an empty address.

drmichaelgorski avatar Jan 14 '16 09:01 drmichaelgorski