Details
Description
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
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"); }); }
Attachments
Issue Links
- links to