Sobhy created CAMEL-20555:
-----------------------------
Summary: camel-lra html response when creating a saga with invalid
lra-url
Key: CAMEL-20555
URL: https://issues.apache.org/jira/browse/CAMEL-20555
Project: Camel
Issue Type: Bug
Components: camel-lra
Affects Versions: 4.4.0
Reporter: Sobhy
when creating saga with invalid lra-url then html response returned causing
{{java.net.MalformedURLException}} exception.
Proposal Fix
In LRAClient -> newLRA can be modified like the following
{code:java}
public CompletableFuture<URL> newLRA(Exchange exchange) {
HttpRequest request = prepareRequest(URI.create(lraUrl +
COORDINATOR_PATH_START), exchange)
.POST(HttpRequest.BodyPublishers.ofString(""))
.build(); CompletableFuture<HttpResponse<String>> future
= client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
return future.thenApply(res -> {
// TODO: check the status code
// TODO: FAIL if status is >= 400: with original URL + body
// See if there's a location header containing the LRA URL
List<String> location = res.headers().map().get("Location");
if (ObjectHelper.isNotEmpty(location)) {
return toURL(location.get(0));
} // If there's no location header try the
Long-Running-Action header, assuming there's only one present in the response
List<String> lraHeaders =
res.headers().map().get(Exchange.SAGA_LONG_RUNNING_ACTION);
if (ObjectHelper.isNotEmpty(lraHeaders) && lraHeaders.size() == 1) {
return toURL(lraHeaders.get(0));
} // Fallback to reading the URL from the response body
String responseBody = res.body();
if (ObjectHelper.isNotEmpty(responseBody)) {
return toURL(responseBody); // <----- Invalid body causes
java.net.MalformedURLException: no protocol: <html>
} throw new IllegalStateException("Cannot obtain LRA id
from LRA coordinator");
});
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)