apache tomcat 8 websocket origin and client address

有些话、适合烂在心里 提交于 2019-12-13 18:15:42

问题


H.e.l.l.o community, i hope someone can help me ... i am using apache tomcat 8.0.0-RC5 and JSR-356 web socket API ... I have 2 questions:

1) Is it possible to get the client ip on @OnOpen method ??

2) Is it possible to get the origin of the connection ???

I followed the websocket example which comes with the distribution of tomcat and i was not able to find the answers .... My java class is basically as follow

@ServerEndpoint(value = "/data.socket")
public class MyWebSocket {
    @OnOpen
    public void onOpen(Session session) {
        // Here is where i need the origin and remote client address
    }

    @OnClose
    public void onClose() {
        // disconnection handling
    }

    @OnMessage
    public void onMessage(String message) {
        // message handling
    }

    @OnError
    public void onError(Session session, Throwable throwable) {
        // Error handling
    }
}

回答1:


Repeating the answer I already gave you on the Tomcat users mailing list...

Client IP. No. Generally this type of information is available at the handshake which occurs before OnOpen but client IP is not one of the pieces of information exposed. You might be better blocking these earlier e.g. with iptables or similar.

Origin. ServerEndpointConfig.Configurator.checkOrigin(String) You'll need a custom Configurator. Keep in mind that a malicious client can forge the origin header.



来源:https://stackoverflow.com/questions/19624012/apache-tomcat-8-websocket-origin-and-client-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!