Accessing Message Context, HttpServletRequest, and HttpServletResponse

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing Message Context, HttpServletRequest, and HttpServletResponse

CMoesel
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
Reply | Threaded
Open this post in threaded view
|

Re: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Sergey Beryozkin-6
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" <[hidden email]>
To: <[hidden email]>
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

Reply | Threaded
Open this post in threaded view
|

Re: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Fred Dushin-3
In reply to this post by CMoesel
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
>

Reply | Threaded
Open this post in threaded view
|

RE: Accessing Message Context, HttpServletRequest, and HttpServletResponse

CMoesel
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:[hidden email]]
Sent: Monday, April 16, 2007 12:11 PM
To: [hidden email]
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
>

Reply | Threaded
Open this post in threaded view
|

RE: Accessing Message Context, HttpServletRequest, and HttpServletResponse

CMoesel
In reply to this post by Sergey Beryozkin-6
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:[hidden email]]
Sent: Monday, April 16, 2007 12:01 PM
To: [hidden email]
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" <[hidden email]>
To: <[hidden email]>
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

Reply | Threaded
Open this post in threaded view
|

Re: Accessing Message Context, HttpServletRequest, and HttpServletResponse

Dan Diephouse-2
In reply to this post by CMoesel
Thanks, that looks great! This is why I love wikis :-)

- Dan

On 4/16/07, Christopher Moesel <[hidden email]> 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