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-17751: Extracting Camel-Saga-Compensate & Camel-Saga-Complete f… #7118

Merged
merged 2 commits into from Mar 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,11 +16,15 @@
*/
package org.apache.camel.service.lra;

import java.net.URISyntaxException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.util.URISupport;

import static org.apache.camel.service.lra.LRAConstants.PARTICIPANT_PATH_COMPENSATE;
import static org.apache.camel.service.lra.LRAConstants.PARTICIPANT_PATH_COMPLETE;
Expand Down Expand Up @@ -59,7 +63,8 @@ public void configure() throws Exception {
}

/**
* Check if the request is pointing to an allowed URI to prevent unauthorized remote uri invocation
* Check if the request is pointing to an allowed URI to prevent unauthorized
* remote uri invocation
*/
private void verifyRequest(Exchange exchange) {
if (exchange.getIn().getHeader(Exchange.SAGA_LONG_RUNNING_ACTION) == null) {
Expand All @@ -76,6 +81,28 @@ private void verifyRequest(Exchange exchange) {
usedURIs.add(completionURI);
}

// CAMEL-17751: Extract URIs from the CamelHttpQuery header
if (usedURIs.isEmpty()) {
try {
Map<String, Object> queryParams = URISupport.parseQuery(exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class));
if (!queryParams.isEmpty()) {
if (queryParams.get(URL_COMPENSATION_KEY) != null) {
compensationURI = queryParams.get(URL_COMPENSATION_KEY).toString();
usedURIs.add(compensationURI);
exchange.getIn().setHeader(URL_COMPENSATION_KEY, compensationURI);
}

if (queryParams.get(URL_COMPLETION_KEY) != null) {
completionURI = queryParams.get(URL_COMPLETION_KEY).toString();
usedURIs.add(completionURI);
exchange.getIn().setHeader(URL_COMPLETION_KEY, completionURI);
}
}
} catch (URISyntaxException ex) {
throw new RuntimeCamelException("URISyntaxException during " + Exchange.HTTP_QUERY + " header parsing");
}
}

for (String uri : usedURIs) {
if (!sagaService.getRegisteredURIs().contains(uri)) {
throw new IllegalArgumentException("URI " + uri + " is not allowed");
Expand Down