Skip to content
Merged
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
6 changes: 6 additions & 0 deletions core/camel-core-languages/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
<directory>../../src/main/resources</directory>
<filtering>false</filtering>
</resource>
<!-- Declaring the module's own resources explicitly: the entry above replaces
Maven's default resource directory, which would otherwise be inherited. -->
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
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.
#
# Camel-karaf specific: Apache Camel intentionally ships no service file for this
# language, because DefaultLanguageResolver resolves the name through a hardcoded
# branch instead. OsgiLanguageResolver has no such branch and looks the language up
# in the OSGi service registry, so without this entry "simple-no-file" cannot be
# resolved in Karaf and poll/pollEnrich with a simple expression fails with
# NoSuchLanguageException. Keep this file across Camel upgrades. See issue #707.
#
class=org.apache.camel.language.simple.SimpleNoFileLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.karaf.camel.test;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.RouteDefinition;
import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
import org.apache.karaf.camel.itests.CamelRouteSupplier;
import org.osgi.service.component.annotations.Component;

/**
* Covers the resolution of the internal {@code simple-no-file} language in OSGi.
* <p>
* When a {@code pollEnrich} is given a {@code simple} expression, {@code PollEnrichReifier} rewrites it to the
* {@code simple-no-file} language, so starting this route makes the Camel context resolve that name. Apache Camel
* ships no service file for it — {@code DefaultLanguageResolver} resolves it through a hardcoded branch — whereas
* camel-karaf's {@code OsgiLanguageResolver} goes through the OSGi service registry. Without the service file in
* the camel-core-languages bundle, this route fails to start with a {@code NoSuchLanguageException}.
*
* @see <a href="https://github.com/apache/camel-karaf/issues/707">issue #707</a>
*/
@Component(
name = "karaf-camel-poll-enrich-test",
immediate = true,
service = CamelRouteSupplier.class
)
public class CamelPollEnrichRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier {

private static final String FILE_NAME_VARIABLE = "sourceFileName";
private static final String SOURCE_FILE_NAME = "poll-enrich-source.txt";
private static final long POLL_TIMEOUT_MS = 10000L;

public String getBaseDir() {
return "%s/poll-enrich".formatted(System.getProperty("project.target"));
}

@Override
protected boolean consumerEnabled() {
// Everything happens in the producer route: it seeds the file, then polls it back.
return false;
}

@Override
protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) {
String directory = getBaseDir();
producerRoute
.setVariable(FILE_NAME_VARIABLE, builder.constant(SOURCE_FILE_NAME))
.setBody(builder.constant("OK"))
.toF("file:%s?fileName=${variable.%s}", directory, FILE_NAME_VARIABLE)
// Clear the body so that only a successful enrichment can restore it.
.setBody(builder.constant(""))
.pollEnrich()
.simple("file:%s?fileName=${variable.%s}&initialDelay=0&delay=100"
.formatted(directory, FILE_NAME_VARIABLE))
.timeout(POLL_TIMEOUT_MS)
.toF("mock:%s", getResultMockName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.apache.karaf.camel.itest;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.camel.component.mock.MockEndpoint;
import org.apache.karaf.camel.itests.AbstractCamelRouteWithBundleITest;
Expand Down Expand Up @@ -63,6 +64,11 @@ public void testCamelBean() throws Exception {
new CamelBeanITest(this).testRoutes();
}

@Test
public void testCamelPollEnrich() throws Exception {
new CamelPollEnrichITest(this).testRoutes();
}

public static class CamelFileITest extends AbstractCamelSingleFeatureResultFileBasedRoute {

public CamelFileITest(CamelContextProvider provider, String baseDir) {
Expand Down Expand Up @@ -110,4 +116,22 @@ public void configureMock(MockEndpoint mock) {
mock.expectedBodiesReceived("OK");
}
}

/**
* Asserts that a {@code pollEnrich} driven by a {@code simple} expression starts and enriches, which requires the
* internal {@code simple-no-file} language to be resolvable in OSGi. See issue #707.
*/
public static class CamelPollEnrichITest extends AbstractCamelSingleFeatureResultMockBasedRoute {

public CamelPollEnrichITest(CamelContextProvider provider) {
super(provider);
}

@Override
public void configureMock(MockEndpoint mock) {
// The route seeds a file and polls it back, so allow more headroom than the 10s default.
mock.setResultWaitTime(TimeUnit.SECONDS.toMillis(30));
mock.expectedBodiesReceived("OK");
}
}
}
Loading