You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Daniel Kulp <dk...@apache.org> on 2010/01/13 16:43:24 UTC

Re: Access to HTTP cookie values in Interceptor or Invoker implementation?

On Tue January 12 2010 9:02:03 pm Michael Guyver wrote:
> Hi there,
> 
> I'm new to CXF and JAX-RS programming so the paradigm is quite foreign
> to me. At the moment I'm trying to figure out how one would go about
> implementing a Interceptor or Invoker that would execute prior to the
> service class mapped to the specific request, for example to validate
> a session token value. I had in mind being able to read this from a
> cookie but can't see any easy way of doing so.
> 
> Within the Interceptor implementation the only way I've found to get
> at this API is this (horrible) hack:
> 
> new MessageContextImpl(message).getHttpHeaders().getCookies()
> 
> I mean, there's got to be an easier and better way than that, right?

That's probably the easiest.    I guess the more "standard" way would be to 
pull the stuff off the message directly instead of using the 
MessageContextImpl wrapper thing, but the wrapper avoids a bunch of casts and 
stuff.

You could do:

((Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS)
to get the map of all the protocol headers and process the cookie things 
yourself.   Probably not fun.

You could also to:

(HTTPServletRequest)message.get("HTTP.REQUEST")
to get the request object and grab the session and everything from there.   
Not sure how valuable that is to you.

Dan



> 
> Cheers
> 
> Mike
> 

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

Re: Access to HTTP cookie values in Interceptor or Invoker implementation?

Posted by Michael Guyver <mi...@gmail.com>.
2010/1/13 Daniel Kulp <dk...@apache.org>:
>>
>> new MessageContextImpl(message).getHttpHeaders().getCookies()
>>
>
> That's probably the easiest.    I guess the more "standard" way would be to
> pull the stuff off the message directly instead of using the
> MessageContextImpl wrapper thing, but the wrapper avoids a bunch of casts and
> stuff.
>
> You could do:
>
> ((Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS)
> to get the map of all the protocol headers and process the cookie things
> yourself.   Probably not fun.
>
> You could also to:
>
> (HTTPServletRequest)message.get("HTTP.REQUEST")
> to get the request object and grab the session and everything from there.
> Not sure how valuable that is to you.
>
> Dan
>

That's really helpful to know, that you very much for your advice. I'm
not sure which route I'm going to chose. Do you think there's a risk
in depending on the implementation class MessageContextImpl? I'm
slightly uneasy about using it directly and would prefer to depend on
MessageContext.

I'm using Spring to configure the jaxrs:server and hence the
interceptor. Is there any way to have the MessageContext
implementation injected into the Interceptor by CXF?

Best wishes,

Michael