hudi
hudi

Reputation: 16525

How to get ip adress and port in web service

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.

Upvotes: 3

Views: 2088

Answers (1)

Kal
Kal

Reputation: 24910

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.

Upvotes: 4

Related Questions