You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by maalej <am...@laas.fr> on 2009/06/03 17:10:35 UTC

MessageContext.getProperty does not work

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 


Re: MessageContext.getProperty does not work

Posted by Greg Stasica <gs...@googlemail.com>.
hi,

i think it's not possible to pass parameters from calling server/client to
any handlers (on the other hand, handlers can pass parameters between each
other e.g. handler1 sets a propertyA while handler2 which gets invoked as a
next one reads propertyA's value). Such parameters (defined on the client or
server side) are not part of SOAP message/envelope/headers hence you get
null while trying to read them.

I did some tests with Axis1 setting parameters as a part of invoking a
method on my stub class (... mystub._setProperty(..)). The only properties
available for me in handlers were those about username & password

i'm not an expert in axis1 or axis2 so I'd be grateful if someone with more
experience could shed some light on this issue (availability of user defined
parameters (defined inside client code or server code )  in handlers). I've
already seen many threads where people had been asking the very same
question but unfortunately nobody actually answering it.



On Thu, Jun 4, 2009 at 10:27 AM, maalej <am...@laas.fr> wrote:

> 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 <am...@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
>>>
>>>
>>>
>>
>>
>>
>>
>>
>
>


-- 
Greg Stasica

Re: MessageContext.getProperty does not work

Posted by maalej <am...@laas.fr>.
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 <am...@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
>>
>>     
>
>
>
>   


Re: MessageContext.getProperty does not work

Posted by Sagara Gunathunga <sa...@gmail.com>.
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 <am...@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
>



-- 
Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://sagaras.awardspace.com/