Need to fetch the country code from response Header | Community
Skip to main content
New Participant
Jan 21, 2021 8:58 AM UTC
Solved

Need to fetch the country code from response Header

Hi All,

 

Could anyone give pointers on how i can fetch the country code being passed from cloudflare which is in our response header within the JAVA model ? 

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
kiranparabAccepted solution
Level 3
Jan 21, 2021 2:01 PM UTC

Hi,

 

There are 2 ways, i guess first way is relevant to your requirement

 

1. Getting Value from SlingModel to Sightly -

https://www.argildx.com/technology/sling-model-sightly-part/

- You need to process the logic from cloudfare to get the countrycode and provide back to sightly.

https://helpx.adobe.com/experience-manager/using/sling_model_adaptation.html

 

Example -

@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

 

@SlingObject
private SlingHttpServletRequest request;

 

request.getHeader("HeaderKEY");

 

 

2. Passing the value through Sightly to SlingModel -

https://stackoverflow.com/questions/42324000/how-to-call-sling-model-method-with-input-parameter-aem

- If you want to pass the countrycode from sightly to slingModel

 

Thanks,

Kiran Parab

4 replies

Umesh_Thakur
New Participant
Jan 22, 2021 4:27 AM UTC

Hi @binoy9299,

You can refer the below link for this purpose https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers-

this is just extension on @peter_puzanovs  post.

But this is not the recommended way, specially in multi- region sites you can not relay on any CDN to get the country code.
Normally in multi-region site we maintain site configuration in the form of Context Aware config and from there we used to get it.
So I will suggest first check in your application is there any implementation like that.
if yes then please use it.
Some times it has been observed some issue like in a country like Canada where we have two locale FR and EN then there was some issue in fetching country specific info.
 
 Hope this will help.
Umesh Thakur
Translate
kiranparabAccepted solution
Level 3
Jan 21, 2021 2:01 PM UTC

Hi,

 

There are 2 ways, i guess first way is relevant to your requirement

 

1. Getting Value from SlingModel to Sightly -

https://www.argildx.com/technology/sling-model-sightly-part/

- You need to process the logic from cloudfare to get the countrycode and provide back to sightly.

https://helpx.adobe.com/experience-manager/using/sling_model_adaptation.html

 

Example -

@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

 

@SlingObject
private SlingHttpServletRequest request;

 

request.getHeader("HeaderKEY");

 

 

2. Passing the value through Sightly to SlingModel -

https://stackoverflow.com/questions/42324000/how-to-call-sling-model-method-with-input-parameter-aem

- If you want to pass the countrycode from sightly to slingModel

 

Thanks,

Kiran Parab

Translate
Level 3
Jan 21, 2021 1:53 PM UTC
Hi ,
Translate
Peter_Puzanovs
New Participant
Jan 21, 2021 9:10 AM UTC

Hi Binoy,

 

Define your model with adaptables = { SlingHttpServletRequest.class }, then in your model body add 

 

 

@1961677 private SlingHttpServletRequest request;

 

 

Once you are inside your init method you can ask for the header value 

 

request.getHeader("my-header"));

 


Regards,

Peter

 

Translate