shashank created CAMEL-25658:
--------------------------------
Summary: camel-bonita - the startCase producer builds a new JAX-RS
client for every exchange, and the login filter one more for every request, and
none of them is closed
Key: CAMEL-25658
URL: https://issues.apache.org/jira/browse/CAMEL-25658
Project: Camel
Issue Type: Bug
Reporter: shashank
Assignee: shashank
Follow-up requested in the review of
[#27802|https://github.com/apache/camel/pull/27802] (CAMEL-25615, merged): the
reviewer found the follow-ups named in its description, "a client per exchange
that is never closed, a login before every request", worth a separate JIRA.
This ticket is about the clients only; the login before every request is not
changed.
Read on main 1de5ec5135f8:
* {{BonitaStartProducer.process}} (line 44) calls
{{BonitaAPIBuilder.build(bonitaAPIConfig)}} for every exchange, which builds a
new JAX-RS {{Client}} (lines 37-39 of {{BonitaAPIBuilder}}). Nothing keeps or
closes it.
* {{BonitaAuthFilter.filter}} logs in before every request (the client keeps no
cookies), each time with a new {{Client}} (lines 58-59) that is not closed
either.
So an exchange without a file input (process lookup and case creation, each
after a login) leaves three clients that are never closed. What a CXF client
holds until it is garbage collected was not measured.
h3. Proposed fix
* The producer creates one client when it starts, builds its {{BonitaAPI}} on
it with a new {{BonitaAPIBuilder.build(BonitaAPIConfig, Client)}}, uses it for
all its exchanges and closes it when it stops.
{{BonitaAPIBuilder.build(BonitaAPIConfig)}} keeps its behaviour for other
callers (a new client, not closed) and says so in its javadoc.
* {{BonitaAuthFilter}} closes the client of a login once it has read the
cookies of the answer.
The endpoint options (hostname, port, username, password) are then read when
the producer starts instead of for every exchange.
#27802 is merged now. With both changes the file upload also goes through the
client of the producer, so each endpoint still uploads to its own server.
h3. Test
New {{BonitaStartProducerClientTest}}: a route to a WireMock Bonita server, the
clients seen through a static mock of {{ClientBuilder.newBuilder()}} that
records what the real builder builds. Without the change both tests fail:
{{clients still open after three exchanges, of 9 created ==> expected: <1> but
was: <9>}} and {{clients still open after the route stopped, of 3 created ==>
expected: <0> but was: <3>}}. With the change: one client open while the route
runs, none after the route or the context stopped, one again after the route is
started again. camel-bonita: 20 tests, 0 failures.
The deprecated upload helper {{BonitaAPIUtil.getInstance}} is not used by Camel
since #27802 and is not counted by the test.
Affected: main, camel-4.23.x, camel-4.22.x and camel-4.18.x have the same lines
({{BonitaStartProducer}} 44, {{BonitaAuthFilter}} 59): read, not run.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)