Move RequestPath to parent server package

This commit is contained in:
Rossen Stoyanchev
2017-07-28 11:55:18 +02:00
parent 4630e62c20
commit 6855a85c41
37 changed files with 68 additions and 49 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.http.server.reactive;
package org.springframework.http.server;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.http.server.reactive;
package org.springframework.http.server;
import java.net.URI;
import java.util.List;
@@ -44,7 +44,7 @@ class DefaultRequestPath implements RequestPath {
this.pathWithinApplication = extractPathWithinApplication(this.fullPath, this.contextPath);
}
DefaultRequestPath(RequestPath requestPath, @Nullable String contextPath) {
private DefaultRequestPath(RequestPath requestPath, String contextPath) {
this.fullPath = requestPath;
this.contextPath = initContextPath(this.fullPath, contextPath);
this.pathWithinApplication = extractPathWithinApplication(this.fullPath, this.contextPath);
@@ -104,6 +104,11 @@ class DefaultRequestPath implements RequestPath {
return this.pathWithinApplication;
}
@Override
public RequestPath modifyContextPath(String contextPath) {
return new DefaultRequestPath(this, contextPath);
}
@Override
public boolean equals(@Nullable Object other) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.http.server.reactive;
package org.springframework.http.server;
import java.util.List;
@@ -25,8 +25,7 @@ import org.springframework.util.MultiValueMap;
* of {@link Separator Separator} and {@link PathSegment PathSegment} elements.
*
* <p>An instance of this class can be created via {@link #parsePath(String)} or
* {@link #parseUrlPath(String)}. For an HTTP request the path can be
* accessed via {@link ServerHttpRequest#getPath()}.
* {@link #parseUrlPath(String)}.
*
* <p>For a URL path each {@link UrlPathSegment UrlPathSegment} exposes its
* structure decoded safely without the risk of encoded reserved characters

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http.server.reactive;
package org.springframework.http.server;
import java.net.URI;
@@ -32,8 +32,10 @@ public interface RequestPath extends PathContainer {
* The context path is always at the beginning of the path and starts but
* does not end with "/". It is shared for URLs of the same application.
* <p>The context path may come from the underlying runtime API such as
* when deploying as a WAR to a Servlet container or it may also be assigned
* through the use of {@link ContextPathCompositeHandler} or both.
* when deploying as a WAR to a Servlet container or it may be assigned in
* a WebFlux application through the use of
* {@link org.springframework.http.server.reactive.ContextPathCompositeHandler
* ContextPathCompositeHandler}.
*/
PathContainer contextPath();
@@ -42,6 +44,14 @@ public interface RequestPath extends PathContainer {
*/
PathContainer pathWithinApplication();
/**
* Return a new {@code RequestPath} instance with a modified context path.
* The new context path must match the beginning of this request path.
* @param contextPath the new context path
* @return a new {@code RequestPath} instance
*/
RequestPath modifyContextPath(String contextPath);
/**
* Create a new {@code RequestPath} with the given parameters.

View File

@@ -23,6 +23,7 @@ import java.util.regex.Pattern;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.RequestPath;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;

View File

@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.RequestPath;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -110,7 +111,7 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
return null;
}
else if (uriToUse == null) {
return new DefaultRequestPath(this.delegate.getPath(), this.contextPath);
return this.delegate.getPath().modifyContextPath(this.contextPath);
}
else {
return RequestPath.parse(uriToUse, this.contextPath);

View File

@@ -22,6 +22,7 @@ import org.springframework.http.HttpCookie;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.http.server.RequestPath;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;

View File

@@ -25,6 +25,7 @@ import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.RequestPath;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;

View File

@@ -19,7 +19,7 @@ package org.springframework.web.cors.reactive;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.http.server.reactive.PathContainer;
import org.springframework.http.server.PathContainer;
import org.springframework.lang.Nullable;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.server.ServerWebExchange;

View File

@@ -18,8 +18,8 @@ package org.springframework.web.util.pattern;
import java.util.List;
import org.springframework.http.server.reactive.PathContainer.Element;
import org.springframework.http.server.reactive.PathContainer.UrlPathSegment;
import org.springframework.http.server.PathContainer.Element;
import org.springframework.http.server.PathContainer.UrlPathSegment;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.pattern.PathPattern.MatchingContext;

View File

@@ -19,7 +19,7 @@ package org.springframework.web.util.pattern;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.http.server.reactive.PathContainer.UrlPathSegment;
import org.springframework.http.server.PathContainer.UrlPathSegment;
import org.springframework.lang.Nullable;
/**

View File

@@ -16,9 +16,9 @@
package org.springframework.web.util.pattern;
import org.springframework.http.server.reactive.PathContainer;
import org.springframework.http.server.reactive.PathContainer.Element;
import org.springframework.http.server.reactive.PathContainer.PathSegment;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.PathContainer.Element;
import org.springframework.http.server.PathContainer.PathSegment;
import org.springframework.web.util.pattern.PathPattern.MatchingContext;
/**

View File

@@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
import org.springframework.http.server.reactive.PathContainer;
import org.springframework.http.server.PathContainer;
import org.springframework.lang.Nullable;
import org.springframework.util.PathMatcher;
import org.springframework.web.util.pattern.PathPattern.PathMatchResult;

View File

@@ -21,9 +21,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.http.server.reactive.PathContainer;
import org.springframework.http.server.reactive.PathContainer.Element;
import org.springframework.http.server.reactive.PathContainer.Separator;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.PathContainer.Element;
import org.springframework.http.server.PathContainer.Separator;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;

View File

@@ -21,7 +21,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.http.server.reactive.PathContainer.UrlPathSegment;
import org.springframework.http.server.PathContainer.UrlPathSegment;
import org.springframework.web.util.pattern.PathPattern.MatchingContext;
/**

View File

@@ -16,8 +16,8 @@
package org.springframework.web.util.pattern;
import org.springframework.http.server.reactive.PathContainer.Element;
import org.springframework.http.server.reactive.PathContainer.PathSegment;
import org.springframework.http.server.PathContainer.Element;
import org.springframework.http.server.PathContainer.PathSegment;
import org.springframework.web.util.pattern.PathPattern.MatchingContext;
/**

View File

@@ -16,8 +16,8 @@
package org.springframework.web.util.pattern;
import org.springframework.http.server.reactive.PathContainer;
import org.springframework.http.server.reactive.PathContainer.Element;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.PathContainer.Element;
import org.springframework.web.util.pattern.PathPattern.MatchingContext;
/**