从AXIS2模块内部访问HttpServletRequest
我正在web应用程序中实现AXIS2服务。我们客户的生产箱有点不稳定,所以我想在性能下降时提高警惕。具体而言:从AXIS2模块内部访问HttpServletRequest,axis2,axis,Axis2,Axis,我正在web应用程序中实现AXIS2服务。我们客户的生产箱有点不稳定,所以我想在性能下降时提高警惕。具体而言: 请求进入我的AXIS2服务 测量请求所花费的时间 如果时间大于X,则记录错误 因此,我编写了一个AXIS2模块,如下所示: public class PerformanceHandler extends AbstractHandler implements Handler { protected Logger logger = null; public PerformanceHa
- 请求进入我的AXIS2服务
- 测量请求所花费的时间
- 如果时间大于X,则记录错误
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;
}
}
之后,我适当地编辑了module.xml和axis2.xml,创建了*.mar文件并运行了应用程序
然而,似乎
HttpServletRequest r = ( HttpServletRequest )msgContext.getProperty( HTTPConstants.MC_HTTP_SERVLETREQUEST )
是空的。这是出乎意料的
因此,我的问题是:
- 如何在AXIS2模块中访问servlet请求
- 如果这是不允许的,我有什么办法来跟踪请求开始处理和结束处理之间的时间
- 我应该使用其他一些现有的AXIS2功能来获得相同的结果
Dave C.您应该使用
OperationContext
(可以使用getOperationContext
方法从MessageContext
获取)来存储请求的时间戳,而不是使用HttpServletRequest
。传入请求和相应响应的操作上下文相同。最后,我编写了一个javax.servlet.ServletRequestListener。但是知道OperationContext的用途是很好的;将来一定会用到它。