You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Christopher Moesel <Ch...@avid.com> on 2007/04/16 17:52:34 UTC

Accessing Message Context, HttpServletRequest, and HttpServletResponse

I needed access to the request object from within my service
implementation. So after finding nothing in the documentation, I dug
through the samples and found a way.

I thought this would be useful to others, so I added it to the User
Guide WIKI at the bottom of:
http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport

If this is the incorrect place for it, or if this is not the recommended
approach, please feel free to modify, move, or delete it at will.

Thanks,
Chris

Re: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Posted by Dan Diephouse <da...@envoisolutions.com>.
Thanks, that looks great! This is why I love wikis :-)

- Dan

On 4/16/07, Christopher Moesel <Ch...@avid.com> wrote:
>
> I needed access to the request object from within my service
> implementation. So after finding nothing in the documentation, I dug
> through the samples and found a way.
>
> I thought this would be useful to others, so I added it to the User
> Guide WIKI at the bottom of:
> http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport
>
> If this is the incorrect place for it, or if this is not the recommended
> approach, please feel free to modify, move, or delete it at will.
>
> Thanks,
> Chris
>



-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

RE: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Posted by Christopher Moesel <Ch...@avid.com>.
Good point, Fred.  I've added the following snippet to the end of the
section:

"Of course, it is always a good idea to program defensively if using
transport-specific entities like the HttpServletRequest and
HttpServletResponse. If the transport were changed (for instance to the
JMS transport), then these values would likely be null."

-Chris

-----Original Message-----
From: Fred Dushin [mailto:fred@dushin.net] 
Sent: Monday, April 16, 2007 12:11 PM
To: cxf-user@incubator.apache.org
Subject: Re: Accessing Message Context, HttpServletRequest, and
HttpServletResponse

Just bear in mind that this is fragile, and servants should be coded  
defensively for the case in which this information is not available.   
(E.g., due to underlying changes in the transport implementation, or  
an administrative modification that changes the transport type, all  
together)

That being said, the idea that all information about the request  
context is available is laudable, and CXF should be commended for  
it.  You never know when an application is going to need information  
about what's really going on under the hood, and in a managed  
language like Java, it's pretty senseless to throw this information  
away.

-Fred

On Apr 16, 2007, at 11:52 AM, Christopher Moesel wrote:

> I needed access to the request object from within my service
> implementation. So after finding nothing in the documentation, I dug
> through the samples and found a way.
>
> I thought this would be useful to others, so I added it to the User
> Guide WIKI at the bottom of:
> http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport
>
> If this is the incorrect place for it, or if this is not the  
> recommended
> approach, please feel free to modify, move, or delete it at will.
>
> Thanks,
> Chris
>


Re: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Posted by Fred Dushin <fr...@dushin.net>.
Just bear in mind that this is fragile, and servants should be coded  
defensively for the case in which this information is not available.   
(E.g., due to underlying changes in the transport implementation, or  
an administrative modification that changes the transport type, all  
together)

That being said, the idea that all information about the request  
context is available is laudable, and CXF should be commended for  
it.  You never know when an application is going to need information  
about what's really going on under the hood, and in a managed  
language like Java, it's pretty senseless to throw this information  
away.

-Fred

On Apr 16, 2007, at 11:52 AM, Christopher Moesel wrote:

> I needed access to the request object from within my service
> implementation. So after finding nothing in the documentation, I dug
> through the samples and found a way.
>
> I thought this would be useful to others, so I added it to the User
> Guide WIKI at the bottom of:
> http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport
>
> If this is the incorrect place for it, or if this is not the  
> recommended
> approach, please feel free to modify, move, or delete it at will.
>
> Thanks,
> Chris
>


RE: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Posted by Christopher Moesel <Ch...@avid.com>.
Yes, it looks like the CXF code has a static value for content-type as
well, that will lower-case it for you.

AbstractHTTPDestination.java defines PROTOCOL_HEADERS_CONTENT_TYPE like
so:

public static final String PROTOCOL_HEADERS_CONTENT_TYPE =
Message.CONTENT_TYPE.toLowerCase();

So, if you need to get the content-type, it's probably a good idea to
use that static final member rather than a String literal.

-Chris

-----Original Message-----
From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com] 
Sent: Monday, April 16, 2007 12:01 PM
To: cxf-user@incubator.apache.org
Subject: Re: Accessing Message Context, HttpServletRequest, and
HttpServletResponse

Hi

One thing  I've found is that if you need to access the Content-Type
request header you need to use
a lower-key value, "content-type", "Content-Type" doesn't recognized as
a key. Not  sure whether it's the case with a servlet-based 
code though

Cheers, Sergey


----- Original Message ----- 
From: "Christopher Moesel" <Ch...@avid.com>
To: <cx...@incubator.apache.org>
Sent: Monday, April 16, 2007 4:52 PM
Subject: Accessing Message Context, HttpServletRequest, and
HttpServletResponse


I needed access to the request object from within my service
implementation. So after finding nothing in the documentation, I dug
through the samples and found a way.

I thought this would be useful to others, so I added it to the User
Guide WIKI at the bottom of:
http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport

If this is the incorrect place for it, or if this is not the recommended
approach, please feel free to modify, move, or delete it at will.

Thanks,
Chris 


Re: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

One thing  I've found is that if you need to access the Content-Type request header you need to use
a lower-key value, "content-type", "Content-Type" doesn't recognized as a key. Not  sure whether it's the case with a servlet-based 
code though

Cheers, Sergey


----- Original Message ----- 
From: "Christopher Moesel" <Ch...@avid.com>
To: <cx...@incubator.apache.org>
Sent: Monday, April 16, 2007 4:52 PM
Subject: Accessing Message Context, HttpServletRequest, and HttpServletResponse


I needed access to the request object from within my service
implementation. So after finding nothing in the documentation, I dug
through the samples and found a way.

I thought this would be useful to others, so I added it to the User
Guide WIKI at the bottom of:
http://cwiki.apache.org/confluence/display/CXF20DOC/Servlet+Transport

If this is the incorrect place for it, or if this is not the recommended
approach, please feel free to modify, move, or delete it at will.

Thanks,
Chris