/** * An alternative to {@link #fromMethodCall(Object)} for use with an instance * of this class created via {@link #relativeTo}. * <p><strong>Note:</strong> This method extracts values from "Forwarded" * and "X-Forwarded-*" headers if found. See class-level docs. * @since 4.2 */ public UriComponentsBuilder withMethodCall(Object invocationInfo) { return fromMethodCall(this.baseUrl, invocationInfo); }
/** * An alternative to {@link #fromMethodCall(Object)} for use with an instance * of this class created via {@link #relativeTo}. * <p><strong>Note:</strong> This method extracts values from "Forwarded" * and "X-Forwarded-*" headers if found. See class-level docs. * @since 4.2 */ public UriComponentsBuilder withMethodCall(Object invocationInfo) { return fromMethodCall(this.baseUrl, invocationInfo); }
@Test(expected = IllegalStateException.class) // SPR-16710 public void fromMethodCallWithStringReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithString.class).getBooking(21L)).buildAndExpand(42); assertEquals("http://localhost/hotels/42/bookings/21", uriComponents.encode().toUri().toString()); }
@Test // SPR-16710 public void fromMethodCallWithModelAndViewReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithModelAndView.class).getBooking(21L)).buildAndExpand(42); assertEquals("http://localhost/hotels/42/bookings/21", uriComponents.encode().toUri().toString()); }
@Test public void fromMethodCallWithPathVariableAndMultiValueRequestParams() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodWithMultiValueRequestParams("1", Arrays.asList(3, 7), 5)).build(); assertThat(uriComponents.getPath(), is("/something/1/foo")); MultiValueMap<String, String> queryParams = uriComponents.getQueryParams(); assertThat(queryParams.get("limit"), contains("5")); assertThat(queryParams.get("items"), containsInAnyOrder("3", "7")); }
@Test // SPR-16710 public void fromMethodCallWithObjectReturnType() { UriComponents uriComponents = fromMethodCall( on(BookingControllerWithObject.class).getBooking(21L)).buildAndExpand(42); assertEquals("http://localhost/hotels/42/bookings/21", uriComponents.encode().toUri().toString()); }
@Test public void fromMethodCallWithPathVariableAndRequestParams() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodForNextPage("1", 10, 5)).build(); assertThat(uriComponents.getPath(), is("/something/1/foo")); MultiValueMap<String, String> queryParams = uriComponents.getQueryParams(); assertThat(queryParams.get("limit"), contains("5")); assertThat(queryParams.get("offset"), contains("10")); }
@Test public void fromMethodCallWithCustomBaseUrlViaStaticCall() { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base"); UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build(); assertEquals("http://example.org:9090/base/something/else", uriComponents.toString()); assertEquals("http://example.org:9090/base", builder.toUriString()); }
@Test public void fromMethodCallPlain() { UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build(); assertThat(uriComponents.toUriString(), startsWith("http://localhost")); assertThat(uriComponents.toUriString(), endsWith("/something/else")); }
@Test public void fromMethodCallOnSubclass() { UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build(); assertThat(uriComponents.toUriString(), startsWith("http://localhost")); assertThat(uriComponents.toUriString(), endsWith("/extended/else")); }
@Test public void fromMethodCallWithPathVariable() { UriComponents uriComponents = fromMethodCall( on(ControllerWithMethods.class).methodWithPathVariable("1")).build(); assertThat(uriComponents.toUriString(), startsWith("http://localhost")); assertThat(uriComponents.toUriString(), endsWith("/something/1/foo")); }
@Test public void fromMethodCallWithTypeLevelUriVars() { UriComponents uriComponents = fromMethodCall( on(PersonsAddressesController.class).getAddressesForCountry("DE")).buildAndExpand(15); assertThat(uriComponents.toUriString(), endsWith("/people/15/addresses/DE")); }
@Test public void fromMethodWithPrefix() { initWebApplicationContext(PathPrefixWebConfig.class); this.request.setServerName("example.org"); this.request.setServerPort(9999); this.request.setContextPath("/base"); assertEquals("http://example.org:9999/base/api/people/123/addresses/DE", fromMethodCall(on(PersonsAddressesController.class).getAddressesForCountry("DE")) .buildAndExpand("123").toString()); }
/** * An alternative to {@link #fromMethodCall(Object)} for use with an instance * of this class created via {@link #relativeTo}. * <p><strong>Note:</strong> This method extracts values from "Forwarded" * and "X-Forwarded-*" headers if found. See class-level docs. * @since 4.2 */ public UriComponentsBuilder withMethodCall(Object invocationInfo) { return fromMethodCall(this.baseUrl, invocationInfo); }
.fromMethodCall(on(YarnContainerClusterMvcEndpoint.class).clusterInfo(request.getClusterId())).build(); responseHeaders.setLocation(uriComponents.toUri());