You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/05/16 17:50:40 UTC
[camel] branch main updated: CAMEL-17723 camel-ssh - Dynamic Header is not resolved in pollCommand. (#7605)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6d43b4fbcb5 CAMEL-17723 camel-ssh - Dynamic Header is not resolved in pollCommand. (#7605)
6d43b4fbcb5 is described below
commit 6d43b4fbcb517786c856d6288443f910f3d8cef6
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Mon May 16 19:50:32 2022 +0200
CAMEL-17723 camel-ssh - Dynamic Header is not resolved in pollCommand. (#7605)
---
.../camel/builder/EndpointConsumerBuilder.java | 7 ++-
.../camel/builder/EndpointProducerBuilder.java | 7 ++-
.../apache/camel/model/ProcessorDefinition.java | 10 ++--
.../org/apache/camel/reifier/ToDynamicReifier.java | 2 +-
.../org/apache/camel/reifier/WireTapReifier.java | 4 +-
.../java/org/apache/camel/xml/jaxb/JaxbHelper.java | 6 +-
.../builder/endpoint/AbstractEndpointBuilder.java | 4 ++
.../builder/endpoint/RawUrlPollEnrichTest.java | 65 ++++++++++++++++++++++
.../builder/endpoint/RawUrlWireTapDslTest.java | 64 +++++++++++++++++++++
9 files changed, 156 insertions(+), 13 deletions(-)
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointConsumerBuilder.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointConsumerBuilder.java
index 7b52e88905e..cdb66b76221 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointConsumerBuilder.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointConsumerBuilder.java
@@ -29,10 +29,15 @@ import org.apache.camel.Expression;
*/
public interface EndpointConsumerBuilder extends EndpointConsumerResolver {
/**
- * Builds the url of this endpoint. This API is only intended for Camel internally.
+ * Builds the encoded url of this endpoint. This API is only intended for Camel internally.
*/
String getUri();
+ /**
+ * Builds the raw url of this endpoint. This API is only intended for Camel internally.
+ */
+ String getRawUri();
+
/**
* Adds an option to this endpoint. This API is only intended for Camel internally.
*/
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointProducerBuilder.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointProducerBuilder.java
index e5122be37c3..a6acd231946 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointProducerBuilder.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/EndpointProducerBuilder.java
@@ -29,10 +29,15 @@ import org.apache.camel.Expression;
*/
public interface EndpointProducerBuilder extends EndpointProducerResolver {
/**
- * Builds the url of this endpoint. This API is only intended for Camel internally.
+ * Builds the encoded url of this endpoint. This API is only intended for Camel internally.
*/
String getUri();
+ /**
+ * Builds the raw url of this endpoint. This API is only intended for Camel internally.
+ */
+ String getRawUri();
+
/**
* Adds an option to this endpoint. This API is only intended for Camel internally.
*/
diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index e2b0cadf078..3dd1418045c 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -3022,7 +3022,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
* @see org.apache.camel.processor.Enricher
*/
public EnrichClause<ProcessorDefinition<Type>> enrichWith(@AsEndpointUri EndpointProducerBuilder resourceUri) {
- return enrichWith(resourceUri.getUri());
+ return enrichWith(resourceUri.getRawUri());
}
/**
@@ -3126,7 +3126,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
@AsEndpointUri EndpointProducerBuilder resourceUri, AggregationStrategy aggregationStrategy,
boolean aggregateOnException, boolean shareUnitOfWork) {
EnrichDefinition answer = new EnrichDefinition();
- answer.setExpression(new SimpleExpression(resourceUri.getUri()));
+ answer.setExpression(new SimpleExpression(resourceUri.getRawUri()));
answer.setAggregationStrategy(aggregationStrategy);
answer.setAggregateOnException(Boolean.toString(aggregateOnException));
answer.setShareUnitOfWork(Boolean.toString(shareUnitOfWork));
@@ -3250,7 +3250,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
* @see org.apache.camel.processor.PollEnricher
*/
public Type pollEnrich(EndpointConsumerBuilder resourceUri) {
- return pollEnrich(new SimpleExpression(resourceUri.getUri()), -1, (String) null, false);
+ return pollEnrich(new SimpleExpression(resourceUri.getRawUri()), -1, (String) null, false);
}
/**
@@ -3475,7 +3475,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
public Type pollEnrich(
@AsEndpointUri EndpointConsumerBuilder resourceUri, long timeout, AggregationStrategy aggregationStrategy,
boolean aggregateOnException) {
- return pollEnrich(new SimpleExpression(resourceUri.getUri()), timeout, aggregationStrategy, aggregateOnException);
+ return pollEnrich(new SimpleExpression(resourceUri.getRawUri()), timeout, aggregationStrategy, aggregateOnException);
}
/**
@@ -3502,7 +3502,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
public Type pollEnrich(
@AsEndpointUri EndpointConsumerBuilder resourceUri, long timeout, String aggregationStrategyRef,
boolean aggregateOnException) {
- return pollEnrich(new SimpleExpression(resourceUri.getUri()), timeout, aggregationStrategyRef, aggregateOnException);
+ return pollEnrich(new SimpleExpression(resourceUri.getRawUri()), timeout, aggregationStrategyRef, aggregateOnException);
}
/**
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
index aece53b3e4a..40a51c22bcc 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ToDynamicReifier.java
@@ -40,7 +40,7 @@ public class ToDynamicReifier<T extends ToDynamicDefinition> extends ProcessorRe
String uri;
Expression exp;
if (definition.getEndpointProducerBuilder() != null) {
- uri = definition.getEndpointProducerBuilder().getUri();
+ uri = definition.getEndpointProducerBuilder().getRawUri();
exp = definition.getEndpointProducerBuilder().expr(camelContext);
} else {
uri = StringHelper.notEmpty(definition.getUri(), "uri", this);
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
index 6e1304dd236..79f2577d5a6 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/WireTapReifier.java
@@ -56,7 +56,7 @@ public class WireTapReifier extends ToDynamicReifier<WireTapDefinition<?>> {
// optimize to only use dynamic processor if really needed
String uri;
if (definition.getEndpointProducerBuilder() != null) {
- uri = definition.getEndpointProducerBuilder().getUri();
+ uri = definition.getEndpointProducerBuilder().getRawUri();
} else {
uri = StringHelper.notEmpty(definition.getUri(), "uri", this);
}
@@ -69,7 +69,7 @@ public class WireTapReifier extends ToDynamicReifier<WireTapDefinition<?>> {
SendDynamicProcessor dynamicSendProcessor = null;
SendProcessor sendProcessor = null;
- boolean simple = LanguageSupport.hasSimpleFunction(definition.getUri());
+ boolean simple = LanguageSupport.hasSimpleFunction(uri);
boolean dynamic = parseBoolean(definition.getDynamicUri(), true);
if (dynamic && simple) {
// dynamic so we need the dynamic send processor
diff --git a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
index 128add6465c..d140de5e6b9 100644
--- a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
+++ b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
@@ -120,20 +120,20 @@ public final class JaxbHelper {
public static void resolveEndpointDslUris(RouteDefinition route) {
FromDefinition from = route.getInput();
if (from != null && from.getEndpointConsumerBuilder() != null) {
- String uri = from.getEndpointConsumerBuilder().getUri();
+ String uri = from.getEndpointConsumerBuilder().getRawUri();
from.setUri(uri);
}
Collection<SendDefinition> col = filterTypeInOutputs(route.getOutputs(), SendDefinition.class);
for (SendDefinition<?> to : col) {
if (to.getEndpointProducerBuilder() != null) {
- String uri = to.getEndpointProducerBuilder().getUri();
+ String uri = to.getEndpointProducerBuilder().getRawUri();
to.setUri(uri);
}
}
Collection<ToDynamicDefinition> col2 = filterTypeInOutputs(route.getOutputs(), ToDynamicDefinition.class);
for (ToDynamicDefinition to : col2) {
if (to.getEndpointProducerBuilder() != null) {
- String uri = to.getEndpointProducerBuilder().getUri();
+ String uri = to.getEndpointProducerBuilder().getRawUri();
to.setUri(uri);
}
}
diff --git a/dsl/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java b/dsl/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
index ed464210387..5cdec3e6bfc 100644
--- a/dsl/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
+++ b/dsl/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/AbstractEndpointBuilder.java
@@ -103,6 +103,10 @@ public class AbstractEndpointBuilder {
return computeUri(new LinkedHashMap<>(), null, false, true).getUri();
}
+ public String getRawUri() {
+ return computeUri(new LinkedHashMap<>(), null, false, false).getUri();
+ }
+
protected NormalizedUri computeUri(
Map<String, Object> remaining, CamelContext camelContext, boolean bindToRegistry, boolean encode) {
NormalizedUri answer;
diff --git a/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/RawUrlPollEnrichTest.java b/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/RawUrlPollEnrichTest.java
new file mode 100644
index 00000000000..73066724de7
--- /dev/null
+++ b/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/RawUrlPollEnrichTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder.endpoint;
+
+import org.apache.camel.AggregationStrategy;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+public class RawUrlPollEnrichTest extends BaseEndpointDslTest {
+
+ @Test
+ public void testRawUrl() throws Exception {
+ template.sendBody("seda:foo?size=1", "Camel");
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+
+ mock.expectedBodiesReceived("Hello Camel");
+
+ template.sendBodyAndHeader("direct:start", "Hello", "size", "1");
+
+ mock.assertIsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new EndpointRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(direct("start"))
+ .pollEnrich(seda("foo").size("${header.size}"), new SampleAggregator())
+ .to(mock("result"));
+ }
+ };
+ }
+
+ private static class SampleAggregator implements AggregationStrategy {
+
+ @Override
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ if (newExchange == null) {
+ return oldExchange;
+ }
+ Object oldBody = oldExchange.getIn().getBody();
+ Object newBody = newExchange.getIn().getBody();
+ oldExchange.getIn().setBody(oldBody + " " + newBody);
+ return oldExchange;
+ }
+ }
+}
diff --git a/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/RawUrlWireTapDslTest.java b/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/RawUrlWireTapDslTest.java
new file mode 100644
index 00000000000..9648a961ca6
--- /dev/null
+++ b/dsl/camel-endpointdsl/src/test/java/org/apache/camel/builder/endpoint/RawUrlWireTapDslTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.builder.endpoint;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+//Covers both WireTapReifier and ToDynamicReifier
+public class RawUrlWireTapDslTest extends BaseEndpointDslTest {
+
+ @Test
+ public void testFlow() throws Exception {
+ MockEndpoint m1 = getMockEndpoint("mock:m1");
+ m1.expectedMessageCount(1);
+
+ MockEndpoint m2 = getMockEndpoint("mock:m2");
+ m2.expectedMessageCount(1);
+
+ MockEndpoint m3 = getMockEndpoint("mock:m3");
+ m3.expectedMessageCount(1);
+
+ template.requestBodyAndHeader("direct:a", "Hello World", "size", 1, String.class);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new EndpointRouteBuilder() {
+ public void configure() {
+ from(direct("a"))
+ .recipientList(endpoints(mock("m1"), direct("b")))
+ .routingSlip(endpoints(mock("m2"), direct("c")))
+ .wireTap(seda("d").size("${header.size}")).dynamicUri(true)
+ .enrich(direct("e"))
+ .toD(mock("${header.next}"));
+
+ from(direct("b")).to(log("endpoint.b"));
+ from(direct("c")).to(log("endpoint.c"));
+ from(seda("d?size=1")).to(log("endpoint.d"));
+ from(direct("e"))
+ .setBody(constant("body"))
+ .setHeader("next", constant("m3"));
+
+ }
+ };
+ }
+
+}