Closed emakunin closed 2 months ago
The issue seems to be related to this and this part of ClientWriterInterceptorContextImpl used in the client. Temporary buffer replaces a link to the output stream. However other interceptors can call setOutputStream
as well to capture the output. They'll do some actions (e.g sigh it) and then reset the output stream from theirs own buffer.
Consider interception like this:
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
OutputStream originalStream = context.getOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
context.setOutputStream(baos);
try {
//wait the serialization of the body
context.proceed();
} finally {
// when body is serialized get it
byte[] body = baos.toByteArray();
// do something with the body content here (E.g add signature, hash-sum, etc)
// write request to originalStream
baos.writeTo(originalStream);
baos.close();
context.setOutputStream(originalStream);
}
ClientWriterInterceptorContextImpl::baos
will always be empty or what can be even warse can contain "half baked" data. Since inside the interceptor the reference can be changed.
The code is there for 4 years so not sure whether it's desired/documented. IMHO it's better to fix. For the time being I'll try to modify my interceptors. However the right fix should be in the context (we should not be able to set streams) or in the writer (it should always read output stream)
UPD:
If someone struggles with similar issue. The fix is easy. Just use below in your interceptor.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TeeOutputStream teeStream = new TeeOutputStream(context.getOutputStream(), baos);
context.setOutputStream(teeStream);
Probably the same can be applied to the ClientWriterInterceptorContextImpl. However there will be a qustion suring setOutputStream
as well it's easy to get a recursion there if we just wrap the stream. Not ready to provide an elegant solution straight away.
Hi folks,
I'm trying to migrate to Quarkus v3.13.2 (tried also v3.11 with the same effect) and as per documentation I'm migrating my resteasy clients to
quarkus-rest-client
However it does not pass POST payload. Current quarkus LTS (3.8.1) worked fine with resteasy client.
The problem is that post body value is always null. I checked in debugger and in rest logs. They contain server response with an error. due to missing fields that I do pass as I can see in the debugger. The object serializatioin seems to be just ignoring the input class object (see below)
My setup
Quarkus 3.13.2
I have below dependencies in runtime package (plus correspoinding ones with *-deployment suffix in deployment lib)
Also I added a build step to add my client to the index as otherwise quarkus cannot start saying `REST client interface: interface ....FbaInboundV2024Api was not indexed at build time
Probably worths a separate issue, but in case it matters: I noticed that if I add beans.xml file to my estension then I get producers conflict even though I provide 2 Named ones, quarkus ApplicationImpl tries to init every single rest client (I have many for each api segment) with @Default qualifier and complains that there are 2 named beans. Probably it's an incorrect initialization.