querybuilder returning ISO-8859-1 instead of utf8

Avatar

Avatar
Affirm 5
Level 4
TB3dock
Level 4

Likes

37 likes

Total Posts

223 posts

Correct reply

5 solutions
Top badges earned
Affirm 5
Ignite 10
Boost 25
Give Back 25
Validate 10
View profile

Avatar
Affirm 5
Level 4
TB3dock
Level 4

Likes

37 likes

Total Posts

223 posts

Correct reply

5 solutions
Top badges earned
Affirm 5
Ignite 10
Boost 25
Give Back 25
Validate 10
View profile
TB3dock
Level 4

02-05-2021

I am using querybuilder to read the properties of some text components. If I enter UTF8 chars (e.g ü) into the Adobe author editor (and I can see from the page source that its set to UTF8), I get ISO-8859-1 out.

When I get the ValueMap from the component in a servlet, I write the results to a file, and to the servlet response writer also.  In the file, if I open it as a ISO-8859-1 I see ü. If i open it as a utf8 file (in VS code), i get a back "?".  In postman I see a black "?" and also on the resultant webpage (which has utf8 set in the header).

NOTE: we have set the servlet parameter encoding to UTF8 in the OSGi config as per: http://adobeaemtips.blogspot.com/2015/11/utf-8-encoding-in-aem.html

Any ideas?

FYI, I also tried with Content-Type: application/json; charset=utf-8 request header.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

593 likes

Total Posts

705 posts

Correct reply

207 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

02-05-2021

Hi @TB3dock 

 

Please add the below entry in "Apache Sling Main Servlet" config and try.

 

Additional response headers:
                 Content-Type=text/html;charset=utf-8

 

Thanks!

TB3dock
Hi, thanks for the reply. do you mean osgi config, or the servlet source code? Setting the header probably wont have any effect, as the encoding is wrong right after reading it from the query builder result and logging it.
TB3dock
Well, I found "Apache Sling Main Servlet" in OSGI config, and set the header as you suggest, and, surprisingly, it worked. Surely it should be the request headers which mandate the charset, not a manually set response header? Anyway, thanks for the tip. The problem now is is there any way to set this via code, so that other developers get this setting when they build and deploy locally?
asutosh_jena

Hi @TB3dock 

 

You can add this as an OSGi config with org.apache.sling.engine.impl.SlingMainServlet as sling.additional.response.headers property and checkin via code. It will be available for all developers.

 

Thanks!

TB3dock

Hi. I have created a file called ../config/org.apache.engine.impl.SlingMainServlet.cfg.json, but am not sure what to put in it. My guess would be:

 

sling.additional.response.headers:"Content-Type=test/html; charset=utf-8"

 

But presumably this will overwrite the existing 2 defined headers?

The osgi editor page says this|:

 

Provides mappings for additional response headers Each entry is of the form 'bundleId [ ":" responseHeaderName ] "=" responseHeaderValue' (sling.additional.response.headers)

 

But this makes no sense -  in json, you have xxx:"yyy", but this is saying we should be using :xxx=yyy which seems wrong.

 

asutosh_jena

Hi @TB3dock 

 

Please create a file with org.apache.sling.engine.impl.SlingMainServlet.cfg.json name under the config folder.

 

Add the below content to it.

 

{
"sling.max.calls": "1000",
"sling.max.inclusions": "50",
"sling.max.record.requests": "20",
"sling.additional.response.headers":[
"X-Content-Type-Options=nosniff",
"Content-Type=text/html;charset=utf-8"
]
}

 

Thanks! 

Answers (1)

Answers (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,442 likes

Total Posts

3,318 posts

Correct reply

941 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

02-05-2021

you can try escaping HTML character e.g.

org.apache.commons.lang.StringEscapeUtils.escapeHtml("aäuüöo");