Java - Rich logging in web services -
i have simple web service this:
@webservice public class mywebservice { @webmethod public string processquery(@webparam(name="query") string q) { // logging here: user ip, etc. } public static void main(string[] args) throws exception { string address = "http://127.0.0.1:8023/_webservicedemo"; endpoint.publish(address, new mywebservice()); new documentserver(); system.out.println("listening: " + address); } } i want add logging method service extract information. i've heard ncsa format , log4j don't know how use them in service. want log user's ip , other info. how can it?
thanks.
edit: should note main part of question how can retrieve data such user's ip, client, etc. in web method.
add webservicecontext class, can httpservletrequest:
@webservice public class mywebservice { @resource webservicecontext wscontext; @webmethod public string processquery(@webparam(name="query") string q) { messagecontext messagecontext = wscontext.getmessagecontext(); httpservletrequest request = (httpservletrequest) messagecontext.get(soapmessagecontext.servlet_request); // can want request } }
Comments
Post a Comment