Hi,
I will be uploading an image to aem server using a service that aem or coustom code provides (www.abc.com/upload/image.json)
Now this request is triggered from https://uploadservice.com . How could i get the host name in aem servlet (uploadservice.com) and ip address of this when it is triggred from (uploadservice.com).
What will code for this??
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
What is this request? How will it invoke the above code if you access the URL.
Can you please provide info how are you integrating this code?
Thanks!
Hi @srinivas_chann1 ,
Host name - Host name can be obtained from the SlingHTTPServletRequest object header "referer". Sample -
request.getHeader("referer");
IP address - There are few methods that help here like getRemoteAddr()/getRemoteHost() of SlingHTTPServletRequest object or the request header value "X-Forwarded-For". But, they can't be entirely relied on, because for most of the scenarios you may be receiving the IP address of the Default Gateway or proxy.
Thanks,
Fani
Please use the below code. I use it and it works perfectly fine.
public static String getClientIPAddress(HttpServletRequest request) {
String xForwardedForHeader = request.getHeader(HttpHeaders.X_FORWARDED_FOR);
if (xForwardedForHeader == null) {
return request.getRemoteAddr();
} else {
return new StringTokenizer(xForwardedForHeader, ",").nextToken().trim();
}
}
Thanks!
Hi ,
I tried it my local with the above code using postman to trigger the reuqest( http://localhost:4502/upload/image.json) .In the logs it does not print any value for this ??
What could be the reason
Thanks
What is this request? How will it invoke the above code if you access the URL.
Can you please provide info how are you integrating this code?
Thanks!
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies