I think, I want to use URIBuilder
here but not entirely sure...
I have the following code:
String serverURL = getServerURL(); // ex: "http://somesrv.example.com"
String appURL = getAppURL(); // ex: "http://myapp.example.com"
I now need to add the two together, so that it produces the following:
http://somesrv.example.com/fizz?widget=http://myapp.example.com
But I don't just want to use string bashing (def url = serverURL + "/fizz?widget=" + appURL
). Plus I'd like URL encoding, etc. Again, I think URLBuilder
is the way to go here, but not sure.
I've seen an example uses JAX-RS' UriBuilder
:
String url = UriBuilder.fromUri(serverURL).path("fizz").queryParam("widget", appURL).build();
Now I just need to figure out how to do this in Groovy?