Hello Community - I am using the request object ${request.serverName} to retrieve the domain name. If I access the dispatcher URL, it is returning the AEM Publish instance name(which is incorrect) instead of the actual domain name of the page I am trying to access.
i.e If I try to access the page: https://www.example.com/test.html - It should return "www.example.com"
Accessing AEM Publish instance: https://aempublish:8080/test.html - should return "aempublish"
I have even verified the dispatcher configs (VirtualHost entrues). Can someone tell me how can I fix this?
Views
Replies
Total Likes
@aemninja You might have to try ${request.requestURL.toString}
https://stackoverflow.com/a/56376338/8671041
Thanks
Veena ✌
Actually request.ServerName is showing the value of the publish instance instead of dispatcher URL domain name. The same is working as expected in other environment.
Hi @aemninja
I am using the below code in Servlet to get the request domain along with port.
String domain = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
Thanks!
It works in one environment but doesn’t work in other environment. In the working environment. We don’t use any servlet. We are using only thr request object.
When you say it works in one env and does not work in other. I did not get it.
You can read the value from request and check the value and if it's working in one env, it should work in other as well. what's the difference in environment?
The problem is I am getting the value but instead of dispatcher url domain name (The page that I am accessing) I am getting AEM Publish instance. I have compared with other environment but not able to figure it out.
@aemninja If you use it with HTL, your pages are cached right? HTL will be cached at the disaptcher and the request will never reach publish except the first request.
So you need to either disable caching of the HTML where you use this component or you need to get this value from a servlet and the servlet needs to be triggered using JS.
Thanks!
@asutosh_jena - I am using SDI. The request will reach the publish instance for every request. Also what I observed is, I am getting the AEM Publish instance information in the response header(Access-Control-Allow-Origin).
i.e Access-Control-Allow-Origin: AEM Publish instance instead of Dispatcher Domain.
so where are you using the request object ? in sling models or servlet?
I am not using any servlet or model. Using HTL to retrieve the domain name from the request object.
There are two ways to do it,
1. create a sling model and get a domain name by using request object. and pass that variable value to HTL.
2. Write a JS where you will get teh domain name, set the attribute value to HTL.
Views
Likes
Replies