function demo(request,response){
request.getScheme() is returning http instead of returning https.
System.out.println(\"\"+request.getScheme());
}
If your server is running behind a proxy server, make sure your proxy header is set:
proxy_set_header X-Forwarded-Proto $scheme;
Then to get the right scheme
you can use springframework's classes:
HttpRequest httpRequest = new ServletServerHttpRequest(request); //request is HttpServletRequest
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
String scheme = uriComponents.getScheme(); // http/https
I used to have a similar problem with getScheme()
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
I've solved using "//" instead:
String basePath = "//"+request.getServerName()+":"+request.getServerPort()+path+"/";
See the answer https://stackoverflow.com/a/19599143/1524502, and note the issues about being behind a reverse proxy or load balancer. Most likely, that is your problem.
The answerer in that question recommended using
request.getHeader("x-forwarded-proto")
instead, though that is dependent on your load balancer setting the header correctly.