0

There is a clean way to build this examples with Apache URIBuilder?

"http://host/path", passing "path2" -> "http://host/path/path2"
"http://host/path", passing "/path2" -> "http://host/path2"

"resolve" method is not working, it always return:

http://host/path2

Thanks.

Phaedra
  • 237
  • 1
  • 3
  • 11

1 Answers1

1

You should add a trailing slash on your baseurl.

new java.net.URI("http://host/path/").resolve("path2");  // http://host/path/path2
new java.net.URI("http://host/path/").resolve("/path2"); // http://host/path2

Without the trailing slash path will not be handled as directory. Than it does not matter if you resolve a absolute or relative path2 because they are resolved against host/

lefloh
  • 10,653
  • 3
  • 28
  • 50