Polish RestClient, etc.
This commit is contained in:
parent
a6c5692586
commit
368a917466
|
|
@ -149,7 +149,7 @@ final class DefaultRestClient implements RestClient {
|
|||
|
||||
@Override
|
||||
public RequestBodyUriSpec method(HttpMethod method) {
|
||||
Assert.notNull(method, "Method must not be null");
|
||||
Assert.notNull(method, "HttpMethod must not be null");
|
||||
return methodInternal(method);
|
||||
}
|
||||
|
||||
|
|
@ -450,7 +450,6 @@ final class DefaultRestClient implements RestClient {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
private interface InternalBody {
|
||||
|
||||
|
|
@ -487,7 +486,7 @@ final class DefaultRestClient implements RestClient {
|
|||
|
||||
@Override
|
||||
public ResponseSpec onStatus(ResponseErrorHandler errorHandler) {
|
||||
Assert.notNull(errorHandler, "ErrorHandler must not be null");
|
||||
Assert.notNull(errorHandler, "ResponseErrorHandler must not be null");
|
||||
|
||||
return onStatusInternal(StatusHandler.fromErrorHandler(errorHandler));
|
||||
}
|
||||
|
|
@ -613,6 +612,6 @@ final class DefaultRestClient implements RestClient {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,11 +61,12 @@ import org.springframework.web.util.UriBuilderFactory;
|
|||
* <li>{@link RequestHeadersSpec#retrieve() retrieve()}
|
||||
* <li>{@link RequestHeadersSpec#exchange(RequestHeadersSpec.ExchangeFunction) exchange(Function<ClientHttpRequest, T>)}
|
||||
* </ul>
|
||||
*
|
||||
* <p>For examples with a request body see:
|
||||
* <ul>
|
||||
* <li>{@link RequestBodySpec#body(Object) body(Object)}
|
||||
* <li>{@link RequestBodySpec#body(Object, ParameterizedTypeReference) body(Object, ParameterizedTypeReference)}
|
||||
* <li>{@link RequestBodySpec#body(StreamingHttpOutputMessage.Body) body(Consumer<OutputStream>}
|
||||
* <li>{@link RequestBodySpec#body(StreamingHttpOutputMessage.Body) body(Consumer<OutputStream>)}
|
||||
* </ul>
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -218,7 +219,8 @@ public interface RestClient {
|
|||
* for a given URL is absolute in which case the base URL is ignored.
|
||||
* <p><strong>Note:</strong> this method is mutually exclusive with
|
||||
* {@link #uriBuilderFactory(UriBuilderFactory)}. If both are used, the
|
||||
* baseUrl value provided here will be ignored.
|
||||
* {@code baseUrl} value provided here will be ignored.
|
||||
* @return this builder
|
||||
* @see DefaultUriBuilderFactory#DefaultUriBuilderFactory(String)
|
||||
* @see #uriBuilderFactory(UriBuilderFactory)
|
||||
*/
|
||||
|
|
@ -236,7 +238,8 @@ public interface RestClient {
|
|||
* </pre>
|
||||
* <p><strong>Note:</strong> this method is mutually exclusive with
|
||||
* {@link #uriBuilderFactory(UriBuilderFactory)}. If both are used, the
|
||||
* defaultUriVariables value provided here will be ignored.
|
||||
* {@code defaultUriVariables} value provided here will be ignored.
|
||||
* @return this builder
|
||||
* @see DefaultUriBuilderFactory#setDefaultUriVariables(Map)
|
||||
* @see #uriBuilderFactory(UriBuilderFactory)
|
||||
*/
|
||||
|
|
@ -251,6 +254,7 @@ public interface RestClient {
|
|||
* <li>{@link #defaultUriVariables(Map)}.
|
||||
* </ul>
|
||||
* @param uriBuilderFactory the URI builder factory to use
|
||||
* @return this builder
|
||||
* @see #baseUrl(String)
|
||||
* @see #defaultUriVariables(Map)
|
||||
*/
|
||||
|
|
@ -261,19 +265,22 @@ public interface RestClient {
|
|||
* if the request does not already contain such a header.
|
||||
* @param header the header name
|
||||
* @param values the header values
|
||||
* @return this builder
|
||||
*/
|
||||
Builder defaultHeader(String header, String... values);
|
||||
|
||||
/**
|
||||
* Provides access to every {@link #defaultHeader(String, String...)}
|
||||
* declared so far with the possibility to add, replace, or remove.
|
||||
* Provide a consumer to access to every {@linkplain #defaultHeader(String, String...)
|
||||
* default header} declared so far, with the possibility to add, replace, or remove.
|
||||
* @param headersConsumer the consumer
|
||||
* @return this builder
|
||||
*/
|
||||
Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer);
|
||||
|
||||
/**
|
||||
* Provide a consumer to customize every request being built.
|
||||
* @param defaultRequest the consumer to use for modifying requests
|
||||
* @return this builder
|
||||
*/
|
||||
Builder defaultRequest(Consumer<RequestHeadersSpec<?>> defaultRequest);
|
||||
|
||||
|
|
@ -306,6 +313,7 @@ public interface RestClient {
|
|||
/**
|
||||
* Add the given request interceptor to the end of the interceptor chain.
|
||||
* @param interceptor the interceptor to be added to the chain
|
||||
* @return this builder
|
||||
*/
|
||||
Builder requestInterceptor(ClientHttpRequestInterceptor interceptor);
|
||||
|
||||
|
|
@ -321,6 +329,7 @@ public interface RestClient {
|
|||
/**
|
||||
* Add the given request initializer to the end of the initializer chain.
|
||||
* @param initializer the initializer to be added to the chain
|
||||
* @return this builder
|
||||
*/
|
||||
Builder requestInitializer(ClientHttpRequestInitializer initializer);
|
||||
|
||||
|
|
@ -338,12 +347,14 @@ public interface RestClient {
|
|||
* for plugging in and/or customizing options of the underlying HTTP
|
||||
* client library (e.g. SSL).
|
||||
* @param requestFactory the request factory to use
|
||||
* @return this builder
|
||||
*/
|
||||
Builder requestFactory(ClientHttpRequestFactory requestFactory);
|
||||
|
||||
/**
|
||||
* Configure the message converters for the {@code RestClient} to use.
|
||||
* @param configurer the configurer to apply
|
||||
* @return this builder
|
||||
*/
|
||||
Builder messageConverters(Consumer<List<HttpMessageConverter<?>>> configurer);
|
||||
|
||||
|
|
@ -351,6 +362,7 @@ public interface RestClient {
|
|||
* Apply the given {@code Consumer} to this builder instance.
|
||||
* <p>This can be useful for applying pre-packaged customizations.
|
||||
* @param builderConsumer the consumer to apply
|
||||
* @return this builder
|
||||
*/
|
||||
Builder apply(Consumer<Builder> builderConsumer);
|
||||
|
||||
|
|
@ -379,14 +391,14 @@ public interface RestClient {
|
|||
|
||||
/**
|
||||
* Specify the URI for the request using a URI template and URI variables.
|
||||
* If a {@link UriBuilderFactory} was configured for the client (e.g.
|
||||
* <p>If a {@link UriBuilderFactory} was configured for the client (e.g.
|
||||
* with a base URI) it will be used to expand the URI template.
|
||||
*/
|
||||
S uri(String uri, Object... uriVariables);
|
||||
|
||||
/**
|
||||
* Specify the URI for the request using a URI template and URI variables.
|
||||
* If a {@link UriBuilderFactory} was configured for the client (e.g.
|
||||
* <p>If a {@link UriBuilderFactory} was configured for the client (e.g.
|
||||
* with a base URI) it will be used to expand the URI template.
|
||||
*/
|
||||
S uri(String uri, Map<String, ?> uriVariables);
|
||||
|
|
@ -478,11 +490,11 @@ public interface RestClient {
|
|||
/**
|
||||
* Callback for access to the {@link ClientHttpRequest} that in turn
|
||||
* provides access to the native request of the underlying HTTP library.
|
||||
* This could be useful for setting advanced, per-request options that
|
||||
* exposed by the underlying library.
|
||||
* <p>This could be useful for setting advanced, per-request options that
|
||||
* are exposed by the underlying library.
|
||||
* @param requestConsumer a consumer to access the
|
||||
* {@code ClientHttpRequest} with
|
||||
* @return {@code ResponseSpec} to specify how to decode the body
|
||||
* @return this builder
|
||||
*/
|
||||
S httpRequest(Consumer<ClientHttpRequest> requestConsumer);
|
||||
|
||||
|
|
@ -508,6 +520,7 @@ public interface RestClient {
|
|||
* {@link HttpClientErrorException} and 5xx response codes in a
|
||||
* {@link HttpServerErrorException}. To customize error handling, use
|
||||
* {@link ResponseSpec#onStatus(Predicate, ResponseSpec.ErrorHandler) onStatus} handlers.
|
||||
* @return {@code ResponseSpec} to specify how to decode the body
|
||||
*/
|
||||
ResponseSpec retrieve();
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ final class StatusHandler {
|
|||
}
|
||||
|
||||
public static StatusHandler fromErrorHandler(ResponseErrorHandler errorHandler) {
|
||||
Assert.notNull(errorHandler, "ErrorHandler must not be null");
|
||||
Assert.notNull(errorHandler, "ResponseErrorHandler must not be null");
|
||||
|
||||
return new StatusHandler(errorHandler::hasError, (request, response) ->
|
||||
errorHandler.handleError(request.getURI(), request.getMethod(), response));
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class RestClientIntegrationTests {
|
|||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("clientHttpRequestFactories")
|
||||
@interface ParameterizedWebClientTest {
|
||||
@interface ParameterizedRestClientTest {
|
||||
}
|
||||
|
||||
static Stream<Named<ClientHttpRequestFactory>> clientHttpRequestFactories() {
|
||||
|
|
@ -104,7 +104,7 @@ class RestClientIntegrationTests {
|
|||
}
|
||||
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJson(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonWithParameterizedTypeReference(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonAsResponseEntity(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -200,7 +200,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonAsBodilessEntity(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonArray(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonArrayAsResponseEntityList(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonAsSerializedText(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -302,8 +302,8 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@SuppressWarnings("rawtypes")
|
||||
@ParameterizedRestClientTest
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
void retrieveJsonNull(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -320,7 +320,7 @@ class RestClientIntegrationTests {
|
|||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve404(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ class RestClientIntegrationTests {
|
|||
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve404WithBody(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve500(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -383,7 +383,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo(path));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve500AsEntity(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -404,7 +404,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve500AsBodilessEntity(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -425,7 +425,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void retrieve555UnknownStatus(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/unknownPage"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void postPojoAsJson(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -477,13 +477,12 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> {
|
||||
assertThat(request.getPath()).isEqualTo("/pojo/capitalize");
|
||||
assertThat(request.getBody().readUtf8()).isEqualTo("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}");
|
||||
// assertThat(request.getHeader(HttpHeaders.CONTENT_LENGTH)).isEqualTo("31");
|
||||
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
|
||||
assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("application/json");
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void statusHandler(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -504,7 +503,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void statusHandlerParameterizedTypeReference(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -526,7 +525,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void statusHandlerSuppressedErrorSignal(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -545,7 +544,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void statusHandlerSuppressedErrorSignalWithEntity(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -570,7 +569,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void exchangeForPlainText(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -590,7 +589,7 @@ class RestClientIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void exchangeFor404(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -607,7 +606,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getPath()).isEqualTo("/greeting"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void requestInitializer(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -629,7 +628,7 @@ class RestClientIntegrationTests {
|
|||
expectRequest(request -> assertThat(request.getHeader("foo")).isEqualTo("bar"));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void requestInterceptor(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -656,7 +655,7 @@ class RestClientIntegrationTests {
|
|||
}
|
||||
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void filterForErrorHandling(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
@ -700,7 +699,7 @@ class RestClientIntegrationTests {
|
|||
}
|
||||
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
@ParameterizedRestClientTest
|
||||
void invalidDomain(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue