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-21216: Apache Camel LRA does not work with Oracle MicroTX LRA coordinator #15558

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DFiedler
Copy link

Enable Oracle MicroTX lra-coordinator compatibility (https://issues.apache.org/jira/browse/CAMEL-21216).

  1. While joining an LRA Transaction, the payload sent by Apache Camel is URL encoded (fix in: LRAUrlBuilder.java)
  2. The Query parameter sent by Oracle LRA coordinator are url encoded, but will not be decoded by Apache Camal LRA (see also: CAMEL-21197) (workaround in: LRASagaRoutes.java)

The changes are backwards compatible to Narayana lra-coordinator.

Dirk Fiedler added 2 commits September 13, 2024 15:24
…ecoded. As long as 'CAMEL-21197' is not solved, this workaround is needed.
…se the generated url is part of the http put body.
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

zhfeng commented Sep 14, 2024

It seems that when seding the LRA Join request, there is a wrong context-text header, maybe it need to change to application/x-www-form-urlencoded since the payload is encodeded. See

HttpRequest request = prepareRequest(URI.create(lraEndpoint), exchange)
.setHeader(HEADER_LINK, link.toString())
.setHeader(Exchange.SAGA_LONG_RUNNING_ACTION, lra.toString())
.setHeader(CONTENT_TYPE, TEXT_PLAIN_CONTENT)
.PUT(HttpRequest.BodyPublishers.ofString(link.toString()))
.build();

Can you share the Oracle LRA coordinator configurations? and I could use to reproduce this issue locally.

@zhfeng
Copy link
Contributor

zhfeng commented Sep 14, 2024

Hmm, it looks like the payload is redundant since there is a link header. So can you try to use

.PUT(HttpRequest.BodyPublishers.ofString(""))

to see if it works with Oracle LRA coordinator?

@DFiedler
Copy link
Author

this is our current oracle lra-coordinator config ..
.. i will try your suggestion on Monday ;o)

have a nice weekend!
configmap-tcs-config.yaml.txt
statefulset-otmm-tcs.yaml.txt

@DFiedler
Copy link
Author

Hi,

when i am changing the the code to:

.PUT(HttpRequest.BodyPublishers.ofString(""))

then i am still getting this error message from LRA-Coordinator:

error while joining LRA: 400 / error: URL is double encoded

The same error (still) occurs, if i change the header:

.setHeader(CONTENT_TYPE, "application/x-www-form-urlencoded")

best regards
Dirk

@zhfeng
Copy link
Contributor

zhfeng commented Sep 18, 2024

@DFiedler sorry for the late reply since there are the public holidy on Mon and Tue in China.

Well, how can I run the Oracle LRA coordinator on my local machine? is there any docker image? It would be very helpful if you can share a simple reproducer. I'd like to take a deep look.

@DFiedler
Copy link
Author

@zhfeng we are using OpenShift as the preferred runtime, u can also use Docker: https://docs.oracle.com/en/database/oracle/transaction-manager-for-microservices/24.2/tmmdg/supported-operating-systems.html

because oracle also implements the Eclipse Microprofile LRA specification, it should work out of the box instead of Narayana (i guess u are using it for lra-coordinator) ...

In our case this is the lra-coordinator base path (oracle microtx url): http://otmm-tcs.qa-servicebuilder-dev.svc.cluster.local:9000
and this the lra-coordinator context path: api/v1/lra-coordinator

@zhfeng
Copy link
Contributor

zhfeng commented Sep 18, 2024

Thanks @DFiedler - I can start a oracle coordinator locally and reproduce the issue.

I'd like to discuss this issue with the Narayana team to see if there is any feedback. So let's hold the PR.

}
copy.query += key + "=" + value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
copy.query += key + "=" + value;
copy.query += toNonnullString(key) + "=" + toNonnullString(value);

Copy link
Contributor

Choose a reason for hiding this comment

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

@DFiedler please take a look this suggestion.

@@ -87,12 +88,18 @@ private void verifyRequest(Exchange exchange) {
if (!queryParams.isEmpty()) {
if (queryParams.get(URL_COMPENSATION_KEY) != null) {
compensationURI = queryParams.get(URL_COMPENSATION_KEY).toString();
// CAMEL-21216: the call from the lra-coordinator is not correctly url-decoded
// as long as 'CAMEL-21197' is not solved, this workaround is needed
compensationURI = java.net.URLDecoder.decode(compensationURI, StandardCharsets.UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

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

Map<String, Object> queryParam = URISupport.parseQuery(exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class));

I'd like to use a different way to parse the query string from HTTP since as @davsclaus mentions that URISupport.parseQuery is used for endpoints and have various optimized code. So it is NOT intend to as general purpose here.

@zhfeng
Copy link
Contributor

zhfeng commented Sep 19, 2024

Hi @DFiedler

After meeting the narayana team, it looks like

  • The communications between the LRA client and coordinator is not a part of the MP LRA specification
  • The Link header format is private used in Narayana LRA internally
  • Oracle MicroTx LRA seems following the similar way with Narayana but we can not expect it can be OOTB
  • The changes to NOT encoding the query paramters in Link is OK

@DFiedler
Copy link
Author

Hi @zhfeng
this means, within this pull request we can deliver the whole compatibility changes for Oracle MicroTX?
Sounds good .. thanks for your investigation!

@davsclaus
Copy link
Contributor

@zhfeng can you help get the last bits in place so this can be merged so it works with both oracle and narayana

@zhfeng
Copy link
Contributor

zhfeng commented Sep 20, 2024

@davsclaus sure, I can.

@DFiedler Do you mind I open a new PR to supersede this one?

@DFiedler
Copy link
Author

@zhfeng I want to ask, what is the next step here .. can i do anything to finalize this PR?

@zhfeng
Copy link
Contributor

zhfeng commented Sep 20, 2024

@DFiedler

  • Please take a look at my above suggestion on LRAUrlBuilder.java
  • Have a new method to replace URISupport.parseQuery to get the parmeters from HTTP and decode them
  • Maybe run ./mvnw -f components/camel-lra/pom.xml process-sources to format the files and make the CI happy.

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