webservice获取ip地址
webservice客户端访问,服务端获取客户端ip地址。
import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.MessageContext; import org.apache.cxf.jaxws.context.WebServiceContextImpl; import javax.servlet.http.HttpServletRequest; import org.apache.cxf.transport.http.AbstractHTTPDestination; public String getIpAddress() { WebServiceContext context = new WebServiceContextImpl(); MessageContext ctx = context.getMessageContext(); HttpServletRequest request = (HttpServletRequest) ctx.get(AbstractHTTPDestination.HTTP_REQUEST); String userIp = request.getRemoteAddr();
return userIp; }