Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-20555

camel-lra html response when creating a saga with invalid lra-url

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 4.4.0
    • 4.0.5, 4.4.2, 4.5.0
    • camel-lra
    • None
    • Unknown

    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

          Activity

            People

              Unassigned Unassigned
              sobhy Sobhy
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: