diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java index 05b082a0f2d..60dcb5d0d8c 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java @@ -39,7 +39,7 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest { public ServerHttpRequestDecorator(ServerHttpRequest delegate) { - Assert.notNull(delegate, "'delegate' is required."); + Assert.notNull(delegate, "ServerHttpRequest delegate is required."); this.delegate = delegate; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java new file mode 100644 index 00000000000..7e4b785db61 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java @@ -0,0 +1,112 @@ +/* + * Copyright 2002-2016 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.http.server.reactive; + +import java.util.function.Function; +import java.util.function.Supplier; + +import org.reactivestreams.Publisher; +import reactor.core.publisher.Mono; + +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseCookie; +import org.springframework.util.Assert; +import org.springframework.util.MultiValueMap; + +/** + * Wraps another {@link ServerHttpResponse} and delegates all methods to it. + * Sub-classes can override specific methods selectively. + * + * @author Rossen Stoyanchev + * @since 5.0 + */ +public class ServerHttpResponseDecorator implements ServerHttpResponse { + + private final ServerHttpResponse delegate; + + + public ServerHttpResponseDecorator(ServerHttpResponse delegate) { + Assert.notNull(delegate, "ServerHttpResponse delegate is required."); + this.delegate = delegate; + } + + + public ServerHttpResponse getDelegate() { + return this.delegate; + } + + + // ServerHttpResponse delegation methods... + + @Override + public boolean setStatusCode(HttpStatus status) { + return getDelegate().setStatusCode(status); + } + + @Override + public HttpStatus getStatusCode() { + return getDelegate().getStatusCode(); + } + + @Override + public HttpHeaders getHeaders() { + return getDelegate().getHeaders(); + } + + @Override + public MultiValueMap getCookies() { + return getDelegate().getCookies(); + } + + @Override + public String encodeUrl(String url) { + return getDelegate().encodeUrl(url); + } + + @Override + public void registerUrlEncoder(Function encoder) { + getDelegate().registerUrlEncoder(encoder); + } + + @Override + public DataBufferFactory bufferFactory() { + return getDelegate().bufferFactory(); + } + + @Override + public void beforeCommit(Supplier> action) { + getDelegate().beforeCommit(action); + } + + @Override + public Mono writeWith(Publisher body) { + return getDelegate().writeWith(body); + } + + @Override + public Mono writeAndFlushWith(Publisher> body) { + return getDelegate().writeAndFlushWith(body); + } + + @Override + public Mono setComplete() { + return getDelegate().setComplete(); + } + +}