Skip to content

Instantly share code, notes, and snippets.

@odrotbohm
Created January 13, 2012 14:31
Show Gist options
  • Save odrotbohm/1606493 to your computer and use it in GitHub Desktop.
Save odrotbohm/1606493 to your computer and use it in GitHub Desktop.
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest("GET", "http://localhost:8080/foo/bar?foo=bar");
String string = ServletUriComponentsBuilder.fromRequest(httpServletRequest).path("/something").build().toUriString();
assertThat(string, is("http://localhost:8080/foo/bar/something?foo=bar"));
java.lang.AssertionError:
Expected: is "http://localhost:8080/foo/bar/something?foo=bar"
got: "http://localhost/http://localhost:8080/foo/bar?foo=bar/something"
@rstoyanchev
Copy link

MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/bar");
request.setProtocol("http");
request.setServerName("localhost");
request.setServerPort(8080);
request.setQueryString("foo=bar");
String actual = ServletUriComponentsBuilder.fromRequest(request).path("/something").build().toUriString();

assertEquals("http://localhost:8080/foo/bar/something?foo=bar", actual);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment