在无状态 EJB 中获取客户端 IP
Get Client IP in Stateless EJB
我有无状态 EJB Web 服务。
WS 接口:
@Remote
@WebService
public interface WSInterface{
@WebMethod
public String[] WSMethod(@WebParam(name="arg0") String arg0)
}
WS 实施:
@WebService
@Stateless
public class WSImpl extends GenericSessionBean implements WSInterface {
@WebMethod
public String[] WSMethod( String arg0)
{
return ...;
}
}
而且我需要在 WSMethod 中获取客户端 IP。
我试图通过这种方式获取它(它适用于 "common" 网络服务):
@Resource
private SessionContext ctx;
public String[] getProperties() {
List propList = new ArrayList();
MessageContext mc = ctx.getMessageContext();
Iterator props = mc.getPropertyNames();
for (String prop = (String)props.next(); props.hasNext(); prop = (String)props.next())
{ propList.add(prop); }
return propList.toArray(new String[propList.size()]);
}
但没有成功:在 MessageContext
.
中没有名称为 REMOTE_ADDR
的 属性
有没有办法在 @Stateless
EJB 中获取 REMOTE_ADDR
?
您可以尝试使用@Resource 获取WebServiceContext 而不是SessionContext 吗?我现在没有合适的环境来检查它
我有无状态 EJB Web 服务。
WS 接口:
@Remote
@WebService
public interface WSInterface{
@WebMethod
public String[] WSMethod(@WebParam(name="arg0") String arg0)
}
WS 实施:
@WebService
@Stateless
public class WSImpl extends GenericSessionBean implements WSInterface {
@WebMethod
public String[] WSMethod( String arg0)
{
return ...;
}
}
而且我需要在 WSMethod 中获取客户端 IP。 我试图通过这种方式获取它(它适用于 "common" 网络服务):
@Resource
private SessionContext ctx;
public String[] getProperties() {
List propList = new ArrayList();
MessageContext mc = ctx.getMessageContext();
Iterator props = mc.getPropertyNames();
for (String prop = (String)props.next(); props.hasNext(); prop = (String)props.next())
{ propList.add(prop); }
return propList.toArray(new String[propList.size()]);
}
但没有成功:在 MessageContext
.
REMOTE_ADDR
的 属性
有没有办法在 @Stateless
EJB 中获取 REMOTE_ADDR
?
您可以尝试使用@Resource 获取WebServiceContext 而不是SessionContext 吗?我现在没有合适的环境来检查它