70
70
71
71
/**
72
72
* Creates instances of {@link org.springframework.web.util.UriComponentsBuilder}
73
- * by pointing to Spring MVC controllers and {@code @RequestMapping} methods.
73
+ * by pointing to {@code @RequestMapping} methods on Spring MVC controllers .
74
74
*
75
- * <p>The static {@code fromXxx(...)} methods prepare links relative to the
76
- * current request as determined by a call to
75
+ * <p>There are several groups of methods:
76
+ * <ul>
77
+ * <li>Static {@code fromXxx(...)} methods to prepare links using information
78
+ * from the current request as determined by a call to
77
79
* {@link org.springframework.web.servlet.support.ServletUriComponentsBuilder#fromCurrentServletMapping()}.
80
+ * <li>Static {@code fromXxx(UriComponentsBuilder,...)} methods can be given
81
+ * a baseUrl when operating outside the context of a request.
82
+ * <li>Instance-based {@code withXxx(...)} methods where an instance of
83
+ * MvcUriComponentsBuilder is created with a baseUrl via
84
+ * {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}.
85
+ * </ul>
78
86
*
79
- * <p>The static {@code fromXxx(UriComponentsBuilder,...)} methods can be given
80
- * the baseUrl when operating outside the context of a request.
81
- *
82
- * <p>You can also create an MvcUriComponentsBuilder instance with a baseUrl
83
- * via {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}
84
- * and then use the non-static {@code withXxx(...)} method variants.
87
+ * <p><strong>Note:</strong> This class extracts and uses values from the headers
88
+ * "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>),
89
+ * or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
90
+ * "Forwarded" is not found, in order to reflect the client-originated protocol
91
+ * and address. As an alternative consider using the
92
+ * {@link org.springframework.web.filter.ForwardedHeaderFilter} to have such
93
+ * headers extracted once and removed, or removed only (without being used).
94
+ * See the reference for further information including security considerations.
85
95
*
86
96
* @author Oliver Gierke
87
97
* @author Rossen Stoyanchev
@@ -142,6 +152,8 @@ public static MvcUriComponentsBuilder relativeTo(UriComponentsBuilder baseUrl) {
142
152
* Create a {@link UriComponentsBuilder} from the mapping of a controller class
143
153
* and current request information including Servlet mapping. If the controller
144
154
* contains multiple mappings, only the first one is used.
155
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
156
+ * and "X-Forwarded-*" headers if found. See class-level docs.
145
157
* @param controllerType the controller to build a URI for
146
158
* @return a UriComponentsBuilder instance (never {@code null})
147
159
*/
@@ -154,6 +166,8 @@ public static UriComponentsBuilder fromController(Class<?> controllerType) {
154
166
* {@code UriComponentsBuilder} representing the base URL. This is useful
155
167
* when using MvcUriComponentsBuilder outside the context of processing a
156
168
* request or to apply a custom baseUrl not matching the current request.
169
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
170
+ * and "X-Forwarded-*" headers if found. See class-level docs.
157
171
* @param builder the builder for the base URL; the builder will be cloned
158
172
* and therefore not modified and may be re-used for further calls.
159
173
* @param controllerType the controller to build a URI for
@@ -171,6 +185,8 @@ public static UriComponentsBuilder fromController(@Nullable UriComponentsBuilder
171
185
* Create a {@link UriComponentsBuilder} from the mapping of a controller
172
186
* method and an array of method argument values. This method delegates
173
187
* to {@link #fromMethod(Class, Method, Object...)}.
188
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
189
+ * and "X-Forwarded-*" headers if found. See class-level docs.
174
190
* @param controllerType the controller
175
191
* @param methodName the method name
176
192
* @param args the argument values
@@ -190,6 +206,8 @@ public static UriComponentsBuilder fromMethodName(Class<?> controllerType,
190
206
* accepts a {@code UriComponentsBuilder} representing the base URL. This is
191
207
* useful when using MvcUriComponentsBuilder outside the context of processing
192
208
* a request or to apply a custom baseUrl not matching the current request.
209
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
210
+ * and "X-Forwarded-*" headers if found. See class-level docs.
193
211
* @param builder the builder for the base URL; the builder will be cloned
194
212
* and therefore not modified and may be re-used for further calls.
195
213
* @param controllerType the controller
@@ -237,6 +255,10 @@ public static UriComponentsBuilder fromMethodName(UriComponentsBuilder builder,
237
255
* controller.getAddressesForCountry("US")
238
256
* builder = MvcUriComponentsBuilder.fromMethodCall(controller);
239
257
* </pre>
258
+ *
259
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
260
+ * and "X-Forwarded-*" headers if found. See class-level docs.
261
+ *
240
262
* @param info either the value returned from a "mock" controller
241
263
* invocation or the "mock" controller itself after an invocation
242
264
* @return a UriComponents instance
@@ -255,6 +277,8 @@ public static UriComponentsBuilder fromMethodCall(Object info) {
255
277
* {@code UriComponentsBuilder} representing the base URL. This is useful
256
278
* when using MvcUriComponentsBuilder outside the context of processing a
257
279
* request or to apply a custom baseUrl not matching the current request.
280
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
281
+ * and "X-Forwarded-*" headers if found. See class-level docs.
258
282
* @param builder the builder for the base URL; the builder will be cloned
259
283
* and therefore not modified and may be re-used for further calls.
260
284
* @param info either the value returned from a "mock" controller
@@ -305,6 +329,10 @@ public static UriComponentsBuilder fromMethodCall(UriComponentsBuilder builder,
305
329
* </pre>
306
330
* <p>Note that it's not necessary to specify all arguments. Only the ones
307
331
* required to prepare the URL, mainly {@code @RequestParam} and {@code @PathVariable}).
332
+ *
333
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
334
+ * and "X-Forwarded-*" headers if found. See class-level docs.
335
+ *
308
336
* @param mappingName the mapping name
309
337
* @return a builder to prepare the URI String
310
338
* @throws IllegalArgumentException if the mapping name is not found or
@@ -320,6 +348,8 @@ public static MethodArgumentBuilder fromMappingName(String mappingName) {
320
348
* {@code UriComponentsBuilder} representing the base URL. This is useful
321
349
* when using MvcUriComponentsBuilder outside the context of processing a
322
350
* request or to apply a custom baseUrl not matching the current request.
351
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
352
+ * and "X-Forwarded-*" headers if found. See class-level docs.
323
353
* @param builder the builder for the base URL; the builder will be cloned
324
354
* and therefore not modified and may be re-used for further calls.
325
355
* @param name the mapping name
@@ -352,6 +382,8 @@ public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuild
352
382
* {@link org.springframework.web.method.support.UriComponentsContributor
353
383
* UriComponentsContributor}) while remaining argument values are ignored and
354
384
* can be {@code null}.
385
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
386
+ * and "X-Forwarded-*" headers if found. See class-level docs.
355
387
* @param controllerType the controller type
356
388
* @param method the controller method
357
389
* @param args argument values for the controller method
@@ -368,6 +400,8 @@ public static UriComponentsBuilder fromMethod(Class<?> controllerType, Method me
368
400
* This is useful when using MvcUriComponentsBuilder outside the context of
369
401
* processing a request or to apply a custom baseUrl not matching the
370
402
* current request.
403
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
404
+ * and "X-Forwarded-*" headers if found. See class-level docs.
371
405
* @param baseUrl the builder for the base URL; the builder will be cloned
372
406
* and therefore not modified and may be re-used for further calls.
373
407
* @param controllerType the controller type
@@ -549,6 +583,9 @@ private static WebApplicationContext getWebApplicationContext() {
549
583
* <pre class="code">
550
584
* MvcUriComponentsBuilder.fromMethodCall(on(FooController.class).getFoo(1)).build();
551
585
* </pre>
586
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
587
+ * and "X-Forwarded-*" headers if found. See class-level docs.
588
+ *
552
589
* @param controllerType the target controller
553
590
*/
554
591
public static <T > T on (Class <T > controllerType ) {
@@ -571,6 +608,8 @@ public static <T> T on(Class<T> controllerType) {
571
608
* fooController.saveFoo(2, null);
572
609
* builder = MvcUriComponentsBuilder.fromMethodCall(fooController);
573
610
* </pre>
611
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
612
+ * and "X-Forwarded-*" headers if found. See class-level docs.
574
613
* @param controllerType the target controller
575
614
*/
576
615
public static <T > T controller (Class <T > controllerType ) {
@@ -626,6 +665,8 @@ private static <T> T initProxy(Class<?> type, ControllerMethodInvocationIntercep
626
665
/**
627
666
* An alternative to {@link #fromController(Class)} for use with an instance
628
667
* of this class created via a call to {@link #relativeTo}.
668
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
669
+ * and "X-Forwarded-*" headers if found. See class-level docs.
629
670
* @since 4.2
630
671
*/
631
672
public UriComponentsBuilder withController (Class <?> controllerType ) {
@@ -635,6 +676,8 @@ public UriComponentsBuilder withController(Class<?> controllerType) {
635
676
/**
636
677
* An alternative to {@link #fromMethodName(Class, String, Object...)}} for
637
678
* use with an instance of this class created via {@link #relativeTo}.
679
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
680
+ * and "X-Forwarded-*" headers if found. See class-level docs.
638
681
* @since 4.2
639
682
*/
640
683
public UriComponentsBuilder withMethodName (Class <?> controllerType , String methodName , Object ... args ) {
@@ -644,6 +687,8 @@ public UriComponentsBuilder withMethodName(Class<?> controllerType, String metho
644
687
/**
645
688
* An alternative to {@link #fromMethodCall(Object)} for use with an instance
646
689
* of this class created via {@link #relativeTo}.
690
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
691
+ * and "X-Forwarded-*" headers if found. See class-level docs.
647
692
* @since 4.2
648
693
*/
649
694
public UriComponentsBuilder withMethodCall (Object invocationInfo ) {
@@ -653,6 +698,8 @@ public UriComponentsBuilder withMethodCall(Object invocationInfo) {
653
698
/**
654
699
* An alternative to {@link #fromMappingName(String)} for use with an instance
655
700
* of this class created via {@link #relativeTo}.
701
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
702
+ * and "X-Forwarded-*" headers if found. See class-level docs.
656
703
* @since 4.2
657
704
*/
658
705
public MethodArgumentBuilder withMappingName (String mappingName ) {
@@ -662,6 +709,8 @@ public MethodArgumentBuilder withMappingName(String mappingName) {
662
709
/**
663
710
* An alternative to {@link #fromMethod(Class, Method, Object...)}
664
711
* for use with an instance of this class created via {@link #relativeTo}.
712
+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
713
+ * and "X-Forwarded-*" headers if found. See class-level docs.
665
714
* @since 4.2
666
715
*/
667
716
public UriComponentsBuilder withMethod (Class <?> controllerType , Method method , Object ... args ) {
0 commit comments