如何在ejb通话中获取主叫的IP地址? [英] How can you get the calling ip address on an ejb call?

查看:163
本文介绍了如何在ejb通话中获取主叫的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果java客户端在不同的服务器上调用远程EJB,那么如何获取客户端的IP地址?请注意,从服务器获取它很重要,因为客户端可能位于NAT防火墙后面,在这种情况下,我们需要公共IP地址。

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 likely behind a NAT firewall, and in this case we need the public IP address.

注意:虽然它最好是一个通用的解决方案,至少我可以使用一个从JBoss 4.2.2上的EJB2调用中检索IP地址的消息。

NOTE: Although it would preferably be a generic solution, at a minimum I could use one that retrieves the IP address from an EJB2 call on JBoss 4.2.2

推荐答案

关于JBoss社区wiki的本文解决了您的问题。在JBoss 5之前,IP地址显然必须从工作线程名解析。而这似乎是在早期版本上做到这一点的唯一方法。这是代码片段(从上面的链接复制):

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;
}

这篇关于如何在ejb通话中获取主叫的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆