Introduce JettyClientHttpRequestFactory
This commit introduces an implementation of ClientHttpRequestFactory based on Jetty's HttpClient. Closes gh-30564
This commit is contained in:
@@ -111,20 +111,19 @@ abstract class AbstractHttpRequestFactoryTests extends AbstractMockWebServerTest
|
||||
ClientHttpRequest request = factory.createRequest(URI.create(baseUrl + "/echo"), HttpMethod.POST);
|
||||
|
||||
final byte[] body = "Hello World".getBytes(StandardCharsets.UTF_8);
|
||||
request.getHeaders().setContentLength(body.length);
|
||||
if (request instanceof StreamingHttpOutputMessage streamingRequest) {
|
||||
streamingRequest.setBody(outputStream -> {
|
||||
StreamUtils.copy(body, outputStream);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
});
|
||||
streamingRequest.setBody(outputStream -> StreamUtils.copy(body, outputStream));
|
||||
}
|
||||
else {
|
||||
StreamUtils.copy(body, request.getBody());
|
||||
}
|
||||
|
||||
request.execute();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
FileCopyUtils.copy(body, request.getBody()));
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
FileCopyUtils.copy(body, request.getBody()));
|
||||
assertThat(response.getStatusCode()).as("Invalid status code").isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.http.client;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class JettyClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
||||
|
||||
@Override
|
||||
protected ClientHttpRequestFactory createRequestFactory() {
|
||||
return new JettyClientHttpRequestFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void httpMethods() throws Exception {
|
||||
super.httpMethods();
|
||||
assertHttpMethod("patch", HttpMethod.PATCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,6 +48,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.http.client.JettyClientHttpRequestFactory;
|
||||
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.FormHttpMessageConverter;
|
||||
@@ -88,12 +89,12 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
|
||||
@interface ParameterizedRestTemplateTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
static Stream<Named<ClientHttpRequestFactory>> clientHttpRequestFactories() {
|
||||
return Stream.of(
|
||||
named("JDK", new SimpleClientHttpRequestFactory()),
|
||||
named("HttpComponents", new HttpComponentsClientHttpRequestFactory()),
|
||||
named("OkHttp", new OkHttp3ClientHttpRequestFactory())
|
||||
named("OkHttp", new OkHttp3ClientHttpRequestFactory()),
|
||||
named("Jetty", new JettyClientHttpRequestFactory())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user