2

I am using UriComponentsBuilder as such:

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("com.stuff.mycompany:auth/stream/service");
allRequestParams.forEach((k, v) -> builder.queryParam(k, v)); // add all query params
URI uri = builder.encode().build().toUri();

When I run this code, it returns com.stuff.mycompany:?query=whatever, and it truncates the auth/stream/service. I noticed that if I add two slashes after the colon, it works as expected (com.stuff.mycompany:auth/stream/service).

However, I have a requirement to follow and cannot include the double slashes. How can I get this working as expected?

madhead
  • 31,729
  • 16
  • 153
  • 201
yasgur99
  • 756
  • 2
  • 11
  • 32

1 Answers1

1

You can't do that. When you parse that string with UriComponentsBuilder.fromUriString the builder internals looks like this:

scheme = "com.stuff.mycompany"
ssp = "auth/stream/service"

Here SSP is a scheme-specific part. Take a look at queryParam:

public UriComponentsBuilder queryParam(String name, Object... values) {
    Assert.notNull(name, "Name must not be null");
    if (!ObjectUtils.isEmpty(values)) {
        for (Object value : values) {
            String valueAsString = (value != null ? value.toString() : null);
            this.queryParams.add(name, valueAsString);
        }
    }
    else {
        this.queryParams.add(name, null);
    }
    resetSchemeSpecificPart(); //Here is where you lose your SSP
    return this;
}

Looks like Spring / Java implementation of URI is not 100% RFC-compatibel and it does not support queries on opaque URLs. Consider using other implementations.

madhead
  • 31,729
  • 16
  • 153
  • 201