Use spring's URIComponentsBuilder when assembling URLs.