How to get ip adress and port in web service

荒凉一梦 提交于 2019-12-11 03:45:23

问题


I have spring-ws deployed in my server. There is some task every day which should write ip adress and the port of server where this application run. How I can get this information ? I try InetAddress but with no success. There is no port.


回答1:


Getting a hold of the servletRequest should be enough to put you on track to get the IP address.

TransportContext ctx = TransportContextHolder.getTransportContext();
HttpServletConnection conn = (HttpServletConnection )ctx.getConnection();
HttpServletRequest request = conn.getHttpServletRequest();

Use this code in an interceptor defined on your ws. Now you can simply call

request. getRemoteAddr();

to get the IP.



来源:https://stackoverflow.com/questions/9114141/how-to-get-ip-adress-and-port-in-web-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!