You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Peter Dotchev <do...@gmail.com> on 2011/02/10 23:56:45 UTC

Re: request.getCharacterEncoding() always returns ISO-8859-1

Hi,

Recently 
http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
stumbled  over this issue too.

I don't want to add _charset_ input to all the forms.
Is there a way to set the request encoding to UTF-8?
IMHO it would be better if the request encoding is configurable like it is
done in Wicket.

http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
using a filter.
How can I do that in Sling? 
I start Sling with launchpad standalone.

Best regards,
Peter

-- 
View this message in context: http://apache-sling.73963.n3.nabble.com/request-getCharacterEncoding-always-returns-ISO-8859-1-tp1740512p2469927.html
Sent from the Sling - Users mailing list archive at Nabble.com.

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Peter Dotchev <do...@gmail.com>.
Hi Vidar,

Thank you for the suggestion. I will try it.
Now I found that request filters are described here
http://sling.apache.org/site/filters.html

Best regards,
Peter

On Fri, Feb 11, 2011 at 3:27 PM, Vidar Ramdal-2 [via Apache Sling] <
ml-node+2473494-998661287-5361@n3.nabble.com> wrote:

> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <[hidden email]<http://user/SendEmail.jtp?type=node&node=2473494&i=0>>
> wrote:
>
> >
> > Hi,
> >
> > Recently
> >
> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
>
> > stumbled  over this issue too.
> >
> > I don't want to add _charset_ input to all the forms.
> > Is there a way to set the request encoding to UTF-8?
> > IMHO it would be better if the request encoding is configurable like it
> is
> > done in Wicket.
> >
> > http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
>
> > using a filter.
> > How can I do that in Sling?
>
> Hi, you can implement the javax.servlet.Filter interface and register
> your implementation as a Filter service:
>
> @Component(immediate = true)
> @Properties({
>         @Property(name = "filter.scope", value = "request",
> propertyPrivate = true),
>         @Property(name = "filter.order", value = "-9", propertyPrivate =
> true)
> })
> @Services({@Service(javax.servlet.Filter.class)})
> public class YourFilter implements javax.servlet.Filter {
>  ...
> }
>
>
>
> --
> Vidar S. Ramdal <[hidden email]<http://user/SendEmail.jtp?type=node&node=2473494&i=1>>
> - http://www.idium.no
> Sommerrogata 13-15, N-0255 Oslo, Norway
> + 47 22 00 84 00
> Quando omni flunkus moritatus!
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-sling.73963.n3.nabble.com/request-getCharacterEncoding-always-returns-ISO-8859-1-tp1740512p2473494.html
>  To unsubscribe from request.getCharacterEncoding() always returns
> ISO-8859-1, click here<http://apache-sling.73963.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1740512&code=ZG90Y2hldkBnbWFpbC5jb218MTc0MDUxMnwtMTcyMjY3ODE2NA==>.
>
>

-- 
View this message in context: http://apache-sling.73963.n3.nabble.com/request-getCharacterEncoding-always-returns-ISO-8859-1-tp1740512p2474201.html
Sent from the Sling - Users mailing list archive at Nabble.com.

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Markus Joschko <ma...@gmail.com>.
Hi Ian,
> Side question, but related.
> I have tried in the past to register a Filter before the SlingMain Servlet which also has Filter registration functionality (presumably from a time when the OSGi HttpService didnt support filters), however I was always stuck locating the HttpContext. (the Pax HttpService impl needs the a real HttpContext class)
>
> Is the Context ID mentioned in [0], the service ID of the service that implements the HttpContext? (which would be SlingMain as that implements HttpContext and registers against itself)

I would guess so. The only ServletContext Service  I can quickly
identify in the console is the one from sling with the PID
org.apache.sling.engine.impl.helper.SlingServletContext
Using that as a contextId does not change anything. The servletcontext
I get is of type
org.apache.felix.http.base.internal.context.ServletContextImpl

>
> and
>
> Does registering against a null context make a Filter active on all contexts?

Admittedely I am not sure where to look after to verify that.
I see no difference using the above mentioned service PID as contextId
or using no contextId.

Regards,
 Markus



> On 24 Feb 2011, at 18:21, Julian Sedding wrote:
>
>> Hello Markus
>>
>> You can register servlet filters in Sling, but you can also register
>> servlet filters in the OSGi HttpService using the whiteboard[0]. As
>> the SlingMainServlet runs within the OSGi HttpService, you may have
>> more success registering a filter there. I don't know where in the
>> stack ParameterSupport is added, so YMMV. Let us know whether this
>> does the trick.
>>
>> Regards
>> Julian
>>
>> [0] http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard
>>
>>
>>
>> On Thu, Feb 24, 2011 at 4:29 PM, Markus Joschko
>> <ma...@gmail.com> wrote:
>>> Hi Vidar and all,
>>> I think that this approach is not working.
>>> I have the exact same use case. We don't want to put the _charset_
>>> parameter into every form. Therefore I tried to automatically add a
>>> _charset_ request parameter to the request in a filter.
>>> However that parameter never gets picked up as ParameterSupport is
>>> created before the filter gets called (and then uses the reference to
>>> the original servletrequest and not the wrapped one).
>>> I could theoretically reinstantiate Parametersupport but that requires
>>> knowledge of the servlet attribute key where parametersupport is
>>> stored. And that is a private variable in parametersupport.
>>>
>>> Any other chance to not have the _charset_ parameter in every post
>>> request sent to the system?
>>>
>>> Thanks,
>>>  Markus
>>>
>>> On Fri, Feb 11, 2011 at 2:25 PM, Vidar Ramdal <vi...@idium.no> wrote:
>>>> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> Recently
>>>>> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
>>>>> stumbled  over this issue too.
>>>>>
>>>>> I don't want to add _charset_ input to all the forms.
>>>>> Is there a way to set the request encoding to UTF-8?
>>>>> IMHO it would be better if the request encoding is configurable like it is
>>>>> done in Wicket.
>>>>>
>>>>> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
>>>>> using a filter.
>>>>> How can I do that in Sling?
>>>>
>>>> Hi, you can implement the javax.servlet.Filter interface and register
>>>> your implementation as a Filter service:
>>>>
>>>> @Component(immediate = true)
>>>> @Properties({
>>>>        @Property(name = "filter.scope", value = "request",
>>>> propertyPrivate = true),
>>>>        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
>>>> })
>>>> @Services({@Service(javax.servlet.Filter.class)})
>>>> public class YourFilter implements javax.servlet.Filter {
>>>>  ...
>>>> }
>>>>
>>>>
>>>>
>>>> --
>>>> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
>>>> Sommerrogata 13-15, N-0255 Oslo, Norway
>>>> + 47 22 00 84 00
>>>> Quando omni flunkus moritatus!
>>>>
>>>
>
>

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Ian Boston <ie...@tfd.co.uk>.
On 25 Feb 2011, at 16:06, Felix Meschberger wrote:

> The Felix Http Service has whiteboard pattern support for servlet Filter
> registration. So you just register your filter as a javax.servlet.Filter
> service with an alias service property and you should be done.
> 
> Regards
> Felix


Cool, thanks, that makes sense.
I think the reason it wasn't working was because we were still using the Pax Web http service impl with the Felix whiteboard, now using the Felix HttpService.
Ian

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am Freitag, den 25.02.2011, 08:52 +0000 schrieb Ian Boston: 
> Markus,
> Side question, but related.
> I have tried in the past to register a Filter before the SlingMain Servlet which also has Filter registration functionality (presumably from a time when the OSGi HttpService didnt support filters), however I was always stuck locating the HttpContext. (the Pax HttpService impl needs the a real HttpContext class)
> 
> Is the Context ID mentioned in [0], the service ID of the service that implements the HttpContext? (which would be SlingMain as that implements HttpContext and registers against itself)
> 
> and
> 
> Does registering against a null context make a Filter active on all contexts?

The Felix Http Service has whiteboard pattern support for servlet Filter
registration. So you just register your filter as a javax.servlet.Filter
service with an alias service property and you should be done.

Regards
Felix

> 
> TIA
> Ian
> 
> 
> 
> On 24 Feb 2011, at 18:21, Julian Sedding wrote:
> 
> > Hello Markus
> > 
> > You can register servlet filters in Sling, but you can also register
> > servlet filters in the OSGi HttpService using the whiteboard[0]. As
> > the SlingMainServlet runs within the OSGi HttpService, you may have
> > more success registering a filter there. I don't know where in the
> > stack ParameterSupport is added, so YMMV. Let us know whether this
> > does the trick.
> > 
> > Regards
> > Julian
> > 
> > [0] http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard
> > 
> > 
> > 
> > On Thu, Feb 24, 2011 at 4:29 PM, Markus Joschko
> > <ma...@gmail.com> wrote:
> >> Hi Vidar and all,
> >> I think that this approach is not working.
> >> I have the exact same use case. We don't want to put the _charset_
> >> parameter into every form. Therefore I tried to automatically add a
> >> _charset_ request parameter to the request in a filter.
> >> However that parameter never gets picked up as ParameterSupport is
> >> created before the filter gets called (and then uses the reference to
> >> the original servletrequest and not the wrapped one).
> >> I could theoretically reinstantiate Parametersupport but that requires
> >> knowledge of the servlet attribute key where parametersupport is
> >> stored. And that is a private variable in parametersupport.
> >> 
> >> Any other chance to not have the _charset_ parameter in every post
> >> request sent to the system?
> >> 
> >> Thanks,
> >>  Markus
> >> 
> >> On Fri, Feb 11, 2011 at 2:25 PM, Vidar Ramdal <vi...@idium.no> wrote:
> >>> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
> >>>> 
> >>>> Hi,
> >>>> 
> >>>> Recently
> >>>> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
> >>>> stumbled  over this issue too.
> >>>> 
> >>>> I don't want to add _charset_ input to all the forms.
> >>>> Is there a way to set the request encoding to UTF-8?
> >>>> IMHO it would be better if the request encoding is configurable like it is
> >>>> done in Wicket.
> >>>> 
> >>>> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
> >>>> using a filter.
> >>>> How can I do that in Sling?
> >>> 
> >>> Hi, you can implement the javax.servlet.Filter interface and register
> >>> your implementation as a Filter service:
> >>> 
> >>> @Component(immediate = true)
> >>> @Properties({
> >>>        @Property(name = "filter.scope", value = "request",
> >>> propertyPrivate = true),
> >>>        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
> >>> })
> >>> @Services({@Service(javax.servlet.Filter.class)})
> >>> public class YourFilter implements javax.servlet.Filter {
> >>>  ...
> >>> }
> >>> 
> >>> 
> >>> 
> >>> --
> >>> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
> >>> Sommerrogata 13-15, N-0255 Oslo, Norway
> >>> + 47 22 00 84 00
> >>> Quando omni flunkus moritatus!
> >>> 
> >> 
> 



Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Ian Boston <ie...@tfd.co.uk>.
Markus,
Side question, but related.
I have tried in the past to register a Filter before the SlingMain Servlet which also has Filter registration functionality (presumably from a time when the OSGi HttpService didnt support filters), however I was always stuck locating the HttpContext. (the Pax HttpService impl needs the a real HttpContext class)

Is the Context ID mentioned in [0], the service ID of the service that implements the HttpContext? (which would be SlingMain as that implements HttpContext and registers against itself)

and

Does registering against a null context make a Filter active on all contexts?

TIA
Ian



On 24 Feb 2011, at 18:21, Julian Sedding wrote:

> Hello Markus
> 
> You can register servlet filters in Sling, but you can also register
> servlet filters in the OSGi HttpService using the whiteboard[0]. As
> the SlingMainServlet runs within the OSGi HttpService, you may have
> more success registering a filter there. I don't know where in the
> stack ParameterSupport is added, so YMMV. Let us know whether this
> does the trick.
> 
> Regards
> Julian
> 
> [0] http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard
> 
> 
> 
> On Thu, Feb 24, 2011 at 4:29 PM, Markus Joschko
> <ma...@gmail.com> wrote:
>> Hi Vidar and all,
>> I think that this approach is not working.
>> I have the exact same use case. We don't want to put the _charset_
>> parameter into every form. Therefore I tried to automatically add a
>> _charset_ request parameter to the request in a filter.
>> However that parameter never gets picked up as ParameterSupport is
>> created before the filter gets called (and then uses the reference to
>> the original servletrequest and not the wrapped one).
>> I could theoretically reinstantiate Parametersupport but that requires
>> knowledge of the servlet attribute key where parametersupport is
>> stored. And that is a private variable in parametersupport.
>> 
>> Any other chance to not have the _charset_ parameter in every post
>> request sent to the system?
>> 
>> Thanks,
>>  Markus
>> 
>> On Fri, Feb 11, 2011 at 2:25 PM, Vidar Ramdal <vi...@idium.no> wrote:
>>> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
>>>> 
>>>> Hi,
>>>> 
>>>> Recently
>>>> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
>>>> stumbled  over this issue too.
>>>> 
>>>> I don't want to add _charset_ input to all the forms.
>>>> Is there a way to set the request encoding to UTF-8?
>>>> IMHO it would be better if the request encoding is configurable like it is
>>>> done in Wicket.
>>>> 
>>>> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
>>>> using a filter.
>>>> How can I do that in Sling?
>>> 
>>> Hi, you can implement the javax.servlet.Filter interface and register
>>> your implementation as a Filter service:
>>> 
>>> @Component(immediate = true)
>>> @Properties({
>>>        @Property(name = "filter.scope", value = "request",
>>> propertyPrivate = true),
>>>        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
>>> })
>>> @Services({@Service(javax.servlet.Filter.class)})
>>> public class YourFilter implements javax.servlet.Filter {
>>>  ...
>>> }
>>> 
>>> 
>>> 
>>> --
>>> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
>>> Sommerrogata 13-15, N-0255 Oslo, Norway
>>> + 47 22 00 84 00
>>> Quando omni flunkus moritatus!
>>> 
>> 


Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 25.02.11 16:41, "James Stansell" <js...@gmail.com> wrote:
>These days UTF-8 seems like a reasonable convention to take advantage of.

Yes, but AFAIU from a standards perspective ISO-8859-1 is the default
"fallback". Especially if you consider requests coming from other clients,
that were not provided by your web application itself as HTML pages.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by James Stansell <js...@gmail.com>.
On Fri, Feb 25, 2011 at 9:09 AM, Markus Joschko wrote:

>
> Not sure if I get this correctly. ...
> If I choose the same encoding for all my forms I could easily set
> default/fallback encoding which sling
> can use when no _charset_ field is explicitly provided.
>

This phrase comes to mind: convention over configuration

These days UTF-8 seems like a reasonable convention to take advantage of.

Sincerely,

-james.

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Markus Joschko <ma...@gmail.com>.
On Fri, Feb 25, 2011 at 3:37 PM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 25.02.11 11:43, "Markus Joschko" <ma...@gmail.com> wrote:
>>Nevertheless I wonder why it is necessary to include a mandatory
>>parameter with always the same value.
>>Can't this be done by sling?
>
> Yes, but it must match the value of the response of the previous request
> (i.e. the html containing the form). Because this is the character
> encoding that all browsers will use to construct the form - the problem is
> only that they don't explicitly mention that in the request.
>
> So it depends what character encoding the servlet or jsp is using to build
> the html in the first place, hence by making it "global" on the input side
> (you can't easily make output in utf-8 a global setting for all
> servlets/jsps), you could run into issues. That's why the typical approach
> settled on explicitly including the _charset_ parameter - because that one
> is written in the code that is also setting the response output encoding.

Not sure if I get this correctly. I understand that I (the application
developer)
know which encoding I chose for the HTML pages (otherwise I could not
write the _charset_ field anyway).

If I choose the same encoding for all my forms I could easily set
default/fallback encoding which sling
can use when no _charset_ field is explicitly provided.
Seems to be much more convenient then always writing the field or
adding a filter that does that.

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 25.02.11 11:43, "Markus Joschko" <ma...@gmail.com> wrote:
>Nevertheless I wonder why it is necessary to include a mandatory
>parameter with always the same value.
>Can't this be done by sling?

Yes, but it must match the value of the response of the previous request
(i.e. the html containing the form). Because this is the character
encoding that all browsers will use to construct the form - the problem is
only that they don't explicitly mention that in the request.

So it depends what character encoding the servlet or jsp is using to build
the html in the first place, hence by making it "global" on the input side
(you can't easily make output in utf-8 a global setting for all
servlets/jsps), you could run into issues. That's why the typical approach
settled on explicitly including the _charset_ parameter - because that one
is written in the code that is also setting the response output encoding.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Markus Joschko <ma...@gmail.com>.
Hi Julian,

> You can register servlet filters in Sling, but you can also register
> servlet filters in the OSGi HttpService using the whiteboard[0]. As
> the SlingMainServlet runs within the OSGi HttpService, you may have
> more success registering a filter there. I don't know where in the
> stack ParameterSupport is added, so YMMV. Let us know whether this
> does the trick.

Thanks. Using that filter chain does the trick as the filter is added
before any sling processing kicks in.

Nevertheless I wonder why it is necessary to include a mandatory
parameter with always the same value.
Can't this be done by sling?

Regards,
 Markus

> [0] http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard
>
>
>
> On Thu, Feb 24, 2011 at 4:29 PM, Markus Joschko
> <ma...@gmail.com> wrote:
>> Hi Vidar and all,
>> I think that this approach is not working.
>> I have the exact same use case. We don't want to put the _charset_
>> parameter into every form. Therefore I tried to automatically add a
>> _charset_ request parameter to the request in a filter.
>> However that parameter never gets picked up as ParameterSupport is
>> created before the filter gets called (and then uses the reference to
>> the original servletrequest and not the wrapped one).
>> I could theoretically reinstantiate Parametersupport but that requires
>> knowledge of the servlet attribute key where parametersupport is
>> stored. And that is a private variable in parametersupport.
>>
>> Any other chance to not have the _charset_ parameter in every post
>> request sent to the system?
>>
>> Thanks,
>>  Markus
>>
>> On Fri, Feb 11, 2011 at 2:25 PM, Vidar Ramdal <vi...@idium.no> wrote:
>>> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Recently
>>>> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
>>>> stumbled  over this issue too.
>>>>
>>>> I don't want to add _charset_ input to all the forms.
>>>> Is there a way to set the request encoding to UTF-8?
>>>> IMHO it would be better if the request encoding is configurable like it is
>>>> done in Wicket.
>>>>
>>>> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
>>>> using a filter.
>>>> How can I do that in Sling?
>>>
>>> Hi, you can implement the javax.servlet.Filter interface and register
>>> your implementation as a Filter service:
>>>
>>> @Component(immediate = true)
>>> @Properties({
>>>        @Property(name = "filter.scope", value = "request",
>>> propertyPrivate = true),
>>>        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
>>> })
>>> @Services({@Service(javax.servlet.Filter.class)})
>>> public class YourFilter implements javax.servlet.Filter {
>>>  ...
>>> }
>>>
>>>
>>>
>>> --
>>> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
>>> Sommerrogata 13-15, N-0255 Oslo, Norway
>>> + 47 22 00 84 00
>>> Quando omni flunkus moritatus!
>>>
>>
>

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Julian Sedding <js...@gmail.com>.
Hello Markus

You can register servlet filters in Sling, but you can also register
servlet filters in the OSGi HttpService using the whiteboard[0]. As
the SlingMainServlet runs within the OSGi HttpService, you may have
more success registering a filter there. I don't know where in the
stack ParameterSupport is added, so YMMV. Let us know whether this
does the trick.

Regards
Julian

[0] http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-UsingtheWhiteboard



On Thu, Feb 24, 2011 at 4:29 PM, Markus Joschko
<ma...@gmail.com> wrote:
> Hi Vidar and all,
> I think that this approach is not working.
> I have the exact same use case. We don't want to put the _charset_
> parameter into every form. Therefore I tried to automatically add a
> _charset_ request parameter to the request in a filter.
> However that parameter never gets picked up as ParameterSupport is
> created before the filter gets called (and then uses the reference to
> the original servletrequest and not the wrapped one).
> I could theoretically reinstantiate Parametersupport but that requires
> knowledge of the servlet attribute key where parametersupport is
> stored. And that is a private variable in parametersupport.
>
> Any other chance to not have the _charset_ parameter in every post
> request sent to the system?
>
> Thanks,
>  Markus
>
> On Fri, Feb 11, 2011 at 2:25 PM, Vidar Ramdal <vi...@idium.no> wrote:
>> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> Recently
>>> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
>>> stumbled  over this issue too.
>>>
>>> I don't want to add _charset_ input to all the forms.
>>> Is there a way to set the request encoding to UTF-8?
>>> IMHO it would be better if the request encoding is configurable like it is
>>> done in Wicket.
>>>
>>> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
>>> using a filter.
>>> How can I do that in Sling?
>>
>> Hi, you can implement the javax.servlet.Filter interface and register
>> your implementation as a Filter service:
>>
>> @Component(immediate = true)
>> @Properties({
>>        @Property(name = "filter.scope", value = "request",
>> propertyPrivate = true),
>>        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
>> })
>> @Services({@Service(javax.servlet.Filter.class)})
>> public class YourFilter implements javax.servlet.Filter {
>>  ...
>> }
>>
>>
>>
>> --
>> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
>> Sommerrogata 13-15, N-0255 Oslo, Norway
>> + 47 22 00 84 00
>> Quando omni flunkus moritatus!
>>
>

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Markus Joschko <ma...@gmail.com>.
Hi Vidar and all,
I think that this approach is not working.
I have the exact same use case. We don't want to put the _charset_
parameter into every form. Therefore I tried to automatically add a
_charset_ request parameter to the request in a filter.
However that parameter never gets picked up as ParameterSupport is
created before the filter gets called (and then uses the reference to
the original servletrequest and not the wrapped one).
I could theoretically reinstantiate Parametersupport but that requires
knowledge of the servlet attribute key where parametersupport is
stored. And that is a private variable in parametersupport.

Any other chance to not have the _charset_ parameter in every post
request sent to the system?

Thanks,
 Markus

On Fri, Feb 11, 2011 at 2:25 PM, Vidar Ramdal <vi...@idium.no> wrote:
> On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
>>
>> Hi,
>>
>> Recently
>> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
>> stumbled  over this issue too.
>>
>> I don't want to add _charset_ input to all the forms.
>> Is there a way to set the request encoding to UTF-8?
>> IMHO it would be better if the request encoding is configurable like it is
>> done in Wicket.
>>
>> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
>> using a filter.
>> How can I do that in Sling?
>
> Hi, you can implement the javax.servlet.Filter interface and register
> your implementation as a Filter service:
>
> @Component(immediate = true)
> @Properties({
>        @Property(name = "filter.scope", value = "request",
> propertyPrivate = true),
>        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
> })
> @Services({@Service(javax.servlet.Filter.class)})
> public class YourFilter implements javax.servlet.Filter {
>  ...
> }
>
>
>
> --
> Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
> Sommerrogata 13-15, N-0255 Oslo, Norway
> + 47 22 00 84 00
> Quando omni flunkus moritatus!
>

Re: request.getCharacterEncoding() always returns ISO-8859-1

Posted by Vidar Ramdal <vi...@idium.no>.
On Thu, Feb 10, 2011 at 11:56 PM, Peter Dotchev <do...@gmail.com> wrote:
>
> Hi,
>
> Recently
> http://dotev.blogspot.com/2011/02/posting-non-ascii-characters-in-web.html I
> stumbled  over this issue too.
>
> I don't want to add _charset_ input to all the forms.
> Is there a way to set the request encoding to UTF-8?
> IMHO it would be better if the request encoding is configurable like it is
> done in Wicket.
>
> http://wiki.apache.org/tomcat/FAQ/CharacterEncoding Tomcat FAQ  suggests
> using a filter.
> How can I do that in Sling?

Hi, you can implement the javax.servlet.Filter interface and register
your implementation as a Filter service:

@Component(immediate = true)
@Properties({
        @Property(name = "filter.scope", value = "request",
propertyPrivate = true),
        @Property(name = "filter.order", value = "-9", propertyPrivate = true)
})
@Services({@Service(javax.servlet.Filter.class)})
public class YourFilter implements javax.servlet.Filter {
 ...
}



-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00
Quando omni flunkus moritatus!