Skip to content

Commit

Permalink
VertxHttpClientHTTPConduit redirects the request body twice when the …
Browse files Browse the repository at this point in the history
…body was passed through a single buffer, fix quarkiverse#1630
  • Loading branch information
ppalaga committed Dec 1, 2024
1 parent 0b09513 commit bf68f97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.quarkiverse.cxf.deployment.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Instance;
import jakarta.jws.WebMethod;
Expand Down Expand Up @@ -130,7 +133,28 @@ void init(@Observes Router router) {
});
router.post("/vertx-redirect").handler(ctx -> {
Log.info("Redirecting");
ctx.redirect("http://localhost:8081/services/hello");
ctx.redirect("http://localhost:8081/vertx-hello");
});
router.post("/vertx-hello").handler(ctx -> {
final String requestBody = ctx.body().asString();
final Matcher m = Pattern.compile("<arg0>([^<]*)</arg0>").matcher(requestBody);
final StringBuilder response = new StringBuilder()
.append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">")
.append("<soap:Body>")
.append("<ns2:helloResponse xmlns:ns2=\"http://test.deployment.cxf.quarkiverse.io/\">")
.append("<return>");
while (m.find()) {
/*
* Append as many hellos as many <arg0> elements we get to make sure
* we do not get the request body twice - see https://github.com/quarkiverse/quarkus-cxf/issues/1630
*/
response.append("Hello ").append(m.group(1));
}
response.append("</return>")
.append("</ns2:helloResponse>")
.append("</soap:Body>")
.append("</soap:Envelope>");
ctx.response().end(response.toString());
});
}

Expand Down Expand Up @@ -208,11 +232,11 @@ void endpointUri404OnEventLoop() throws InterruptedException {
@Test
void endpointUri302OnWorkerThread() {
RestAssured.given()
.body("Joe")
.body("Single request body")
.post("http://localhost:8081/vertx-blocking/endpointUri302")
.then()
.statusCode(200)
.body(Matchers.is("Hello Joe"));
.body(Matchers.is("Hello Single request body"));
}

private static Throwable rootCause(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,6 @@ void finishRequest(HttpClientRequest req, Buffer buffer) {
}
mode.responseReady(new Result<>(new ResponseEvent(response, sink), ar.cause()));
});
if (bodyRecorder != null) {
bodyRecorder.add(buffer.slice());
}

req
.end(buffer)
.onFailure(t -> mode.responseFailed(t, true));
Expand All @@ -686,7 +682,9 @@ void finishRequest(HttpClientRequest req, Buffer buffer) {

void redirectRetransmit(URI newURL) throws IOException {
if (Log.isDebugEnabled()) {
Log.debugf("Redirect retransmit from %s to %s", redirects.get(redirects.size() - 1), newURL);
final int i = redirects.size() - 2;
final String previousUrl = i >= 0 ? redirects.get(i).toString() : "null";
Log.infof("Redirect retransmit from %s to %s", previousUrl, newURL);
}
boolean ssl;
int port = newURL.getPort();
Expand Down

0 comments on commit bf68f97

Please sign in to comment.