1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -47,6 +47,9 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
47
47
protected ServletUriComponentsBuilder () {
48
48
}
49
49
50
+
51
+ // Factory methods based on a HttpServletRequest
52
+
50
53
/**
51
54
* Prepare a builder from the host, port, scheme, and context path of
52
55
* an HttpServletRequest.
@@ -60,9 +63,7 @@ public static ServletUriComponentsBuilder fromContextPath(HttpServletRequest req
60
63
61
64
/**
62
65
* Prepare a builder from the host, port, scheme, context path, and
63
- * servlet mapping of an HttpServletRequest. The results may vary depending
64
- * on the type of servlet mapping used.
65
- *
66
+ * servlet mapping of the given HttpServletRequest.
66
67
* <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path
67
68
* will end with "/main". If the servlet is mapped otherwise, e.g.
68
69
* {@code "/"} or {@code "*.do"}, the result will be the same as
@@ -114,14 +115,17 @@ public static ServletUriComponentsBuilder fromRequest(HttpServletRequest request
114
115
ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder ();
115
116
builder .scheme (scheme );
116
117
builder .host (host );
117
- if ((scheme . equals ( "http" ) && port != 80 ) || (scheme . equals ( "https" ) && port != 443 )) {
118
+ if (("http" . equals ( scheme ) && port != 80 ) || ("https" . equals ( scheme ) && port != 443 )) {
118
119
builder .port (port );
119
120
}
120
121
builder .path (request .getRequestURI ());
121
122
builder .query (request .getQueryString ());
122
123
return builder ;
123
124
}
124
125
126
+
127
+ // Alternative methods relying on RequestContextHolder to find the request
128
+
125
129
/**
126
130
* Same as {@link #fromContextPath(HttpServletRequest)} except the
127
131
* request is obtained through {@link RequestContextHolder}.
@@ -155,7 +159,7 @@ public static ServletUriComponentsBuilder fromCurrentRequest() {
155
159
}
156
160
157
161
/**
158
- * Obtain the request through {@link RequestContextHolder}.
162
+ * Obtain current request through {@link RequestContextHolder}.
159
163
*/
160
164
protected static HttpServletRequest getCurrentRequest () {
161
165
RequestAttributes requestAttributes = RequestContextHolder .getRequestAttributes ();
0 commit comments