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; }

 

posted @ 2017-07-17 14:43  无知死循环  阅读(1974)  评论(0编辑  收藏  举报