This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.0.x by this push:
new 0f5e66c0e9c CAMEL-20555: adding check for status code when creating a
new saga (#13515)
0f5e66c0e9c is described below
commit 0f5e66c0e9c825f2636fa910ff35b4c667a9141e
Author: Johannes Boßle <[email protected]>
AuthorDate: Mon Mar 18 11:24:35 2024 +0100
CAMEL-20555: adding check for status code when creating a new saga (#13515)
* adding check of status code
* adding check of status code
---------
Co-authored-by: Johannes Boßle <[email protected]>
---
.../src/main/java/org/apache/camel/service/lra/LRAClient.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
index 77833c16264..80fc621f972 100644
---
a/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
+++
b/components/camel-lra/src/main/java/org/apache/camel/service/lra/LRAClient.java
@@ -31,6 +31,8 @@ import java.util.function.Function;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static
org.apache.camel.service.lra.LRAConstants.COORDINATOR_PATH_CANCEL;
import static org.apache.camel.service.lra.LRAConstants.COORDINATOR_PATH_CLOSE;
@@ -46,6 +48,8 @@ public class LRAClient implements Closeable {
private final HttpClient client;
private final String lraUrl;
+ private static final Logger LOG = LoggerFactory.getLogger(LRAClient.class);
+
public LRAClient(LRASagaService sagaService) {
this(sagaService, HttpClient.newHttpClient());
}
@@ -72,6 +76,12 @@ public class LRAClient implements Closeable {
CompletableFuture<HttpResponse<String>> future =
client.sendAsync(request, HttpResponse.BodyHandlers.ofString());
return future.thenApply(res -> {
+ if (res.statusCode() >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ LOG.debug("LRA coordinator responded with error code {}.
Message: {}", res.statusCode(), res.body());
+ throw new IllegalStateException(
+ "Cannot obtain LRA id from LRA coordinator due to
response status code " + res.statusCode());
+ }
+
// See if there's a location header containing the LRA URL
List<String> location = res.headers().map().get("Location");
if (ObjectHelper.isNotEmpty(location)) {