JAVA 1.6 生成的webService 纯JAVA工程获取请求IP方法
在WebService 的发布的代理类:
@Resource
private WebServiceContext wsContext;
@WebMethod(exclude=true)
public String getClientIp(){
javax.xml.ws.handler.MessageContext mc = wsContext.getMessageContext();
com.sun.net.httpserver.HttpExchange exchange = (HttpExchange)mc.get("com.sun.xml.internal.ws.http.exchange");
InetSocketAddress isa = exchange.getRemoteAddress();
InetAddress address = isa.getAddress();
String hostAddress = address.getHostAddress();
return hostAddress;
}