Accessing an HttpServletRequest from inside an AXIS2 module

Dave Cherkassky <[email protected]>
Newsgroups gmane.text.xml.axis.user
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.