Expand my Community achievements bar.

SOLVED

Unable to read Headers in AEM Cloud Dev environment

Avatar

Community Advisor

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.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Prince_Shivhare  

Can you please check if you have added these headers in

clientheaders section in dispatcher configurations.

View solution in original post

5 Replies

Avatar

Community Advisor

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.

Avatar

Correct answer by
Community Advisor

@Prince_Shivhare  

Can you please check if you have added these headers in

clientheaders section in dispatcher configurations.

Avatar

Community Advisor

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...

 

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

Avatar

Community Advisor

@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-accou...

Avatar

Administrator

@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