You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Davide Gesino <wi...@libero.it> on 2008/02/14 15:17:29 UTC

put a variable in an handler and access it from the MessageContext

How can I put a variable in an handler and access it from the MessageContext
once I have reached the endpoint?
I have injected the WebServiceContext in my endpoint (with the @resource
annotation).
I have put an object in my handler in a SoapMessageContext as a key pair
value:

public boolean handleMessage(LogicalMessageContext lmc) {
		
	lmc.put(Constants.MY_CONSTANT, new Date());
		
	return true;
}

 and I expected the variable 

would have been accessed as:

context.getMessageContext().get(Constants.MY_CONSTANT);

Anyway what i get is null. Where is my fault??


-- 
View this message in context: http://www.nabble.com/put-a-variable-in-an-handler-and-access-it-from-the-MessageContext-tp15480680p15480680.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: put a variable in an handler and access it from the MessageContext

Posted by Daniel Kulp <dk...@apache.org>.
You need to set a scope for the property.  In a handler, properties 
default to "Handler" scope and thus are only available to handlers.   
You need to call:
lmc.setScope(Constants.MY_CONSTANT,
              MessageContext.Scope.APPLICATION);
to make it Application scoped.

Dan



On Thursday 14 February 2008, Davide Gesino wrote:
> How can I put a variable in an handler and access it from the
> MessageContext once I have reached the endpoint?
> I have injected the WebServiceContext in my endpoint (with the
> @resource annotation).
> I have put an object in my handler in a SoapMessageContext as a key
> pair value:
>
> public boolean handleMessage(LogicalMessageContext lmc) {
>
> 	lmc.put(Constants.MY_CONSTANT, new Date());
>
> 	return true;
> }
>
>  and I expected the variable
>
> would have been accessed as:
>
> context.getMessageContext().get(Constants.MY_CONSTANT);
>
> Anyway what i get is null. Where is my fault??



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog