|
|
|
@ -70,18 +70,28 @@ import org.springframework.web.util.UriComponentsBuilder; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates instances of {@link org.springframework.web.util.UriComponentsBuilder} |
|
|
|
* Creates instances of {@link org.springframework.web.util.UriComponentsBuilder} |
|
|
|
* by pointing to Spring MVC controllers and {@code @RequestMapping} methods. |
|
|
|
* by pointing to {@code @RequestMapping} methods on Spring MVC controllers. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>The static {@code fromXxx(...)} methods prepare links relative to the |
|
|
|
* <p>There are several groups of methods: |
|
|
|
* current request as determined by a call to |
|
|
|
* <ul> |
|
|
|
|
|
|
|
* <li>Static {@code fromXxx(...)} methods to prepare links using information |
|
|
|
|
|
|
|
* from the current request as determined by a call to |
|
|
|
* {@link org.springframework.web.servlet.support.ServletUriComponentsBuilder#fromCurrentServletMapping()}. |
|
|
|
* {@link org.springframework.web.servlet.support.ServletUriComponentsBuilder#fromCurrentServletMapping()}. |
|
|
|
|
|
|
|
* <li>Static {@code fromXxx(UriComponentsBuilder,...)} methods can be given |
|
|
|
|
|
|
|
* a baseUrl when operating outside the context of a request. |
|
|
|
|
|
|
|
* <li>Instance-based {@code withXxx(...)} methods where an instance of |
|
|
|
|
|
|
|
* MvcUriComponentsBuilder is created with a baseUrl via |
|
|
|
|
|
|
|
* {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}. |
|
|
|
|
|
|
|
* </ul> |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>The static {@code fromXxx(UriComponentsBuilder,...)} methods can be given |
|
|
|
* <p><strong>Note:</strong> This class extracts and uses values from the headers |
|
|
|
* the baseUrl when operating outside the context of a request. |
|
|
|
* "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>), |
|
|
|
* |
|
|
|
* or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if |
|
|
|
* <p>You can also create an MvcUriComponentsBuilder instance with a baseUrl |
|
|
|
* "Forwarded" is not found, in order to reflect the client-originated protocol |
|
|
|
* via {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)} |
|
|
|
* and address. As an alternative consider using the |
|
|
|
* and then use the non-static {@code withXxx(...)} method variants. |
|
|
|
* {@link org.springframework.web.filter.ForwardedHeaderFilter} to have such |
|
|
|
|
|
|
|
* headers extracted once and removed, or removed only (without being used). |
|
|
|
|
|
|
|
* See the reference for further information including security considerations. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Oliver Gierke |
|
|
|
* @author Oliver Gierke |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
@ -142,6 +152,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* Create a {@link UriComponentsBuilder} from the mapping of a controller class
|
|
|
|
* Create a {@link UriComponentsBuilder} from the mapping of a controller class
|
|
|
|
* and current request information including Servlet mapping. If the controller |
|
|
|
* and current request information including Servlet mapping. If the controller |
|
|
|
* contains multiple mappings, only the first one is used. |
|
|
|
* contains multiple mappings, only the first one is used. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param controllerType the controller to build a URI for |
|
|
|
* @param controllerType the controller to build a URI for |
|
|
|
* @return a UriComponentsBuilder instance (never {@code null}) |
|
|
|
* @return a UriComponentsBuilder instance (never {@code null}) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -154,6 +166,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* {@code UriComponentsBuilder} representing the base URL. This is useful |
|
|
|
* {@code UriComponentsBuilder} representing the base URL. This is useful |
|
|
|
* when using MvcUriComponentsBuilder outside the context of processing a |
|
|
|
* when using MvcUriComponentsBuilder outside the context of processing a |
|
|
|
* request or to apply a custom baseUrl not matching the current request. |
|
|
|
* request or to apply a custom baseUrl not matching the current request. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* @param controllerType the controller to build a URI for |
|
|
|
* @param controllerType the controller to build a URI for |
|
|
|
@ -171,6 +185,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* Create a {@link UriComponentsBuilder} from the mapping of a controller |
|
|
|
* Create a {@link UriComponentsBuilder} from the mapping of a controller |
|
|
|
* method and an array of method argument values. This method delegates |
|
|
|
* method and an array of method argument values. This method delegates |
|
|
|
* to {@link #fromMethod(Class, Method, Object...)}. |
|
|
|
* to {@link #fromMethod(Class, Method, Object...)}. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param controllerType the controller |
|
|
|
* @param controllerType the controller |
|
|
|
* @param methodName the method name |
|
|
|
* @param methodName the method name |
|
|
|
* @param args the argument values |
|
|
|
* @param args the argument values |
|
|
|
@ -190,6 +206,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* accepts a {@code UriComponentsBuilder} representing the base URL. This is |
|
|
|
* accepts a {@code UriComponentsBuilder} representing the base URL. This is |
|
|
|
* useful when using MvcUriComponentsBuilder outside the context of processing |
|
|
|
* useful when using MvcUriComponentsBuilder outside the context of processing |
|
|
|
* a request or to apply a custom baseUrl not matching the current request. |
|
|
|
* a request or to apply a custom baseUrl not matching the current request. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* @param controllerType the controller |
|
|
|
* @param controllerType the controller |
|
|
|
@ -237,6 +255,10 @@ public class MvcUriComponentsBuilder { |
|
|
|
* controller.getAddressesForCountry("US") |
|
|
|
* controller.getAddressesForCountry("US") |
|
|
|
* builder = MvcUriComponentsBuilder.fromMethodCall(controller); |
|
|
|
* builder = MvcUriComponentsBuilder.fromMethodCall(controller); |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
|
|
|
|
* |
|
|
|
* @param info either the value returned from a "mock" controller |
|
|
|
* @param info either the value returned from a "mock" controller |
|
|
|
* invocation or the "mock" controller itself after an invocation |
|
|
|
* invocation or the "mock" controller itself after an invocation |
|
|
|
* @return a UriComponents instance |
|
|
|
* @return a UriComponents instance |
|
|
|
@ -255,6 +277,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* {@code UriComponentsBuilder} representing the base URL. This is useful |
|
|
|
* {@code UriComponentsBuilder} representing the base URL. This is useful |
|
|
|
* when using MvcUriComponentsBuilder outside the context of processing a |
|
|
|
* when using MvcUriComponentsBuilder outside the context of processing a |
|
|
|
* request or to apply a custom baseUrl not matching the current request. |
|
|
|
* request or to apply a custom baseUrl not matching the current request. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* @param info either the value returned from a "mock" controller |
|
|
|
* @param info either the value returned from a "mock" controller |
|
|
|
@ -305,6 +329,10 @@ public class MvcUriComponentsBuilder { |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
* <p>Note that it's not necessary to specify all arguments. Only the ones |
|
|
|
* <p>Note that it's not necessary to specify all arguments. Only the ones |
|
|
|
* required to prepare the URL, mainly {@code @RequestParam} and {@code @PathVariable}). |
|
|
|
* required to prepare the URL, mainly {@code @RequestParam} and {@code @PathVariable}). |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
|
|
|
|
* |
|
|
|
* @param mappingName the mapping name |
|
|
|
* @param mappingName the mapping name |
|
|
|
* @return a builder to prepare the URI String |
|
|
|
* @return a builder to prepare the URI String |
|
|
|
* @throws IllegalArgumentException if the mapping name is not found or |
|
|
|
* @throws IllegalArgumentException if the mapping name is not found or |
|
|
|
@ -320,6 +348,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* {@code UriComponentsBuilder} representing the base URL. This is useful |
|
|
|
* {@code UriComponentsBuilder} representing the base URL. This is useful |
|
|
|
* when using MvcUriComponentsBuilder outside the context of processing a |
|
|
|
* when using MvcUriComponentsBuilder outside the context of processing a |
|
|
|
* request or to apply a custom baseUrl not matching the current request. |
|
|
|
* request or to apply a custom baseUrl not matching the current request. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* @param builder the builder for the base URL; the builder will be cloned |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* @param name the mapping name |
|
|
|
* @param name the mapping name |
|
|
|
@ -352,6 +382,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* {@link org.springframework.web.method.support.UriComponentsContributor |
|
|
|
* {@link org.springframework.web.method.support.UriComponentsContributor |
|
|
|
* UriComponentsContributor}) while remaining argument values are ignored and |
|
|
|
* UriComponentsContributor}) while remaining argument values are ignored and |
|
|
|
* can be {@code null}. |
|
|
|
* can be {@code null}. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param controllerType the controller type |
|
|
|
* @param controllerType the controller type |
|
|
|
* @param method the controller method |
|
|
|
* @param method the controller method |
|
|
|
* @param args argument values for the controller method |
|
|
|
* @param args argument values for the controller method |
|
|
|
@ -368,6 +400,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* This is useful when using MvcUriComponentsBuilder outside the context of |
|
|
|
* This is useful when using MvcUriComponentsBuilder outside the context of |
|
|
|
* processing a request or to apply a custom baseUrl not matching the |
|
|
|
* processing a request or to apply a custom baseUrl not matching the |
|
|
|
* current request. |
|
|
|
* current request. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param baseUrl the builder for the base URL; the builder will be cloned |
|
|
|
* @param baseUrl the builder for the base URL; the builder will be cloned |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* and therefore not modified and may be re-used for further calls. |
|
|
|
* @param controllerType the controller type |
|
|
|
* @param controllerType the controller type |
|
|
|
@ -549,6 +583,9 @@ public class MvcUriComponentsBuilder { |
|
|
|
* <pre class="code"> |
|
|
|
* <pre class="code"> |
|
|
|
* MvcUriComponentsBuilder.fromMethodCall(on(FooController.class).getFoo(1)).build(); |
|
|
|
* MvcUriComponentsBuilder.fromMethodCall(on(FooController.class).getFoo(1)).build(); |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
|
|
|
|
* |
|
|
|
* @param controllerType the target controller |
|
|
|
* @param controllerType the target controller |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static <T> T on(Class<T> controllerType) { |
|
|
|
public static <T> T on(Class<T> controllerType) { |
|
|
|
@ -571,6 +608,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
* fooController.saveFoo(2, null); |
|
|
|
* fooController.saveFoo(2, null); |
|
|
|
* builder = MvcUriComponentsBuilder.fromMethodCall(fooController); |
|
|
|
* builder = MvcUriComponentsBuilder.fromMethodCall(fooController); |
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This method extracts values from "Forwarded" |
|
|
|
|
|
|
|
* and "X-Forwarded-*" headers if found. See class-level docs. |
|
|
|
* @param controllerType the target controller |
|
|
|
* @param controllerType the target controller |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static <T> T controller(Class<T> controllerType) { |
|
|
|
public static <T> T controller(Class<T> controllerType) { |
|
|
|
@ -626,6 +665,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* An alternative to {@link #fromController(Class)} for use with an instance |
|
|
|
* An alternative to {@link #fromController(Class)} for use with an instance |
|
|
|
* of this class created via a call to {@link #relativeTo}. |
|
|
|
* of this class created via a call to {@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 |
|
|
|
* @since 4.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UriComponentsBuilder withController(Class<?> controllerType) { |
|
|
|
public UriComponentsBuilder withController(Class<?> controllerType) { |
|
|
|
@ -635,6 +676,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* An alternative to {@link #fromMethodName(Class, String, Object...)}} for |
|
|
|
* An alternative to {@link #fromMethodName(Class, String, Object...)}} for |
|
|
|
* use with an instance of this class created via {@link #relativeTo}. |
|
|
|
* 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 |
|
|
|
* @since 4.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UriComponentsBuilder withMethodName(Class<?> controllerType, String methodName, Object... args) { |
|
|
|
public UriComponentsBuilder withMethodName(Class<?> controllerType, String methodName, Object... args) { |
|
|
|
@ -644,6 +687,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* An alternative to {@link #fromMethodCall(Object)} for use with an instance |
|
|
|
* An alternative to {@link #fromMethodCall(Object)} for use with an instance |
|
|
|
* of this class created via {@link #relativeTo}. |
|
|
|
* 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 |
|
|
|
* @since 4.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UriComponentsBuilder withMethodCall(Object invocationInfo) { |
|
|
|
public UriComponentsBuilder withMethodCall(Object invocationInfo) { |
|
|
|
@ -653,6 +698,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* An alternative to {@link #fromMappingName(String)} for use with an instance |
|
|
|
* An alternative to {@link #fromMappingName(String)} for use with an instance |
|
|
|
* of this class created via {@link #relativeTo}. |
|
|
|
* 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 |
|
|
|
* @since 4.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MethodArgumentBuilder withMappingName(String mappingName) { |
|
|
|
public MethodArgumentBuilder withMappingName(String mappingName) { |
|
|
|
@ -662,6 +709,8 @@ public class MvcUriComponentsBuilder { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* An alternative to {@link #fromMethod(Class, Method, Object...)} |
|
|
|
* An alternative to {@link #fromMethod(Class, Method, Object...)} |
|
|
|
* for use with an instance of this class created via {@link #relativeTo}. |
|
|
|
* 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 |
|
|
|
* @since 4.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public UriComponentsBuilder withMethod(Class<?> controllerType, Method method, Object... args) { |
|
|
|
public UriComponentsBuilder withMethod(Class<?> controllerType, Method method, Object... args) { |
|
|
|
|