001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.server.handler; 018 019import reactor.core.publisher.Mono; 020 021import org.springframework.util.Assert; 022import org.springframework.web.server.ServerWebExchange; 023import org.springframework.web.server.WebHandler; 024 025/** 026 * {@link WebHandler} that decorates and delegates to another {@code WebHandler}. 027 * 028 * @author Rossen Stoyanchev 029 * @since 5.0 030 */ 031public class WebHandlerDecorator implements WebHandler { 032 033 private final WebHandler delegate; 034 035 036 /** 037 * Create a {@code WebHandlerDecorator} for the given delegate. 038 * @param delegate the WebHandler delegate 039 */ 040 public WebHandlerDecorator(WebHandler delegate) { 041 Assert.notNull(delegate, "'delegate' must not be null"); 042 this.delegate = delegate; 043 } 044 045 046 /** 047 * Return the wrapped delegate. 048 */ 049 public WebHandler getDelegate() { 050 return this.delegate; 051 } 052 053 054 @Override 055 public Mono<Void> handle(ServerWebExchange exchange) { 056 return this.delegate.handle(exchange); 057 } 058 059 @Override 060 public String toString() { 061 return getClass().getSimpleName() + " [delegate=" + this.delegate + "]"; 062 } 063 064}