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
I believe that name of the current worker thread contains an IP address of the server, but not the client's IP since threads are pooled rather than created for each call. In JBoss 4, one can use the following workaround to obtain an IP address of the client:
try {
//Reflection is used to avoid compile-time dependency on JBoss internal libraries
Class clazz = Class.forName("org.jboss.web.tomcat.security.HttpServletRequestPolicyContextHandler");
Field requestContextField = clazz.getDeclaredField("requestContext");
requestContextField.setAccessible(true);
ThreadLocal ctx = (ThreadLocal) requestContextField.get(null);
ServletRequest req = ((ServletRequest) ctx.get());
return req==null?null:req.getRemoteAddr();
} catch (Exception e) {
LOG.log(Level.WARNING, "Failed to determine client IP address",e);
}