Moved fromServerRequest to ServerRequest itself

This commit moves WebFluxUriComponentsBuilder.fromServerRequest to the
ServerRequest interface itself.

Consequently, the WebFluxUriComponentsBuilder is removes itself, as it
contained no other methods.

Issue: SPR-15953
This commit is contained in:
Arjen Poutsma
2017-09-25 11:29:07 +02:00
parent 0d8031d9b4
commit 1a3cc3df94
9 changed files with 119 additions and 119 deletions

View File

@@ -87,6 +87,21 @@ public class DefaultServerRequestTests {
assertEquals(uri, request.uri());
}
@Test
public void uriBuilder() throws Exception {
URI uri = new URI("http", "localhost", "/path", "a=1", null);
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, uri).build();
DefaultServerRequest request = new DefaultServerRequest(mockRequest.toExchange(), messageReaders);
URI result = request.uriBuilder().build();
assertEquals("http", result.getScheme());
assertEquals("localhost", result.getHost());
assertEquals(-1, result.getPort());
assertEquals("/path", result.getPath());
assertEquals("a=1", result.getQuery());
}
@Test
public void attribute() throws Exception {
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "http://example.com").build();

View File

@@ -38,6 +38,7 @@ import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRange;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.http.server.PathContainer;
import org.springframework.http.server.RequestPath;
@@ -49,6 +50,8 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.server.WebSession;
import org.springframework.web.util.UriBuilder;
import org.springframework.web.util.UriComponentsBuilder;
/**
* Mock implementation of {@link ServerRequest}.
@@ -118,6 +121,11 @@ public class MockServerRequest implements ServerRequest {
return this.uri;
}
@Override
public UriBuilder uriBuilder() {
return UriComponentsBuilder.fromHttpRequest(new ServerRequestAdapter());
}
@Override
public PathContainer pathContainer() {
return this.pathContainer;
@@ -466,4 +474,23 @@ public class MockServerRequest implements ServerRequest {
}
private final class ServerRequestAdapter implements HttpRequest {
@Override
public String getMethodValue() {
return methodName();
}
@Override
public URI getURI() {
return MockServerRequest.this.uri;
}
@Override
public HttpHeaders getHeaders() {
return MockServerRequest.this.headers.headers;
}
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.support;
import java.net.URI;
import org.junit.Test;
import org.springframework.web.reactive.function.server.MockServerRequest;
import org.springframework.web.util.UriComponents;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
*/
public class WebFluxUriComponentsBuilderTests {
@Test
public void fromServerRequest() throws Exception {
URI uri = new URI("http", "localhost", "/path", "a=1", null);
MockServerRequest request = MockServerRequest.builder().uri(uri).build();
UriComponents result = WebFluxUriComponentsBuilder.fromServerRequest(request).build();
assertEquals("http", result.getScheme());
assertEquals("localhost", result.getHost());
assertEquals(-1, result.getPort());
assertEquals("/path", result.getPath());
assertEquals("a=1", result.getQuery());
}
}