This is an absolute URI of the server:
URI base = new URI("http://localhost/root?a=1");
This is a relative URI:
URI rel = new URI("/child?b=5");
Now I’m trying to apply relative one to the absolute and receive:
URI combined = base + rel; // somehow
assert combined.equals(new URI("http://localhost/root/child?a=1&b=5"));
Is it possible to do such a manipulation with JDK or some library?
To pass on base url’s parameters to merged url, you’ll have to extract them manually by calling URL#getQuery and append them to new URL
Something like,
It will take an if() to decide whether an ‘&’ is required to join them depending on what mergedUrl looks like.