I am implementing AXIS2 services in my web application. Our client's
production boxes are a bit flaky, so I want a heads up when performance
degraded. Specifically:
- request comes into my AXIS2 service
- measure the time that the request takes
- if the time is greater than X, log an error
So I wrote an AXIS2 module like this:
public class PerformanceHandler extends AbstractHandler implements
Handler {
protected Logger logger = null;
public PerformanceHandler() {
logger = LoggerFactory.getLogger( this.getClass() );
}
public InvocationResponse invoke( MessageContext msgContext ) throws
AxisFault {
HttpServletRequest r = ( HttpServletRequest )msgContext.getProperty(
HTTPConstants.MC_HTTP_SERVLETREQUEST );
if( msgContext.getFLOW() == MessageContext.IN_FLOW ||
msgContext.getFLOW() == MessageContext.IN_FAULT_FLOW ) {
// incoming request
Date timeIn = new Date( System.currentTimeMillis() );
r.setAttribute( this.getClass().getName() + ".timeIn",
timeIn );
if( logger.isDebugEnabled() ) {
logger.debug( "Request " + r.toString() + " started processing at "
+ timeIn );
}
} else {
// outgoing response
Date timeIn = ( Date )r.getAttribute( this.getClass().getName() +
".timeIn" );
Date timeOut = new Date( System.currentTimeMillis() );
if( logger.isDebugEnabled() ) {
logger.debug( "Request " + r.toString() + " finished processing at
" + timeOut );
}
long delta = timeOut.getTime() - timeIn.getTime();
if( delta > 300 ) { // todo: parameterize the delta
threshold
logger.error( "Request " + r.toString() + " took " + delta + "ms to
process." );
}
}
return InvocationResponse.CONTINUE;
}
}
After that, I edited the module.xml, axis2.xml appropriately, created
the *.mar file and ran the app.
However, it seems that
HttpServletRequest r = ( HttpServletRequest
)msgContext.getProperty( HTTPConstants.MC_HTTP_SERVLETREQUEST )
is null. That was unexpected.
So my questions are:
- How can I access the servlet request in an AXIS2 module?
- If this is not allowed, what's the alternative for me to track the
time between request starting processing and ending processing?
- I should be using some other existing AXIS2 functionality that can
give me the same kind of result?
Many thanks in advance,
--
Dave Cherkassky
DJiNN Software Inc
VP of Software Development
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@axis.apache.org
For additional commands, e-mail: java-user-h...@axis.apache.org