How can you get the calling ip address on an ejb call?

后端 未结 4 1135
失恋的感觉
失恋的感觉 2020-12-19 22:23

If a java client calls a remote EJB on a different server, how can you get the client IP address? Note that it is important to get it from the server, because the client is

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 22:41

    This article on the JBoss community wiki addresses exactly your issue. Prior to JBoss 5 the IP address apparently has to be parsed from the worker thread name. And that seems to be the only way to do it on earlier versions. This is the code snippet doing it (copied from the above link):

    private String getCurrentClientIpAddress() {
        String currentThreadName = Thread.currentThread().getName();
        System.out.println("Threadname: "+currentThreadName);
        int begin = currentThreadName.indexOf('[') +1;
        int end = currentThreadName.indexOf(']')-1;
        String remoteClient = currentThreadName.substring(begin, end);
        return remoteClient;
    }
    

提交回复
热议问题