Unable to read Headers in AEM Cloud Dev environment | Community
Skip to main content
Prince_Shivhare
Community Advisor
Community Advisor
February 18, 2024
Solved

Unable to read Headers in AEM Cloud Dev environment

  • February 18, 2024
  • 4 replies
  • 1851 views

Hey Community,

Hope you're doing well.

I'm facing an issue with reading headers such as clientId, clientSecret, and orgId in the AEM cloud publish URL and domain URL via POSTMAN. I have a servlet where I'm reading all these headers, and it's working fine on localhost but not in DEV.

Has anyone encountered a similar situation? Any insights would be greatly appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AMANATH_ULLAH

@prince_shivhare  

Can you please check if you have added these headers in

clientheaders section in dispatcher configurations.

4 replies

Imran__Khan
Community Advisor
Community Advisor
February 18, 2024

Beloe os the correct way to read any header for http protocol, request.getHeader(). For example to read User-Agent from below header, request.getHeader("User-Agent"))

Please check one in browser console or print as part of error.log all header we are getting and validate the required one is there or not.

AMANATH_ULLAH
Community Advisor
AMANATH_ULLAHCommunity AdvisorAccepted solution
Community Advisor
February 18, 2024

@prince_shivhare  

Can you please check if you have added these headers in

clientheaders section in dispatcher configurations.
Amanath Ullah
aanchal-sikka
Community Advisor
Community Advisor
February 18, 2024

Hello @prince_shivhare 

 

Requesting you to please check, if this helps https://techrevelhub.wordpress.com/2023/09/05/exploring-aem-request-and-response-headers-analysis-of-browser-cdn-and-dispatcher/#add-custom-header

 

Step-1: Configure AEM Dispatcher to allow custom headers to pass-through

This you can validate from Dispatcher logs. Details are present on blog

 

Step-2: Whitelist custom headers on CDN 

If the dispatcher is sending the response headers, but you're not receiving them, it's possible that they're being blocked by the CDN.

 

I'm unsure about the process on Fastly for Cloud and whether an Adobe ticket is required for this issue. However, please share your findings

Aanchal Sikka
Prince_Shivhare
Community Advisor
Community Advisor
February 19, 2024

@aanchal-sikka 

It was /clientheaders where I had to allow the custom header. but then I got another error while trying to connect to the exchange token URL internally via servlet.

"Server returned HTTP response code: 400 for URL: https://ims-na1.adobelogin.com/ims/exchange/jwt"
 

So basically I am first generating the JWT token using the privatekey.pem file and then hitting the exchange URL internally via servlet to generate the access token so that I can access the AEM author environment to access the resource.

String body = "client_id=" + URLEncoder.encode(clientId, "UTF-8") + "&" + "client_secret="
+ URLEncoder.encode(clientSecret, "UTF-8") + "&" + "jwt_token=" + URLEncoder.encode(jwtToken, "UTF-8");

try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.writeBytes(body);
}

try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String inputLine;
StringBuffer stringBuffer = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
stringBuffer.append(inputLine);
}
response.getWriter().print(stringBuffer);
}

I followed the below URL but not sure what is casuing the issue. do I have to allow my cloud instance to access EXCHANGE TOKEN url?


It's working well in localhost and breaking in DEV in second try statement.


https://techrevel.blog/2023/09/06/access-restricted-resources-on-aemaacs-with-java-and-service-accounts/

kautuk_sahni
Community Manager
Community Manager
February 21, 2024

@prince_shivhare Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni