在JBoss Web服务中获取IP地址 [英] Get IP address in JBoss Web Service

查看:251
本文介绍了在JBoss Web服务中获取IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用唯一的方法开发了一个Java类,并使用JBossWS转换为Web服务(JBOSS).我想获取发起请求的客户端的IP地址. (我没有使用jsp)

I developed a java class with an only method and turned into web service (JBOSS) using JBossWS. I would like to get the IP address of the client who started the request. (I'm not using jsp)

public String getMyIP() {
  //get IP from client from current request
  // return IP as String
}

谢谢!

推荐答案

已解决!

首先在课程中设置此资源:

First set this resource in the class:

@Resource
WebServiceContext wsContext;

然后在您的课程上使用以下代码:

Then use this code on your class:

SOAPMessageContext jaxwsContext = (SOAPMessageContext)wsContext.getMessageContext();
HttpServletRequest request = HttpServletRequest)jaxwsContext.get(SOAPMessageContext.SERVLET_REQUEST);
String ipAddress = request.getRemoteAddr();

这篇关于在JBoss Web服务中获取IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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