One aspect of auditing is measuring the performance of a web service. Performance can be measured by the amount of time taken by a web service to respond to a request received from a client. On the client side, the handleRequest method is called before the client's request is sent to the web service, while the handleResponse is called before the service's response is delivered to the client. The difference between the times at which these methods are called is the elapsed time between request and response.
First, use the client-side message handler's handleRequest method to store the current time in the message context as a property called 'startTime':
public boolean handleRequest(MessageContext context) { try{ Date startTime = new Date(); context.setProperty("startTime", startTime); } catch(Exception e){ e.printStackTrace(); } return true; }
Then, the handler passes the message context to the handleResponse method and the elapsed time is calculated, again in the client-side message handler:
public boolean handleResponse(MessageContext context) { try { Date startTime = (Date)context.getProperty("startTime"); Date endTime = new Date(); long elapsedTime = endTime.getTime()-startTime.getTime(); System.out.println("Elapsed time: Only "+elapsedTime+" milliseconds! \n"); } catch (Exception x) { x.printStackTrace(); } return true; }
See Also | |
---|---|
About Web Services About Web Service Clients About Message Handlers Creating a Message Handler Configuring a Message Handler |