0

how can i parse into url of my current application URI.create(String) when trying to call a number? I would like to parse on the test server http://localhost:8089 etc, but address on the production will be different.

I have tried to get the url

                ((ServletRequestAttributes) RequestContextHolder.
                        currentRequestAttributes()).getRequest();
        String baseEnvLinkURL = "http://" + currentRequest.getLocalName();
        if(currentRequest.getLocalPort() != 80) {
            baseEnvLinkURL += ":" + currentRequest.getLocalPort();
        }
        if(!StringUtils.isEmpty(currentRequest.getContextPath())) {
            baseEnvLinkURL += currentRequest.getContextPath();
        }

but that returns http://0:0:0:0:...:8089/

Is it possible to somehow do it without getting it from different URL? Just parsing some kind of instance of something?

Thanks.

Thomas
  • 169
  • 10
  • Your question needs clarity. Show us code, what you have tried and possibly any error trace. – AzyCrw4282 Mar 17 '20 at 15:30
  • Does this help? https://stackoverflow.com/questions/1490821/whats-the-best-way-to-get-the-current-url-in-spring-mvc – philnash Mar 19 '20 at 04:20

0 Answers0