Till now static content is the part of my WAR package and getting served by tomcat itself but now onwards I want to use CDN to serve static content and I am aware of this question How to use CDN in Spring MVC and about the answer provided, but I think I have different use case which is;
some of my clients are having AWS account and some are having Azure and they don't want any files should get deployed outside their cloud platform, so in that case CDN URLs will be different (even CDN URL will be different for same cloud platform as each client will have different DNS)
So to make the CDN URL dynamic I have option like mentioned here How to use CDN in Spring MVC to keep CDN URL in property file and configure it during deployment, but to adopt this I need to change/look into every JSP (even though I am using sitemesh decorator, some JSPs are having in page reference to some CSS/JS/images)
So I am looking for a way in which, if my JSP is having <img src="<c:url value="/resources/images/logo.png"></c:url>"/> which is getting rendered as <img src="/resources/images/logo.png"> in HTML response, so want something which will resolve <c:url> with appending CDN path before relative path
for eg.
<img src="<c:url value="/resources/images/logo.png"></c:url>"/>
should resolve into HTML response as:
<img src="https://myclientcdn.com/s3/resources/images/logo.png">
where in the CDN URL https://myclientcdn.com/s3/ will kept in property file but I did not required to go and check each JSP to change img tage from this <img src="<c:url value="/resources/images/logo.png"></c:url>"/> to this <img src="<c:url value="${cdnUrl}/resources/images/logo.png"></c:url>"/>
I have tried to change <mvc:resources> in my servlet xml from this <resources mapping="/resources/**" location="/resources/" /> to this <resources mapping="/resources/**" location="http://localhost:2020/cdn" />
as per javadoc location attribute in <mvc:resources> supports HTTP urls
For URL-based resources (e.g. files, HTTP URLs, etc) this property supports a special prefix to indicate the charset associated with the URL so that relative paths appended to it can be encoded correctly, e.g. "[charset=Windows-31J]http://example.org/path".
http://localhost:2020/cdn is simple nginx serving (demonstrating as s3) the images and I can able to browse the image if I enter URL as http://localhost:2020/cdn/resources/images/logo.png
But I am getting 404 in browser after this change.