You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Avlesh Singh <av...@gmail.com> on 2009/06/20 16:51:40 UTC
RequestProcessor and contentType response header
I am using Struts 1.2.7
I wrote a Filter which intercepts all requests and applies response headers
(based on some external configuration) to it. All response headers applied
in my Filter other than "Content-Type" were obeyed and sent to the client.
Content-Type was always "text/html".
After a lot of debugging, I realized the value for this particular header
are always getting overwritten in the struts' RequestProcessor class.
Underneath is the method which in my case turned out to be the "culprit"
>
> protected void processContent(HttpServletRequest request,
> HttpServletResponse response) {
> String contentType =
> moduleConfig.getControllerConfig().getContentType();
> if (contentType != null) {
> response.setContentType(contentType);
> }
> }
>
Couple of questions:
1. Shouldn't this method also check if the response already has a
contentType header applied or not? Is this a known bug, or am I missing
something?
2. I subclassed the RequestProcessor and defined a controller in my
struts config as <controller processorClass="com.me.MyRequestProcessor"/>.
The class merely overrides the processContent method to check for an
existing contentType. Am I doing it correctly, or is there some other way to
achieve the desired behavour in my case.
Cheers
Avlesh
Re: RequestProcessor and contentType response header
Posted by Avlesh Singh <av...@gmail.com>.
>
> I would recomend upgrading to a later version of struts
>
Oh Mike, I wish I could do that! :)
For the problem at hand, I am better off sub-classing the RequestProcessor.
Having said that, would still try and upgrade asap.
Cheers
Avlesh
On Mon, Jun 22, 2009 at 9:30 AM, Mike Dave <i....@gmail.com> wrote:
> >
> > Sounds counter-intuitive. Why should the RequestProcessor overwrite?
> >
> I am in agreement with you, Avlesh. This behaviour is erratic.
> I would recomend upgrading to a later version of struts assuming that the
> behaviour has been fixed.
>
> -m-
>
> On Sun, Jun 21, 2009 at 8:46 PM, Avlesh Singh <av...@gmail.com> wrote:
> >
> >> It's also the weekend.
> >>
> >> I truly respect that.
> >>
> >> It's not a bug, that's just how it works.
> >>>
> >> Sounds counter-intuitive. Why should the RequestProcessor overwrite?
> >>
> >> Overriding the request processor is the normal way to add behavior to
> apps
> >>> running that version of Struts.
> >>>
> >> Thanks for approving the solution.
> >>
> >> Thanks again, Dave.
> >>
> >> Cheers
> >> Avlesh
> >>
> >>
> >> On Sun, Jun 21, 2009 at 5:59 PM, Dave Newton <newton.dave@yahoo.com
> >wrote:
> >>
> >>> Avlesh Singh wrote:
> >>>
> >>>> Did not get a response yet :(
> >>>>
> >>>
> >>> It's also the weekend.
> >>>
> >>> Is this a dev list question
> >>>>
> >>>
> >>> No.
> >>>
> >>> 1. Shouldn't this method also check if the response already has a
> >>>>> contentType header applied or not? Is this a known bug, or am I
> >>>>> missing
> >>>>> something?
> >>>>>
> >>>>
> >>> It's not a bug, that's just how it works.
> >>>
> >>> 2. I subclassed the RequestProcessor and defined a controller in my
> >>>>> struts config as <controller
> >>>>> processorClass="com.me.MyRequestProcessor"/>.
> >>>>> The class merely overrides the processContent method to check for
> an
> >>>>> existing contentType. Am I doing it correctly, or is there some
> other
> >>>>> way to
> >>>>> achieve the desired behavour in my case.
> >>>>>
> >>>>
> >>> Overriding the request processor is the normal way to add behavior to
> >>> apps running that version of Struts.
> >>>
> >>> Dave
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>> For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >>
> >
>
Re: RequestProcessor and contentType response header
Posted by Mike Dave <i....@gmail.com>.
>
> Sounds counter-intuitive. Why should the RequestProcessor overwrite?
>
I am in agreement with you, Avlesh. This behaviour is erratic.
I would recomend upgrading to a later version of struts assuming that the
behaviour has been fixed.
-m-
On Sun, Jun 21, 2009 at 8:46 PM, Avlesh Singh <av...@gmail.com> wrote:
>
>> It's also the weekend.
>>
>> I truly respect that.
>>
>> It's not a bug, that's just how it works.
>>>
>> Sounds counter-intuitive. Why should the RequestProcessor overwrite?
>>
>> Overriding the request processor is the normal way to add behavior to apps
>>> running that version of Struts.
>>>
>> Thanks for approving the solution.
>>
>> Thanks again, Dave.
>>
>> Cheers
>> Avlesh
>>
>>
>> On Sun, Jun 21, 2009 at 5:59 PM, Dave Newton <ne...@yahoo.com>wrote:
>>
>>> Avlesh Singh wrote:
>>>
>>>> Did not get a response yet :(
>>>>
>>>
>>> It's also the weekend.
>>>
>>> Is this a dev list question
>>>>
>>>
>>> No.
>>>
>>> 1. Shouldn't this method also check if the response already has a
>>>>> contentType header applied or not? Is this a known bug, or am I
>>>>> missing
>>>>> something?
>>>>>
>>>>
>>> It's not a bug, that's just how it works.
>>>
>>> 2. I subclassed the RequestProcessor and defined a controller in my
>>>>> struts config as <controller
>>>>> processorClass="com.me.MyRequestProcessor"/>.
>>>>> The class merely overrides the processContent method to check for an
>>>>> existing contentType. Am I doing it correctly, or is there some other
>>>>> way to
>>>>> achieve the desired behavour in my case.
>>>>>
>>>>
>>> Overriding the request processor is the normal way to add behavior to
>>> apps running that version of Struts.
>>>
>>> Dave
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>
Re: RequestProcessor and contentType response header
Posted by Avlesh Singh <av...@gmail.com>.
>
> It's also the weekend.
I truly respect that.
It's not a bug, that's just how it works.
>
Sounds counter-intuitive. Why should the RequestProcessor overwrite?
Overriding the request processor is the normal way to add behavior to apps
> running that version of Struts.
>
Thanks for approving the solution.
Thanks again, Dave.
Cheers
Avlesh
On Sun, Jun 21, 2009 at 5:59 PM, Dave Newton <ne...@yahoo.com> wrote:
> Avlesh Singh wrote:
>
>> Did not get a response yet :(
>>
>
> It's also the weekend.
>
> Is this a dev list question
>>
>
> No.
>
> 1. Shouldn't this method also check if the response already has a
>>> contentType header applied or not? Is this a known bug, or am I missing
>>> something?
>>>
>>
> It's not a bug, that's just how it works.
>
> 2. I subclassed the RequestProcessor and defined a controller in my
>>> struts config as <controller
>>> processorClass="com.me.MyRequestProcessor"/>.
>>> The class merely overrides the processContent method to check for an
>>> existing contentType. Am I doing it correctly, or is there some other
>>> way to
>>> achieve the desired behavour in my case.
>>>
>>
> Overriding the request processor is the normal way to add behavior to apps
> running that version of Struts.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: RequestProcessor and contentType response header
Posted by Dave Newton <ne...@yahoo.com>.
Avlesh Singh wrote:
> Did not get a response yet :(
It's also the weekend.
> Is this a dev list question
No.
>> 1. Shouldn't this method also check if the response already has a
>> contentType header applied or not? Is this a known bug, or am I missing
>> something?
It's not a bug, that's just how it works.
>> 2. I subclassed the RequestProcessor and defined a controller in my
>> struts config as <controller processorClass="com.me.MyRequestProcessor"/>.
>> The class merely overrides the processContent method to check for an
>> existing contentType. Am I doing it correctly, or is there some other way to
>> achieve the desired behavour in my case.
Overriding the request processor is the normal way to add behavior to
apps running that version of Struts.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: RequestProcessor and contentType response header
Posted by Avlesh Singh <av...@gmail.com>.
Did not get a response yet :(
Is this a dev list question or my assumptions are correct?
Cheers
Avlesh
On Sat, Jun 20, 2009 at 8:21 PM, Avlesh Singh <av...@gmail.com> wrote:
> I am using Struts 1.2.7
> I wrote a Filter which intercepts all requests and applies response headers
> (based on some external configuration) to it. All response headers applied
> in my Filter other than "Content-Type" were obeyed and sent to the client.
> Content-Type was always "text/html".
> After a lot of debugging, I realized the value for this particular header
> are always getting overwritten in the struts' RequestProcessor class.
> Underneath is the method which in my case turned out to be the "culprit"
>
>>
>> protected void processContent(HttpServletRequest request,
>> HttpServletResponse response) {
>> String contentType =
>> moduleConfig.getControllerConfig().getContentType();
>> if (contentType != null) {
>> response.setContentType(contentType);
>> }
>> }
>>
>
> Couple of questions:
>
> 1. Shouldn't this method also check if the response already has a
> contentType header applied or not? Is this a known bug, or am I missing
> something?
> 2. I subclassed the RequestProcessor and defined a controller in my
> struts config as <controller processorClass="com.me.MyRequestProcessor"/>.
> The class merely overrides the processContent method to check for an
> existing contentType. Am I doing it correctly, or is there some other way to
> achieve the desired behavour in my case.
>
> Cheers
> Avlesh
>