org.springframework.web.service.invoker.HttpClientAdapter Maven / Gradle / Ivy
/*
* Copyright 2002-2023 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
*
* https://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.service.invoker;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
/**
* Contract to abstract the underlying HTTP client and decouple it from the
* {@linkplain HttpServiceProxyFactory#createClient(Class) HTTP service proxy}.
*
* @author Rossen Stoyanchev
* @author Olga Maciaszek-Sharma
* @since 6.0
* @deprecated in favor of {@link ReactorHttpExchangeAdapter}
*/
@Deprecated(since = "6.1", forRemoval = true)
public interface HttpClientAdapter {
/**
* Perform the given request, and release the response content, if any.
* @param requestValues the request to perform
* @return {@code Mono} that completes when the request is fully executed
* and the response content is released.
*/
Mono requestToVoid(HttpRequestValues requestValues);
/**
* Perform the given request, release the response content, and return the
* response headers.
* @param requestValues the request to perform
* @return {@code Mono} that returns the response headers the request is
* fully executed and the response content released.
*/
Mono requestToHeaders(HttpRequestValues requestValues);
/**
* Perform the given request and decode the response content to the given type.
* @param requestValues the request to perform
* @param bodyType the target type to decode to
* @return {@code Mono} that returns the decoded response.
* @param the type the response is decoded to
*/
Mono requestToBody(HttpRequestValues requestValues, ParameterizedTypeReference bodyType);
/**
* Perform the given request and decode the response content to a stream with
* elements of the given type.
* @param requestValues the request to perform
* @param bodyType the target stream element type to decode to
* @return {@code Flux} with decoded stream elements.
* @param the type the response is decoded to
*/
Flux requestToBodyFlux(HttpRequestValues requestValues, ParameterizedTypeReference bodyType);
/**
* Variant of {@link #requestToVoid(HttpRequestValues)} with additional
* access to the response status and headers.
*/
Mono> requestToBodilessEntity(HttpRequestValues requestValues);
/**
* Variant of {@link #requestToBody(HttpRequestValues, ParameterizedTypeReference)}
* with additional access to the response status and headers.
*/
Mono> requestToEntity(HttpRequestValues requestValues, ParameterizedTypeReference bodyType);
/**
* Variant of {@link #requestToBodyFlux(HttpRequestValues, ParameterizedTypeReference)}
* with additional access to the response status and headers.
*/
Mono>> requestToEntityFlux(HttpRequestValues requestValues, ParameterizedTypeReference bodyType);
/**
* Adapt this instance to {@link ReactorHttpExchangeAdapter}.
* @since 6.1
*/
default ReactorHttpExchangeAdapter asReactorExchangeAdapter() {
return new AbstractReactorHttpExchangeAdapter() {
@Override
public boolean supportsRequestAttributes() {
return true;
}
@Override
public Mono exchangeForMono(HttpRequestValues values) {
return HttpClientAdapter.this.requestToVoid(values);
}
@Override
public Mono exchangeForHeadersMono(HttpRequestValues values) {
return HttpClientAdapter.this.requestToHeaders(values);
}
@Override
public Mono exchangeForBodyMono(HttpRequestValues values, ParameterizedTypeReference bodyType) {
return HttpClientAdapter.this.requestToBody(values, bodyType);
}
@Override
public Flux exchangeForBodyFlux(HttpRequestValues values, ParameterizedTypeReference bodyType) {
return HttpClientAdapter.this.requestToBodyFlux(values, bodyType);
}
@Override
public Mono> exchangeForBodilessEntityMono(HttpRequestValues values) {
return HttpClientAdapter.this.requestToBodilessEntity(values);
}
@Override
public Mono> exchangeForEntityMono(
HttpRequestValues requestValues, ParameterizedTypeReference bodyType) {
return HttpClientAdapter.this.requestToEntity(requestValues, bodyType);
}
@Override
public Mono>> exchangeForEntityFlux(
HttpRequestValues requestValues, ParameterizedTypeReference bodyType) {
return HttpClientAdapter.this.requestToEntityFlux(requestValues, bodyType);
}
};
}
}