All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.web.reactive.function.client.support.ClientResponseWrapper Maven / Gradle / Ivy

/*
 * Copyright 2002-2018 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.function.client.support;

import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeStrategies;

/**
 * Implementation of the {@link ClientResponse} interface that can be subclassed
 * to adapt the request in a
 * {@link org.springframework.web.reactive.function.client.ExchangeFilterFunction exchange filter function}.
 * All methods default to calling through to the wrapped request.
 *
 * @author Arjen Poutsma
 * @since 5.0.5
 */
public class ClientResponseWrapper implements ClientResponse {

	private final ClientResponse delegate;


	/**
	 * Create a new {@code ClientResponseWrapper} that wraps the given response.
	 * @param delegate the response to wrap
	 */
	public ClientResponseWrapper(ClientResponse delegate) {
		Assert.notNull(delegate, "Delegate is required");
		this.delegate = delegate;
	}


	/**
	 * Return the wrapped request.
	 */
	public ClientResponse response() {
		return this.delegate;
	}

	@Override
	public ExchangeStrategies strategies() {
		return this.delegate.strategies();
	}

	@Override
	public HttpStatus statusCode() {
		return this.delegate.statusCode();
	}

	@Override
	public Headers headers() {
		return this.delegate.headers();
	}

	@Override
	public MultiValueMap cookies() {
		return this.delegate.cookies();
	}

	@Override
	public  T body(BodyExtractor extractor) {
		return this.delegate.body(extractor);
	}

	@Override
	public  Mono bodyToMono(Class elementClass) {
		return this.delegate.bodyToMono(elementClass);
	}

	@Override
	public  Mono bodyToMono(ParameterizedTypeReference typeReference) {
		return this.delegate.bodyToMono(typeReference);
	}

	@Override
	public  Flux bodyToFlux(Class elementClass) {
		return this.delegate.bodyToFlux(elementClass);
	}

	@Override
	public  Flux bodyToFlux(ParameterizedTypeReference typeReference) {
		return this.delegate.bodyToFlux(typeReference);
	}

	@Override
	public  Mono> toEntity(Class bodyType) {
		return this.delegate.toEntity(bodyType);
	}

	@Override
	public  Mono> toEntity(ParameterizedTypeReference typeReference) {
		return this.delegate.toEntity(typeReference);
	}

	@Override
	public  Mono>> toEntityList(Class elementType) {
		return this.delegate.toEntityList(elementType);
	}

	@Override
	public  Mono>> toEntityList(ParameterizedTypeReference typeReference) {
		return this.delegate.toEntityList(typeReference);
	}

	/**
	 * Implementation of the {@code Headers} interface that can be subclassed
	  * to adapt the headers in a
	  * {@link org.springframework.web.reactive.function.client.ExchangeFilterFunction exchange filter function}.
	  * All methods default to calling through to the wrapped request.
	 */
	public static class HeadersWrapper implements ClientResponse.Headers {

		private final Headers headers;


		/**
		 * Create a new {@code HeadersWrapper} that wraps the given request.
		 * @param headers the headers to wrap
		 */
		public HeadersWrapper(Headers headers) {
			this.headers = headers;
		}


		@Override
		public OptionalLong contentLength() {
			return this.headers.contentLength();
		}

		@Override
		public Optional contentType() {
			return this.headers.contentType();
		}

		@Override
		public List header(String headerName) {
			return this.headers.header(headerName);
		}

		@Override
		public HttpHeaders asHttpHeaders() {
			return this.headers.asHttpHeaders();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy