68
68
69
69
/**
70
70
* Creates instances of {@link org.springframework.web.util.UriComponentsBuilder}
71
- * by pointing to Spring MVC controllers and {@code @RequestMapping} methods.
71
+ * by pointing to {@code @RequestMapping} methods on Spring MVC controllers .
72
72
*
73
- * <p>The static {@code fromXxx(...)} methods prepare links relative to the
74
- * current request as determined by a call to
73
+ * <p>There are several groups of methods:
74
+ * <ul>
75
+ * <li>Static {@code fromXxx(...)} methods to prepare links using information
76
+ * from the current request as determined by a call to
75
77
* {@link org.springframework.web.servlet.support.ServletUriComponentsBuilder#fromCurrentServletMapping()}.
78
+ * <li>Static {@code fromXxx(UriComponentsBuilder,...)} methods can be given
79
+ * a baseUrl when operating outside the context of a request.
80
+ * <li>Instance-based {@code withXxx(...)} methods where an instance of
81
+ * MvcUriComponentsBuilder is created with a baseUrl via
82
+ * {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}.
83
+ * </ul>
76
84
*
77
- * <p>The static {@code fromXxx(UriComponentsBuilder,...)} methods can be given
78
- * the baseUrl when operating outside the context of a request.
79
- *
80
- * <p>You can also create an MvcUriComponentsBuilder instance with a baseUrl
81
- * via {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}
82
- * and then use the non-static {@code withXxx(...)} method variants.
85
+ * <p><strong>Note:</strong> This class extracts and uses values from the headers
86
+ * "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>),
87
+ * or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
88
+ * "Forwarded" is not found, in order to reflect the client-originated protocol
89
+ * and address. As an alternative consider using the
90
+ * {@link org.springframework.web.filter.ForwardedHeaderFilter} to have such
91
+ * headers extracted once and removed, or removed only (without being used).
92
+ * See the reference for further information including security considerations.
83
93
*
84
94
* @author Oliver Gierke
85
95
* @author Rossen Stoyanchev
@@ -140,6 +150,8 @@ public static MvcUriComponentsBuilder relativeTo(UriComponentsBuilder baseUrl) {
140
150
* Create a {@link UriComponentsBuilder} from the mapping of a controller class
141
151
* and current request information including Servlet mapping. If the controller
142
152
* contains multiple mappings, only the first one is used.
153
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
154
+ * and "X-Forwarded-*" headers if found. See class-level docs.
143
155
* @param controllerType the controller to build a URI for
144
156
* @return a UriComponentsBuilder instance (never {@code null})
145
157
*/
@@ -152,6 +164,8 @@ public static UriComponentsBuilder fromController(Class<?> controllerType) {
152
164
* {@code UriComponentsBuilder} representing the base URL. This is useful
153
165
* when using MvcUriComponentsBuilder outside the context of processing a
154
166
* request or to apply a custom baseUrl not matching the current request.
167
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
168
+ * and "X-Forwarded-*" headers if found. See class-level docs.
155
169
* @param builder the builder for the base URL; the builder will be cloned
156
170
* and therefore not modified and may be re-used for further calls.
157
171
* @param controllerType the controller to build a URI for
@@ -169,6 +183,8 @@ public static UriComponentsBuilder fromController(UriComponentsBuilder builder,
169
183
* Create a {@link UriComponentsBuilder} from the mapping of a controller
170
184
* method and an array of method argument values. This method delegates
171
185
* to {@link #fromMethod(Class, Method, Object...)}.
186
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
187
+ * and "X-Forwarded-*" headers if found. See class-level docs.
172
188
* @param controllerType the controller
173
189
* @param methodName the method name
174
190
* @param args the argument values
@@ -188,6 +204,8 @@ public static UriComponentsBuilder fromMethodName(Class<?> controllerType,
188
204
* accepts a {@code UriComponentsBuilder} representing the base URL. This is
189
205
* useful when using MvcUriComponentsBuilder outside the context of processing
190
206
* a request or to apply a custom baseUrl not matching the current request.
207
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
208
+ * and "X-Forwarded-*" headers if found. See class-level docs.
191
209
* @param builder the builder for the base URL; the builder will be cloned
192
210
* and therefore not modified and may be re-used for further calls.
193
211
* @param controllerType the controller
@@ -235,6 +253,10 @@ public static UriComponentsBuilder fromMethodName(UriComponentsBuilder builder,
235
253
* controller.getAddressesForCountry("US")
236
254
* builder = MvcUriComponentsBuilder.fromMethodCall(controller);
237
255
* </pre>
256
+ *
257
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
258
+ * and "X-Forwarded-*" headers if found. See class-level docs.
259
+ *
238
260
* @param info either the value returned from a "mock" controller
239
261
* invocation or the "mock" controller itself after an invocation
240
262
* @return a UriComponents instance
@@ -253,6 +275,8 @@ public static UriComponentsBuilder fromMethodCall(Object info) {
253
275
* {@code UriComponentsBuilder} representing the base URL. This is useful
254
276
* when using MvcUriComponentsBuilder outside the context of processing a
255
277
* request or to apply a custom baseUrl not matching the current request.
278
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
279
+ * and "X-Forwarded-*" headers if found. See class-level docs.
256
280
* @param builder the builder for the base URL; the builder will be cloned
257
281
* and therefore not modified and may be re-used for further calls.
258
282
* @param info either the value returned from a "mock" controller
@@ -303,6 +327,10 @@ public static UriComponentsBuilder fromMethodCall(UriComponentsBuilder builder,
303
327
* </pre>
304
328
* <p>Note that it's not necessary to specify all arguments. Only the ones
305
329
* required to prepare the URL, mainly {@code @RequestParam} and {@code @PathVariable}).
330
+ *
331
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
332
+ * and "X-Forwarded-*" headers if found. See class-level docs.
333
+ *
306
334
* @param mappingName the mapping name
307
335
* @return a builder to prepare the URI String
308
336
* @throws IllegalArgumentException if the mapping name is not found or
@@ -318,6 +346,8 @@ public static MethodArgumentBuilder fromMappingName(String mappingName) {
318
346
* {@code UriComponentsBuilder} representing the base URL. This is useful
319
347
* when using MvcUriComponentsBuilder outside the context of processing a
320
348
* request or to apply a custom baseUrl not matching the current request.
349
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
350
+ * and "X-Forwarded-*" headers if found. See class-level docs.
321
351
* @param builder the builder for the base URL; the builder will be cloned
322
352
* and therefore not modified and may be re-used for further calls.
323
353
* @param name the mapping name
@@ -350,6 +380,8 @@ public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder
350
380
* {@link org.springframework.web.method.support.UriComponentsContributor
351
381
* UriComponentsContributor}) while remaining argument values are ignored and
352
382
* can be {@code null}.
383
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
384
+ * and "X-Forwarded-*" headers if found. See class-level docs.
353
385
* @param controllerType the controller type
354
386
* @param method the controller method
355
387
* @param args argument values for the controller method
@@ -366,6 +398,8 @@ public static UriComponentsBuilder fromMethod(Class<?> controllerType, Method me
366
398
* This is useful when using MvcUriComponentsBuilder outside the context of
367
399
* processing a request or to apply a custom baseUrl not matching the
368
400
* current request.
401
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
402
+ * and "X-Forwarded-*" headers if found. See class-level docs.
369
403
* @param baseUrl the builder for the base URL; the builder will be cloned
370
404
* and therefore not modified and may be re-used for further calls.
371
405
* @param controllerType the controller type
@@ -557,6 +591,9 @@ private static WebApplicationContext getWebApplicationContext() {
557
591
* <pre class="code">
558
592
* MvcUriComponentsBuilder.fromMethodCall(on(FooController.class).getFoo(1)).build();
559
593
* </pre>
594
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
595
+ * and "X-Forwarded-*" headers if found. See class-level docs.
596
+ *
560
597
* @param controllerType the target controller
561
598
*/
562
599
public static <T > T on (Class <T > controllerType ) {
@@ -579,6 +616,8 @@ public static <T> T on(Class<T> controllerType) {
579
616
* fooController.saveFoo(2, null);
580
617
* builder = MvcUriComponentsBuilder.fromMethodCall(fooController);
581
618
* </pre>
619
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
620
+ * and "X-Forwarded-*" headers if found. See class-level docs.
582
621
* @param controllerType the target controller
583
622
*/
584
623
public static <T > T controller (Class <T > controllerType ) {
@@ -634,6 +673,8 @@ private static <T> T initProxy(Class<?> type, ControllerMethodInvocationIntercep
634
673
/**
635
674
* An alternative to {@link #fromController(Class)} for use with an instance
636
675
* of this class created via a call to {@link #relativeTo}.
676
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
677
+ * and "X-Forwarded-*" headers if found. See class-level docs.
637
678
* @since 4.2
638
679
*/
639
680
public UriComponentsBuilder withController (Class <?> controllerType ) {
@@ -643,6 +684,8 @@ public UriComponentsBuilder withController(Class<?> controllerType) {
643
684
/**
644
685
* An alternative to {@link #fromMethodName(Class, String, Object...)}} for
645
686
* use with an instance of this class created via {@link #relativeTo}.
687
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
688
+ * and "X-Forwarded-*" headers if found. See class-level docs.
646
689
* @since 4.2
647
690
*/
648
691
public UriComponentsBuilder withMethodName (Class <?> controllerType , String methodName , Object ... args ) {
@@ -652,6 +695,8 @@ public UriComponentsBuilder withMethodName(Class<?> controllerType, String metho
652
695
/**
653
696
* An alternative to {@link #fromMethodCall(Object)} for use with an instance
654
697
* of this class created via {@link #relativeTo}.
698
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
699
+ * and "X-Forwarded-*" headers if found. See class-level docs.
655
700
* @since 4.2
656
701
*/
657
702
public UriComponentsBuilder withMethodCall (Object invocationInfo ) {
@@ -661,6 +706,8 @@ public UriComponentsBuilder withMethodCall(Object invocationInfo) {
661
706
/**
662
707
* An alternative to {@link #fromMappingName(String)} for use with an instance
663
708
* of this class created via {@link #relativeTo}.
709
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
710
+ * and "X-Forwarded-*" headers if found. See class-level docs.
664
711
* @since 4.2
665
712
*/
666
713
public MethodArgumentBuilder withMappingName (String mappingName ) {
@@ -670,6 +717,8 @@ public MethodArgumentBuilder withMappingName(String mappingName) {
670
717
/**
671
718
* An alternative to {@link #fromMethod(Class, Method, Object...)}
672
719
* for use with an instance of this class created via {@link #relativeTo}.
720
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
721
+ * and "X-Forwarded-*" headers if found. See class-level docs.
673
722
* @since 4.2
674
723
*/
675
724
public UriComponentsBuilder withMethod (Class <?> controllerType , Method method , Object ... args ) {
0 commit comments