Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/camel-spring-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

<modules>
<module>camel-spring</module>
<module>camel-spring-ai</module>
<module>camel-spring-batch</module>
<module>camel-spring-jdbc</module>
<module>camel-spring-ldap</module>
Expand All @@ -47,6 +46,7 @@
<module>camel-spring-xml</module>
<module>camel-undertow-spring-security</module>
<module>camel-spring-cloud-config</module>
<module>camel-spring-ai</module>
</modules>

</project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class DefaultLanguageResolver implements LanguageResolver {
public static final String LANGUAGE_RESOURCE_PATH = "META-INF/services/org/apache/camel/language/";
public static final String LANGUAGE_RESOLVER_RESOURCE_PATH = LANGUAGE_RESOURCE_PATH + "resolver/";

private static final String SIMPLE_NO_FILE = "org.apache.camel.language.simple.SimpleNoFileLanguage";

private static final Logger LOG = LoggerFactory.getLogger(DefaultLanguageResolver.class);

protected FactoryFinder languageFactory;
Expand All @@ -41,12 +43,17 @@ public class DefaultLanguageResolver implements LanguageResolver {
@Override
public Language resolveLanguage(String name, CamelContext context) {
Class<?> type = null;
try {
type = findLanguage(name, context);
} catch (NoFactoryAvailableException e) {
// ignore
} catch (Exception e) {
throw new IllegalArgumentException("Invalid URI, no Language registered for scheme: " + name, e);

if ("simple-no-file".equals(name)) {
type = context.getClassResolver().resolveClass(SIMPLE_NO_FILE);
} else {
try {
type = findLanguage(name, context);
} catch (NoFactoryAvailableException e) {
// ignore
} catch (Exception e) {
throw new IllegalArgumentException("Invalid URI, no Language registered for scheme: " + name, e);
}
}

if (type != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ public class SimpleExpressionParser extends BaseSimpleParser {

// use caches to avoid re-parsing the same expressions over and over again
private final Map<String, Expression> cacheExpression;
private boolean skipFileFunctions;

public SimpleExpressionParser(CamelContext camelContext, String expression, boolean allowEscape,
public SimpleExpressionParser(CamelContext camelContext, String expression,
boolean allowEscape,
Map<String, Expression> cacheExpression) {
this(camelContext, expression, allowEscape, false, cacheExpression);
}

public SimpleExpressionParser(CamelContext camelContext, String expression,
boolean allowEscape, boolean skipFileFunctions,
Map<String, Expression> cacheExpression) {
super(camelContext, expression, allowEscape);
this.cacheExpression = cacheExpression;
this.skipFileFunctions = skipFileFunctions;
}

public Expression parseExpression() {
Expand Down Expand Up @@ -172,7 +181,7 @@ private SimpleNode createNode(SimpleToken token, AtomicInteger functions) {
if (token.getType().isFunctionStart()) {
// starting a new function
functions.incrementAndGet();
return new SimpleFunctionStart(token, cacheExpression);
return new SimpleFunctionStart(token, cacheExpression, skipFileFunctions);
} else if (functions.get() > 0 && token.getType().isFunctionEnd()) {
// there must be a start function already, to let this be a end function
functions.decrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class SimpleLanguage extends LanguageSupport implements StaticService {
private static final String CACHE_KEY_PREFIX = "@SIMPLE@";

boolean allowEscape = true;
boolean skipFileFunctions;

// use caches to avoid re-parsing the same expressions over and over again
private Map<String, Expression> cacheExpression;
Expand All @@ -60,6 +61,13 @@ public class SimpleLanguage extends LanguageSupport implements StaticService {
public SimpleLanguage() {
}

/**
* Special purpose for {@link SimpleNoFileLanguage}
*/
SimpleLanguage(boolean skipFileFunctions) {
this.skipFileFunctions = skipFileFunctions;
}

@Override
public void init() {
// setup cache which requires CamelContext to be set first
Expand Down Expand Up @@ -123,7 +131,7 @@ public Predicate createPredicate(String expression) {

// using the expression cache here with the predicate parser is okay
SimplePredicateParser parser
= new SimplePredicateParser(getCamelContext(), expression, allowEscape, cacheExpression);
= new SimplePredicateParser(getCamelContext(), expression, allowEscape, skipFileFunctions, cacheExpression);
answer = parser.parsePredicate();

if (cachePredicate != null && answer != null) {
Expand Down Expand Up @@ -182,7 +190,8 @@ public Expression createExpression(String expression) {

// only parse if there are simple functions
SimpleExpressionParser parser
= new SimpleExpressionParser(getCamelContext(), expression, allowEscape, cacheExpression);
= new SimpleExpressionParser(
getCamelContext(), expression, allowEscape, skipFileFunctions, cacheExpression);
answer = parser.parseExpression();

if (cacheExpression != null && answer != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.language.simple;

public class SimpleNoFileLanguage extends SimpleLanguage {

public SimpleNoFileLanguage() {
super(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,20 @@ public class SimplePredicateParser extends BaseSimpleParser {

// use caches to avoid re-parsing the same expressions over and over again
private final Map<String, Expression> cacheExpression;
private boolean skipFileFunctions;

public SimplePredicateParser(CamelContext camelContext, String expression, boolean allowEscape,
public SimplePredicateParser(CamelContext camelContext, String expression,
boolean allowEscape,
Map<String, Expression> cacheExpression) {
this(camelContext, expression, allowEscape, false, cacheExpression);
}

public SimplePredicateParser(CamelContext camelContext, String expression,
boolean allowEscape, boolean skipFileFunctions,
Map<String, Expression> cacheExpression) {
super(camelContext, expression, allowEscape);
this.cacheExpression = cacheExpression;
this.skipFileFunctions = skipFileFunctions;
}

public Predicate parsePredicate() {
Expand Down Expand Up @@ -295,7 +304,7 @@ private SimpleNode createNode(
AtomicBoolean startFunction) {
if (token.getType().isFunctionStart()) {
startFunction.set(true);
return new SimpleFunctionStart(token, cacheExpression);
return new SimpleFunctionStart(token, cacheExpression, skipFileFunctions);
} else if (token.getType().isFunctionEnd()) {
startFunction.set(false);
return new SimpleFunctionEnd(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.CamelContext;
import org.apache.camel.Expression;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.language.constant.ConstantLanguage;
import org.apache.camel.language.simple.BaseSimpleParser;
import org.apache.camel.language.simple.SimpleExpressionBuilder;
import org.apache.camel.language.simple.types.SimpleParserException;
Expand All @@ -47,10 +48,12 @@ public class SimpleFunctionExpression extends LiteralExpression {

// use caches to avoid re-parsing the same expressions over and over again
private final Map<String, Expression> cacheExpression;
private final boolean skipFileFunctions;

public SimpleFunctionExpression(SimpleToken token, Map<String, Expression> cacheExpression) {
public SimpleFunctionExpression(SimpleToken token, Map<String, Expression> cacheExpression, boolean skipFileFunctions) {
super(token);
this.cacheExpression = cacheExpression;
this.skipFileFunctions = skipFileFunctions;
}

/**
Expand Down Expand Up @@ -195,7 +198,13 @@ private Expression createSimpleExpression(CamelContext camelContext, String func
// file: prefix
remainder = ifStartsWithReturnRemainder("file:", function);
if (remainder != null) {
Expression fileExpression = createSimpleFileExpression(remainder, strict);
Expression fileExpression;
if (skipFileFunctions) {
// do not create file expressions but keep the function as-is as a constant value
fileExpression = ConstantLanguage.constant("${" + function + "}");
} else {
fileExpression = createSimpleFileExpression(remainder, strict);
}
if (fileExpression != null) {
return fileExpression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public class SimpleFunctionStart extends BaseSimpleNode implements BlockStart {
// use caches to avoid re-parsing the same expressions over and over again
private final Map<String, Expression> cacheExpression;
private final CompositeNodes block;
private final boolean skipFileFunctions;

public SimpleFunctionStart(SimpleToken token, Map<String, Expression> cacheExpression) {
public SimpleFunctionStart(SimpleToken token, Map<String, Expression> cacheExpression, boolean skipFileFunctions) {
super(token);
this.block = new CompositeNodes(token);
this.cacheExpression = cacheExpression;
this.skipFileFunctions = skipFileFunctions;
}

public CompositeNodes getBlock() {
Expand Down Expand Up @@ -68,7 +70,7 @@ public Expression createExpression(CamelContext camelContext, String expression)
}

private Expression doCreateLiteralExpression(CamelContext camelContext, String expression) {
SimpleFunctionExpression function = new SimpleFunctionExpression(this.getToken(), cacheExpression);
SimpleFunctionExpression function = new SimpleFunctionExpression(this.getToken(), cacheExpression, skipFileFunctions);
LiteralNode literal = (LiteralNode) block.getChildren().get(0);
function.addText(literal.getText());
return function.createExpression(camelContext, expression);
Expand Down Expand Up @@ -119,7 +121,7 @@ public <T> T evaluate(Exchange exchange, Class<T> type) {
// we have now concat the block as a String which contains the function expression
// which we then need to evaluate as a function
String exp = sb.toString();
SimpleFunctionExpression function = new SimpleFunctionExpression(token, cacheExpression);
SimpleFunctionExpression function = new SimpleFunctionExpression(token, cacheExpression, skipFileFunctions);
function.addText(exp);
try {
return function.createExpression(camelContext, exp).evaluate(exchange, type);
Expand Down Expand Up @@ -161,7 +163,7 @@ public String createCode(CamelContext camelContext, String expression) throws Si
}

private String doCreateLiteralCode(CamelContext camelContext, String expression) {
SimpleFunctionExpression function = new SimpleFunctionExpression(this.getToken(), cacheExpression);
SimpleFunctionExpression function = new SimpleFunctionExpression(this.getToken(), cacheExpression, skipFileFunctions);
LiteralNode literal = (LiteralNode) block.getChildren().get(0);
function.addText(literal.getText());
return function.createCode(camelContext, expression);
Expand Down Expand Up @@ -203,7 +205,7 @@ private String doCreateCompositeCode(CamelContext camelContext, String expressio
// we have now concat the block as a String which contains inlined functions parsed
// so now we should reparse as a single function
String exp = sb.toString();
SimpleFunctionExpression function = new SimpleFunctionExpression(token, cacheExpression);
SimpleFunctionExpression function = new SimpleFunctionExpression(token, cacheExpression, skipFileFunctions);
function.addText(exp);
try {
return function.createCode(camelContext, exp);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.model.language;

import jakarta.xml.bind.annotation.XmlTransient;

@XmlTransient
public class SimpleNoFileExpression extends TypedExpressionDefinition {

public SimpleNoFileExpression(SimpleExpression expression) {
super(expression);
}

@Override
public String getLanguage() {
return "simple-no-file";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.camel.model.ProcessorDefinitionHelper;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.language.ConstantExpression;
import org.apache.camel.model.language.SimpleExpression;
import org.apache.camel.model.language.SimpleNoFileExpression;
import org.apache.camel.processor.PollEnricher;
import org.apache.camel.support.DefaultExchange;
import org.apache.camel.support.EndpointHelper;
Expand All @@ -44,6 +46,11 @@ public Processor createProcessor() throws Exception {
exp = createExpression(definition.getExpression());
Exchange ex = new DefaultExchange(camelContext);
uri = exp.evaluate(ex, String.class);
} else if (definition.getExpression() instanceof SimpleExpression se) {
// special for simple as we need to not include file functions
SimpleNoFileExpression copy = new SimpleNoFileExpression(se);
exp = createExpression(copy);
uri = definition.getExpression().getExpression();
} else {
exp = createExpression(definition.getExpression());
uri = definition.getExpression().getExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ protected Expression createExpression(String uri) {
// only use simple language if needed
language = LanguageSupport.hasSimpleFunction(uri) ? "simple" : "constant";
}
if ("simple".equals(language)) {
// special for simple as we need to not include file functions
language = "simple-no-file";
}
Language lan = camelContext.resolveLanguage(language);
return lan.createExpression(uri);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.component.file;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;

public class PollEnrichSimpleMoveTest extends ContextTestSupport {

@Test
public void testPollEnrichSimpleMove() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedFileExists(fileUri().substring(5) + "/backup/my-hello.txt");

template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt");

template.sendBody("direct:start", "Trigger");

assertMockEndpointsSatisfied();
}

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:start")
.pollEnrich().simple(fileUri() + "?move=backup/my-${file:onlyname}").timeout(5000).end()
.to("mock:result");
}
};
}

}
Loading