Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAMEL-21884: camel-platform-http - Introduce useBodyHandler option #17528

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zhfeng
Copy link
Contributor

@zhfeng zhfeng commented Mar 21, 2025

Description

Target

  • I checked that the commit is targeting the correct branch (Camel 4 uses the main branch)

Tracking

  • If this is a large change, bug fix, or code improvement, I checked there is a JIRA issue filed for the change (usually before you start working on it).

Apache Camel coding standards and style

  • I checked that each commit in the pull request has a meaningful subject line and body.
  • I have run mvn clean install -DskipTests locally from root folder and I have committed all auto-generated changes.

Copy link
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟

🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run

  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot.

  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.

  • Build and test logs are available in the Summary page. Only Apache Camel committers have access to the summary.

  • ⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@zhfeng
Copy link
Contributor Author

zhfeng commented Mar 21, 2025

/component-test platform-http platform-http-vertx

Result ❌ The tests failed please check the logs

Copy link
Contributor

🤖 The Apache Camel test robot will run the tests for you 👍

@zhfeng
Copy link
Contributor Author

zhfeng commented Mar 21, 2025

component-test is suck ?

Copy link
Contributor

@jamesnetherton jamesnetherton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment as a potential improvement.

Also we need tests for this.

DefaultHttpRequestBodyHandler(Handler<RoutingContext> delegate) {
final boolean useBodyHandler;

DefaultHttpRequestBodyHandler(Handler<RoutingContext> delegate, boolean useBodyHandler) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick - I think it'd be better to have a dedicated class, like:

class NoOpHttpRequestBodyHandler extends HttpRequestBodyHandler {
    NoOpHttpRequestBodyHandler(Handler<RoutingContext> delegate) {
        super(delegate);
    }

    @Override
    void configureRoute(Route route) {
    }

    @Override
    Future<Void> handle(RoutingContext routingContext, Message message) {
        return Future.succeededFuture();
    }
}

That way you don't pollute DefaultHttpRequestBodyHandler with useBodyHandler checks. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks good to me. I will add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jamesnetherton ,

I create such a test

public class VertxPlatformHttpNoBodyHandlerTest {
    private final int port = AvailablePortFinder.getNextAvailable();
    private final WireMockServer wireMockServer = new WireMockServer(options().port(port));

    @BeforeEach
    void before() {
        wireMockServer.stubFor(post(urlPathEqualTo("/test"))
                .withRequestBody(containing("Hello World"))
                .willReturn(aResponse()
                        .withBody("This is a test")));

        wireMockServer.start();
    }

    @AfterEach
    void after() {
        if (wireMockServer != null) {
            wireMockServer.stop();
        }
    }

    @Test
    void testNoBodyHandler() throws Exception {
        final CamelContext context = VertxPlatformHttpEngineTest.createCamelContext();
        final var mockUrl = "http://localhost:" + wireMockServer.port();

        try {
            context.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                    from("platform-http:/camel?matchOnUriPrefix=true&useBodyHandler=false")
                            .process(exchange -> {
                                HttpMessage message = exchange.getMessage(HttpMessage.class);
                                message.setBody(message.getRequest());
                            })
                            .removeHeader("CamelHttpUri")
                            .setHeader("OrgCamelHttpUri", simple(mockUrl + "${header.CamelHttpPath}"))
                            .setHeader("CamelHttpPath", simple(""))
                            .toD("${bean:" + PathCreator.class.getName()
                                 + "?method=createNewUri(${header.OrgCamelHttpUri})}?bridgeEndpoint=true");
                }
            });

            context.start();

            given()
                    .body("Hello World")
                    .post("/camel/test")
                    .then()
                    .statusCode(200)
                    .body(is("This is a test"));
        } finally {
            context.stop();
        }
    }
}

But the test is hanging and can not get any response. When I remove the line message.setBody(message.getRequest());, it starts to work. I'm struggling for a while. Can you give me some lights?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to take a look later today.

Copy link
Contributor Author

@zhfeng zhfeng Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jamesnetherton - I just push my commits with the above test on zhfeng@e9bf41a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused as to what's making the request hang. It's maybe related to the setup and configuration of VertxPlatformHttpServer used in the tests.

If I run a similar test on Camel Quarkus, it seems to work. Likewise If I create just a plain Vert.x Server -> Client test (E.g no Camel), it also works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is WARN message in the log

[worker-thread-0] WARN  VertxImpl - You're already on a Vert.x context, are you sure you want to create a new Vertx instance?

any hint?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any hint?

It just means that the platform-http component and the vertx-http component created their own Vert.x instances. You can avoid the waning by binding a Vertx instance to the registry.

@oscerd
Copy link
Contributor

oscerd commented Mar 21, 2025

component-test is suck ?

It seems it cannot find camel-buildtools 4.11.0-SNAPSHOT, but it's there https://repository.apache.org/content/repositories/public/org/apache/camel/camel-buildtools/4.11.0-SNAPSHOT/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants