webservice获取客户端ip

 

自用:

 


import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.xml.internal.ws.developer.JAXWSProperties;

 

 

 @Resource
 private WebServiceContext wsContext;
 
 private void getClientInfo() {
  try {
   MessageContext mc = wsContext.getMessageContext();
   HttpExchange exchange = (HttpExchange) mc.get(JAXWSProperties.HTTP_EXCHANGE);
   InetSocketAddress isa = exchange.getRemoteAddress();
   System.out.println("InetSocketAddress : " + isa);
   System.out.println("Hostname : " + isa.getAddress().getHostName()
     + " address: " + isa.getAddress().getHostAddress());
  } catch (Exception e) {
   log.error(e.getMessage(), e);
  }

 }

 

 

你可能感兴趣的:(webservice获取客户端ip)