Refine web.server package structure
Introduce adapter and handler sub-packages under web.server following a review prompted by the addition of the session package and the package cycle it brought in based on dependency on session.WebSessionManager.
This commit is contained in:
@@ -18,6 +18,9 @@ package org.springframework.web.server;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.web.server.adapter.WebToHttpHandlerAdapter;
|
||||
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
|
||||
|
||||
/**
|
||||
* Contract to handle a web server exchange.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.adapter;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -25,6 +25,8 @@ import reactor.core.publisher.Processors;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.WebSession;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.adapter;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -24,6 +24,9 @@ import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.handler.WebHandlerDecorator;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.session.DefaultWebSessionManager;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
@@ -13,14 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.adapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||
import org.springframework.web.server.handler.FilteringWebHandler;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
/**
|
||||
@@ -76,7 +82,7 @@ public class WebToHttpHandlerBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public WebToHttpHandlerAdapter build() {
|
||||
public HttpHandler build() {
|
||||
WebHandler handler = this.targetHandler;
|
||||
if (!this.exceptionHandlers.isEmpty()) {
|
||||
WebExceptionHandler[] array = new WebExceptionHandler[this.exceptionHandlers.size()];
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Implementation support to adapt
|
||||
* {@link org.springframework.web.server Spring web server} to the underlying
|
||||
* {@link org.springframework.http.server.reactive HTTP server} layer.
|
||||
*/
|
||||
package org.springframework.web.server.adapter;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -24,6 +24,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
|
||||
/**
|
||||
* {@code WebHandler} that decorates another with exception handling using one
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -21,6 +21,11 @@ import java.util.List;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
|
||||
/**
|
||||
* {@code WebHandler} that decorates another with a chain of {@link WebFilter}s.
|
||||
*
|
||||
@@ -13,11 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
|
||||
/**
|
||||
* Base class for a {@link WebHandler} that decorates and delegates to another.
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Provides WebHandler implementations.
|
||||
*/
|
||||
package org.springframework.web.server.handler;
|
||||
@@ -15,6 +15,6 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Web server infrastructure like filter, exchange (request + response), etc.
|
||||
* Foundational Spring web server support.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
* Support for a user session.
|
||||
* Web session support.
|
||||
*/
|
||||
package org.springframework.web.server.session;
|
||||
|
||||
@@ -49,9 +49,9 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.reactive.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.reactive.method.annotation.RequestMappingHandlerMapping;
|
||||
import org.springframework.web.reactive.method.annotation.ResponseBodyResultHandler;
|
||||
import org.springframework.web.server.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.ExceptionHandlingWebHandler;
|
||||
import org.springframework.web.server.FilteringWebHandler;
|
||||
import org.springframework.web.server.adapter.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||
import org.springframework.web.server.handler.FilteringWebHandler;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.MockServerHttpResponse;
|
||||
import org.springframework.web.ResponseStatusException;
|
||||
import org.springframework.web.server.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.adapter.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.web.reactive.DispatcherHandler;
|
||||
import org.springframework.web.reactive.ResponseStatusExceptionHandler;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.WebToHttpHandlerBuilder;
|
||||
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.reactive.HandlerResult;
|
||||
import org.springframework.web.reactive.method.annotation.RequestParamArgumentResolver;
|
||||
import org.springframework.web.server.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.adapter.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.server.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.adapter.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.DispatcherHandler;
|
||||
import org.springframework.web.reactive.handler.SimpleHandlerResultHandler;
|
||||
import org.springframework.web.server.WebToHttpHandlerBuilder;
|
||||
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
@@ -26,6 +26,11 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.MockServerHttpResponse;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.handler.ExceptionHandlingWebHandler;
|
||||
import org.springframework.web.server.adapter.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.server;
|
||||
package org.springframework.web.server.handler;
|
||||
|
||||
|
||||
import java.net.URI;
|
||||
@@ -30,10 +30,14 @@ import org.springframework.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.MockServerHttpResponse;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -104,7 +108,7 @@ public class FilteringWebHandlerTests {
|
||||
assertTrue(webHandler.invoked());
|
||||
}
|
||||
|
||||
private WebToHttpHandlerAdapter createHttpHandler(StubWebHandler webHandler, WebFilter... filters) {
|
||||
private HttpHandler createHttpHandler(StubWebHandler webHandler, WebFilter... filters) {
|
||||
return WebToHttpHandlerBuilder.webHandler(webHandler).filters(filters).build();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.MockServerHttpResponse;
|
||||
import org.springframework.web.server.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.adapter.DefaultWebServerExchange;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.WebSession;
|
||||
|
||||
@@ -37,7 +37,6 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -74,7 +73,7 @@ public class DefaultWebSessionManagerTests {
|
||||
|
||||
session.save();
|
||||
|
||||
assertFalse(this.idResolver.getId().isPresent());
|
||||
assertNull(this.idResolver.getId());
|
||||
assertNull(this.manager.getSessionStore().retrieveSession(session.getId()).get());
|
||||
}
|
||||
|
||||
@@ -86,8 +85,8 @@ public class DefaultWebSessionManagerTests {
|
||||
session.save();
|
||||
|
||||
String id = session.getId();
|
||||
assertTrue(this.idResolver.getId().isPresent());
|
||||
assertEquals(id, this.idResolver.getId().get());
|
||||
assertNotNull(this.idResolver.getId());
|
||||
assertEquals(id, this.idResolver.getId());
|
||||
assertSame(session, this.manager.getSessionStore().retrieveSession(id).get());
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ public class DefaultWebSessionManagerTests {
|
||||
session.getAttributes().put("foo", "bar");
|
||||
session.save();
|
||||
|
||||
assertTrue(this.idResolver.getId().isPresent());
|
||||
assertNotNull(this.idResolver.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,14 +128,14 @@ public class DefaultWebSessionManagerTests {
|
||||
|
||||
private Optional<String> idToResolve = Optional.empty();
|
||||
|
||||
private Optional<String> id = Optional.empty();
|
||||
private String id = null;
|
||||
|
||||
|
||||
public void setIdToResolve(Optional<String> idToResolve) {
|
||||
this.idToResolve = idToResolve;
|
||||
}
|
||||
|
||||
public Optional<String> getId() {
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@@ -146,7 +145,7 @@ public class DefaultWebSessionManagerTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSessionId(WebServerExchange exchange, Optional<String> sessionId) {
|
||||
public void setSessionId(WebServerExchange exchange, String sessionId) {
|
||||
this.id = sessionId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.WebServerExchange;
|
||||
import org.springframework.web.server.WebToHttpHandlerBuilder;
|
||||
import org.springframework.web.server.adapter.WebToHttpHandlerBuilder;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
Reference in New Issue
Block a user