Hi!
I found a very old post here and tried and looked around some myself in the documentation also, and finally managed to put together some code to do this,
and had problems finding it when I googled for it, so I figured I'd post an example
for others. I'm working under tomcat.
The thing to do is to implement the ServiceLifecycle interface, like so:
public class MyWSImpl implements MyWSIF, javax.xml.rpc.server.ServiceLifecycle {
private javax.xml.rpc.server.ServletEndpointContext wsctx = null;
public void init(Object ctx) {
wsctx = (javax.xml.rpc.server.ServletEndpointContext)ctx;
System.out.println("INIT CALLED: " + wsctx);
}
public void destroy() {
System.out.println("DESTROY CALLED.");
}
private String getRemoteAddr() {
String remoteHost = "unknown.remote.host";
try {
javax.xml.rpc.handler.MessageContext msgCtx = wsctx.getMessageContext();
javax.servlet.http.HttpServletRequest request = null;
request = (javax.servlet.http.HttpServletRequest)
msgCtx.getProperty("com.sun.xml.rpc.server.http.HttpServletRequest");
remoteHost = request.getRemoteAddr();
} catch (Throwable t) { }
return remoteHost;
}
public String reloadConfig(String msg) throws RemoteException {
String addr = getRemoteAddr();
System.out.println("Message from " + addr + ": " + msg);
return "Hi " + addr;
}
}
Search hits improvement: client ip, remote ip, remote address, client address, jwsdp.