Hi
i would be grateful for the response you sent to me
actually, all the properties figure in a an other class which the name
and the body are as follows:
/*******************************************/
public final class StatisticsConstants {
public static final String GLOBAL_REQUEST_COUNTER =
"wso2wsf.GlobalRequestCounter";
public static final String GLOBAL_RESPONSE_COUNTER =
"wso2wsf.GlobalResponseCounter";
public static final String REQUEST_RECEIVED_TIME =
"wso2wsf.request.received.time";
public static final String RESPONSE_SENT_TIME =
"wso2wsf.response.sent.time";
private StatisticsConstants() {
}
}
/*******************************************/
these properties are used in the main class of the handler which the aim
is to compute the response time:
/*****************************************/
import org.wsf.common.statistics.StatisticsConstants;
public class ResponseTimeHandler extends AbstractHandler {
public InvocationResponse invoke(MessageContext msgContext) throws
AxisFault {
System.out.println(getClass().getName() + " invokeMethode");
// this statement is just used to display the class's name
OperationContext opctx = msgContext.getOperationContext();
if (opctx != null) {
System.out.println("opctx != null");
MessageContext inMsgCtx =
opctx.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
if (inMsgCtx != null) {
System.out.println("inMsgCtx != null");
Object receivedTime =
inMsgCtx.getProperty(StatisticsConstants.REQUEST_RECEIVED_TIME);
if (receivedTime != null) {
long responseTime = System.currentTimeMillis()
-Long.parseLong(receivedTime.toString());
// Handle global reponse time
Parameter globalReqCounterParam =
inMsgCtx.getParameter(StatisticsConstants.GLOBAL_REQUEST_COUNTER);
int globalReqCount = 0;
if (globalReqCounterParam != null) {
globalReqCount = ((Counter)
globalReqCounterParam.getValue()).getCount();
}
StatisticsModule.responseTimeProcessor.addResponseTime(responseTime,
globalReqCount, msgContext);
System.out.println("avg response time = " +
StatisticsModule.responseTimeProcessor.getAvgResponseTime());
// Handle service response time
AxisService axisService = msgContext.getAxisService();
if (axisService != null) {
Parameter parameter =
axisService.getParameter(StatisticsConstants.SERVICE_RESPONSE_TIME_PROCESSOR);
Parameter srcParam =
axisService.getParameter(StatisticsConstants.SERVICE_REQUEST_COUNTER);
int srcCount = 0;
if (srcParam != null) {
srcCount = ((Counter)
srcParam.getValue()).getCount();
}
if (parameter != null) {
((ResponseTimeProcessor) parameter.getValue()).
addResponseTime(responseTime,
srcCount, msgContext);
} else {
ResponseTimeProcessor proc = new
ResponseTimeProcessor();
proc.addResponseTime(responseTime, srcCount,
msgContext);
parameter = new Parameter();
parameter.setName(StatisticsConstants.SERVICE_RESPONSE_TIME_PROCESSOR);
parameter.setValue(proc);
axisService.addParameter(parameter);
}
}
// Handle operation response time
AxisOperation axisOperation =
msgContext.getAxisOperation();
if (axisOperation != null) {
Parameter parameter =
axisOperation.getParameter(StatisticsConstants.OPERATION_RESPONSE_TIME_PROCESSOR);
Parameter opReqCounterParam =
axisOperation.getParameter(StatisticsConstants.IN_OPERATION_COUNTER);
int opReqCount = 0;
if (opReqCounterParam != null) {
opReqCount = ((Counter)
opReqCounterParam.getValue()).getCount();
}
if (parameter != null) {
((ResponseTimeProcessor) parameter.getValue()).
addResponseTime(responseTime,
opReqCount, msgContext);
} else {
ResponseTimeProcessor proc = new
ResponseTimeProcessor();
proc.addResponseTime(responseTime,
opReqCount, msgContext);
parameter = new Parameter();
parameter.setName(StatisticsConstants.OPERATION_RESPONSE_TIME_PROCESSOR);
parameter.setValue(proc);
axisOperation.addParameter(parameter);
}
}
}
else{
System.out.println("receivedTime = null");
}
}else{ System.out.println("inMsgCtx = null");}
}else{
System.out.println("opctx = null");
}
return InvocationResponse.CONTINUE;
}
}
/*******************************************/
Concerning the class which take in charge tha addition of the response
time is ResponseTimeProcessor
/******************************************/
public class ResponseTimeProcessor {
private long maxResponseTime = 0;
private long minResponseTime = -1;
private double avgResponseTime = 0;
private double totalresponseTime;
public synchronized void addResponseTime(long responseTime,long
requestCount,MessageContext msgctx) {
if (maxResponseTime < responseTime) {
maxResponseTime = responseTime;
}
if (minResponseTime > responseTime) {
minResponseTime = responseTime;
}
if (minResponseTime == -1) {
minResponseTime = responseTime;
}
totalresponseTime = totalresponseTime + responseTime;
avgResponseTime = totalresponseTime / requestCount;
}
}
/****************************************/
Remark: this is a simple try of a code which already exist at :
https://wso2.org/svn/browse/wso2/wsf/java/trunk/modules/statistics/src/main/java/org/wso2/wsf/common/statistics/module/?pathrev=281
Of course, i build the necessary files (as module.xml) and i generate
their byte code and finally i encapsulated them in a .mar archive to
test the module
when i engage it, i don't face any problem and the whole of the module
work properly, but the main object (received time) which all of the
class depend on are returned, always, as a null
hoping you can identify what i'm missing, i'll be so thankful
Best regards
Sagara Gunathunga a écrit :
Hi ,
in where you set the value for your property ...? can you provide
some codes to figure out your problem ..?
On Wed, Jun 3, 2009 at 8:40 PM, maalej <amaa...@laas.fr> wrote:
Hello
When I try to get a property from MessageContext it always returns null.
the instruction is below:
/****************************************************/
MessageContext inMsgCtx = opctx.getMessageContext("In");
if (inMsgCtx != null) {
Object receivedTime =
inMsgCtx.getProperty(StatisticsConstants.REQUEST_RECEIVED_TIME);
if (receivedTime != null) {
System.out.println("receivedTime != null");
long responseTime = System.currentTimeMillis() -
Long.parseLong(receivedTime.toString());
}
else System.out.println("receivedTime = null");
/*************************************************/
_Remark :_
StatisticsConstants.REQUEST_RECEIVED_TIME
is a static final String defined in an other class "StatisticsConstants"
value : REQUEST_RECEIVED_TIME = "wso2wsf.request.received.time";
please can some one help me