Comments (10)
The Spring RestClient
is nothing more then a wrapper, however internally it will use a Streaming Request and not a plain String
or other simple type.
Rewriting the code to use something streaming makes it fail with a plain HttpClient
as well.
var client = HttpClient.newHttpClient();
var body = new ObjectMapper().writeValueAsBytes(new SomeRequest(16));
var publisher = HttpRequest.BodyPublishers.ofByteArray(body, 0, body.length);
var request = HttpRequest.newBuilder().
.uri(URI.create(runtimeInfo.getHttpBaseUrl() + "/something"))
.header("Content-Type", "application/json")
.PUT(HttpRequest.BodyPublishers.fromPublisher(publisher))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Result: java.io.IOException: EOF reached while reading
I've attached the logging for the HttpClient
maybe that can shed some light. The output for both the RestClient
or plain HttpClient
is the same as well as the end result.
UPDATE: Fails with a simple byte[]
as well in the exact same manner.
from wiremock.
If I'm not mistaken there are no implementations of HTTP/2 without TLS. So my guess is that you set up a http stub that is served with HTTP/1.1. So it might be Java HttpClient's bug for not downgrading to HTTP/1.1 on non-TLS connection or not handling failed upgrade attempt properly. Or maybe underlying Jetty is not configured to use h2c for not-TLS HTTP/2 connections (probably need some configuration to enable it).
Actually, your code can be changed to use only one ClientHttpRequestFactory
:
return RestClient.builder()
.requestFactory(new JdkClientHttpRequestFactory(HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build()))
.baseUrl(properties.baseUrl())
.build();
and it works.
from wiremock.
The point is that Wiremock is that HTTP stub and forcing HTTP/1.1 should not be needed.
from wiremock.
Well, I can only add that I could not reproduce error by using plain Jdk HttpClient
like this:
var httpClient = HttpClient.newHttpClient();
HttpResponse<String> response = httpClient.send(HttpRequest.newBuilder()
.uri(new URI(runtimeInfo.getHttpBaseUrl() + "/something"))
.header("Content-Type", "application/json")
.PUT(HttpRequest.BodyPublishers.ofString("{ \"data\": \"test\" }"))
.build(),
HttpResponse.BodyHandlers.ofString()
);
Same using sendAsync()
. Maybe error has something to do with Spring RestClient usage of HttpClient.
from wiremock.
Related Issues (20)
- Extensions always supplies a null TemplateEngine to ExtensionFactory
- Detect overlapping mock json in wiremock HOT 2
- Extension configuration validation HOT 1
- gradle-wrapper.jar is inconsistent with current gradle version. HOT 2
- Make it possible to configure level for SubEvents, or to make it possible to disable them
- Composable startup configuration with extra bindings HOT 1
- Support custom startup parameters for extensions HOT 5
- Cannot send 'large' SOAP requests with http2 HOT 2
- Remove/disable stub when it was called one time HOT 1
- Fail to process request with sub boundaries HOT 1
- Is it feasible to set the level of SubEvents or to make them inactive? HOT 1
- JSON decoding error HOT 2
- Decimals matching issue in wiremock 3.4.0 HOT 1
- Wiremock standalone 3: NoSuchMethodError HOT 5
- Wiremock not detecting POST body request by Spring 6 RestClient HOT 1
- WireMockExtension.stopServerIfRunning() produces NPE when Unit Test aborts unexpectedly
- Add option to preserve User-Agent in the proxied request header
- Add project icon for IntelliJ
- EqualToXml does not detect difference on certain XML documents if Xalan is on classpath HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wiremock.