index int64 0 0 | repo_id stringlengths 9 205 | file_path stringlengths 31 246 | content stringlengths 1 12.2M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka/KafkaUtil.java | /*
* 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.example.resume.strategies.kafka;
import java.time.Duration;
import org.apache.camel.processor.resume.kafka.KafkaResumeStrategyConfiguration;
import org.apache.camel.processor.resume.kafka.KafkaResumeStrategyConfigurationBuilder;
import org.apache.camel.processor.resume.kafka.SingleNodeKafkaResumeStrategy;
public final class KafkaUtil {
private KafkaUtil() {
}
public static SingleNodeKafkaResumeStrategy getDefaultStrategy() {
KafkaResumeStrategyConfiguration resumeStrategyConfiguration = getDefaultKafkaResumeStrategyConfiguration();
return new SingleNodeKafkaResumeStrategy(resumeStrategyConfiguration);
}
public static KafkaResumeStrategyConfiguration getDefaultKafkaResumeStrategyConfiguration() {
return getDefaultKafkaResumeStrategyConfigurationBuilder().build();
}
public static KafkaResumeStrategyConfigurationBuilder getDefaultKafkaResumeStrategyConfigurationBuilder() {
String bootStrapAddress = System.getProperty("bootstrap.address", "localhost:9092");
String kafkaTopic = System.getProperty("resume.type.kafka.topic", "offsets");
return KafkaResumeStrategyConfigurationBuilder.newBuilder()
.withBootstrapServers(bootStrapAddress)
.withTopic(kafkaTopic)
.withProducerProperty("max.block.ms", "10000")
.withMaxInitializationDuration(Duration.ofSeconds(5))
.withProducerProperty("delivery.timeout.ms", "30000")
.withProducerProperty("session.timeout.ms", "15000")
.withProducerProperty("request.timeout.ms", "15000")
.withConsumerProperty("session.timeout.ms", "20000");
}
}
| 1,700 |
0 | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka/fileset/LargeDirectoryRouteBuilder.java | /*
* 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.example.resume.strategies.kafka.fileset;
import java.io.File;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.example.resume.strategies.kafka.KafkaUtil;
import org.apache.camel.resume.ResumeStrategyConfiguration;
import org.apache.camel.resume.ResumeStrategyConfigurationBuilder;
import org.apache.camel.resume.cache.ResumeCache;
import org.apache.camel.support.resume.Resumables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LargeDirectoryRouteBuilder extends RouteBuilder {
private static final Logger LOG = LoggerFactory.getLogger(LargeDirectoryRouteBuilder.class);
private final ResumeCache<File> cache;
private final ResumeStrategyConfigurationBuilder<? extends ResumeStrategyConfigurationBuilder, ? extends ResumeStrategyConfiguration> resumeStrategyConfigurationBuilder;
private final long delay;
public LargeDirectoryRouteBuilder(ResumeCache<File> cache) {
this(KafkaUtil.getDefaultKafkaResumeStrategyConfigurationBuilder(), cache);
}
public LargeDirectoryRouteBuilder(ResumeStrategyConfigurationBuilder<?, ?> resumeStrategyConfigurationBuilder, ResumeCache<File> cache) {
this(resumeStrategyConfigurationBuilder, cache, 0);
}
public LargeDirectoryRouteBuilder(ResumeStrategyConfigurationBuilder<? extends ResumeStrategyConfigurationBuilder, ? extends ResumeStrategyConfiguration> resumeStrategyConfigurationBuilder, ResumeCache<File> cache, long delay) {
this.resumeStrategyConfigurationBuilder = resumeStrategyConfigurationBuilder;
this.cache = cache;
this.delay = delay;
}
private void process(Exchange exchange) throws InterruptedException {
File path = exchange.getMessage().getHeader("CamelFilePath", File.class);
LOG.debug("Processing {}", path.getPath());
exchange.getMessage().setHeader(Exchange.OFFSET, Resumables.of(path.getParentFile(), path));
if (delay > 0) {
Thread.sleep(delay);
}
}
/**
* Let's configure the Camel routing rules using Java code...
*/
public void configure() {
from("file:{{input.dir}}?noop=true&recursive=true")
.resumable().configuration(resumeStrategyConfigurationBuilder.withResumeCache(cache))
.process(this::process)
.to("file:{{output.dir}}");
}
}
| 1,701 |
0 | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka/file/LargeFileRouteBuilder.java | /*
* 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.example.resume.strategies.kafka.file;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.file.FileConstants;
import org.apache.camel.example.resume.strategies.kafka.KafkaUtil;
import org.apache.camel.processor.resume.kafka.KafkaResumeStrategyConfigurationBuilder;
import org.apache.camel.resume.Resumable;
import org.apache.camel.resume.cache.ResumeCache;
import org.apache.camel.support.resume.Resumables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A Camel Java DSL Router
*/
public class LargeFileRouteBuilder extends RouteBuilder {
private static final Logger LOG = LoggerFactory.getLogger(LargeFileRouteBuilder.class);
private ProducerTemplate producerTemplate;
private final ResumeCache<File> cache;
private long lastOffset;
private long lineCount = 0;
private final CountDownLatch latch;
public LargeFileRouteBuilder(ResumeCache<File> cache, CountDownLatch latch) {
this.cache = cache;
this.latch = latch;
}
private void process(Exchange exchange) {
final String body = exchange.getMessage().getBody(String.class);
final String filePath = exchange.getMessage().getHeader(Exchange.FILE_PATH, String.class);
final File file = new File(filePath);
// Get the initial offset and use it to update the last offset when reading the first line
final Resumable resumable = exchange.getMessage().getHeader(FileConstants.INITIAL_OFFSET, Resumable.class);
final Long value = resumable.getLastOffset().getValue(Long.class);
if (lineCount == 0) {
lastOffset += value;
}
// It sums w/ 1 in order to account for the newline that is removed by readLine
lastOffset += body.length() + 1;
lineCount++;
exchange.getMessage().setHeader(Exchange.OFFSET, Resumables.of(file, lastOffset));
producerTemplate.sendBody("direct:summary", String.valueOf(lastOffset));
LOG.info("Read data: {} / offset key: {} / offset value: {}", body, filePath, lastOffset);
if (latch.getCount() == 1) {
exchange.setRouteStop(true);
}
latch.countDown();
}
/**
* Let's configure the Camel routing rules using Java code...
*/
public void configure() {
producerTemplate = getContext().createProducerTemplate();
final KafkaResumeStrategyConfigurationBuilder defaultKafkaResumeStrategyConfigurationBuilder = KafkaUtil
.getDefaultKafkaResumeStrategyConfigurationBuilder()
.withResumeCache(cache);
from("file:{{input.dir}}?noop=true&fileName={{input.file}}")
.routeId("largeFileRoute")
.convertBodyTo(String.class)
.split(body().tokenize("\n"))
.streaming()
.stopOnException()
.resumable()
.configuration(defaultKafkaResumeStrategyConfigurationBuilder)
.intermittent(true)
.process(this::process);
from("direct:summary")
.to("file:{{output.dir}}?fileName=summary.txt&fileExist=Append&appendChars=\n");
}
}
| 1,702 |
0 | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka | Create_ds/camel-examples/resume-api/resume-api-common/src/main/java/org/apache/camel/example/resume/strategies/kafka/check/CheckRoute.java | package org.apache.camel.example.resume.strategies.kafka.check;
import org.apache.camel.builder.RouteBuilder;
public class CheckRoute extends RouteBuilder {
@Override
public void configure() {
from("kafka:{{resume.type.kafka.topic}}?brokers={{bootstrap.address}}&maxBlockMs=5000&pollTimeoutMs=1000")
.to("file:{{output.dir}}?fileName=summary.txt&fileExist=Append&appendChars=\n");
}
}
| 1,703 |
0 | Create_ds/camel-examples/oaipmh/src/test/java/org/apache/camel/example | Create_ds/camel-examples/oaipmh/src/test/java/org/apache/camel/example/oaipmh/OAIPMHTest.java | /*
* 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.example.oaipmh;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can extract data using OAI-PMH.
*/
class OAIPMHTest extends CamelTestSupport {
@Test
void should_extract_title_publications() {
NotifyBuilder notify = new NotifyBuilder(context).wereSentTo("log:titles").whenCompleted(1).create();
assertTrue(
notify.matches(40, TimeUnit.SECONDS), "at least 1 message should be completed"
);
}
@Override
protected RoutesBuilder createRouteBuilder() {
return new OAIPMHRouteBuilder();
}
}
| 1,704 |
0 | Create_ds/camel-examples/oaipmh/src/main/java/org/apache/camel/example | Create_ds/camel-examples/oaipmh/src/main/java/org/apache/camel/example/oaipmh/Application.java | /*
* 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.example.oaipmh;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
public final class Application {
private Application() {
}
public static void main(String[] args) throws Exception {
try (CamelContext context = new DefaultCamelContext()) {
context.addRoutes(new OAIPMHRouteBuilder());
context.start();
// so run for 10 seconds
Thread.sleep(10_000);
}
}
}
| 1,705 |
0 | Create_ds/camel-examples/oaipmh/src/main/java/org/apache/camel/example | Create_ds/camel-examples/oaipmh/src/main/java/org/apache/camel/example/oaipmh/OAIPMHRouteBuilder.java | /*
* 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.example.oaipmh;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.support.builder.Namespaces;
public class OAIPMHRouteBuilder extends RouteBuilder {
@Override
public void configure() {
from("oaipmh://export.arxiv.org/oai2?"
+ "verb=ListSets"
+ "&onlyFirst=true"
+ "&delay=1000"
+ "&initialDelay=1000")
.split(xpath("/default:OAI-PMH/default:ListSets/default:set",
new Namespaces("default", "http://www.openarchives.org/OAI/2.0/")))
.filter().xpath("default:set/default:setName='Mathematics'",
new Namespaces("default", "http://www.openarchives.org/OAI/2.0/"))
.to ("direct:ListRecords");
from("direct:ListRecords")
.setHeader("CamelOaimphSet", xpath("/default:set/default:setSpec/text()",
new Namespaces("default", "http://www.openarchives.org/OAI/2.0/")))
//Prevent error message by request overload
.delay(10000)
.setHeader("CamelOaimphOnlyFirst", constant("true"))
.to("oaipmh://export.arxiv.org/oai2?")
.split(body())
.split(xpath("/default:OAI-PMH/default:ListRecords/default:record/default:metadata/oai_dc:dc/dc:title/text()",
new Namespaces("default", "http://www.openarchives.org/OAI/2.0/")
.add("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/")
.add("dc", "http://purl.org/dc/elements/1.1/")))
//Log the titles of the records
.to("log:titles")
.to("mock:result");
}
}
| 1,706 |
0 | Create_ds/camel-examples/basic/src/test/java/org/apache/camel/example | Create_ds/camel-examples/basic/src/test/java/org/apache/camel/example/basic/CamelBasicTest.java | /*
* 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.example.basic;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;
import static org.apache.camel.example.basic.CamelBasic.createBasicRoute;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can be launched in standalone mode.
*/
class CamelBasicTest extends CamelTestSupport {
@Test
void should_support_standalone_mode() {
NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(1).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
);
}
@Override
protected RoutesBuilder createRouteBuilder() {
return createBasicRoute();
}
}
| 1,707 |
0 | Create_ds/camel-examples/basic/src/main/java/org/apache/camel/example | Create_ds/camel-examples/basic/src/main/java/org/apache/camel/example/basic/CamelBasic.java | /*
* 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.example.basic;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
/**
* A basic example running as public static void main.
*/
public final class CamelBasic {
public static void main(String[] args) throws Exception {
// create a CamelContext
try (CamelContext camel = new DefaultCamelContext()) {
// add routes which can be inlined as anonymous inner class
// (to keep all code in a single java file for this basic example)
camel.addRoutes(createBasicRoute());
// start is not blocking
camel.start();
// so run for 10 seconds
Thread.sleep(10_000);
}
}
static RouteBuilder createBasicRoute() {
return new RouteBuilder() {
@Override
public void configure() {
from("timer:foo")
.log("Hello Camel");
}
};
}
}
| 1,708 |
0 | Create_ds/camel-examples/main-yaml/src/test/java/org/apache/camel | Create_ds/camel-examples/main-yaml/src/test/java/org/apache/camel/example/MainYAMLTest.java | /*
* 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.example;
import java.util.concurrent.TimeUnit;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel supports YAML routes.
*/
class MainYAMLTest extends CamelMainTestSupport {
@Test
void should_support_yaml_routes() {
NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(1).whenBodiesDone("Bye World").create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
);
}
@Override
protected Class<?> getMainClass() {
return MyApplication.class;
}
}
| 1,709 |
0 | Create_ds/camel-examples/main-yaml/src/main/java/org/apache/camel | Create_ds/camel-examples/main-yaml/src/main/java/org/apache/camel/example/MyConfiguration.java | /*
* 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.example;
import org.apache.camel.BindToRegistry;
import org.apache.camel.CamelContext;
import org.apache.camel.PropertyInject;
import org.apache.camel.CamelConfiguration;
/**
* Class to configure the Camel application.
*/
public class MyConfiguration implements CamelConfiguration {
@BindToRegistry
public MyBean myBean(@PropertyInject("hi") String hi, @PropertyInject("bye") String bye) {
// this will create an instance of this bean with the name of the method (eg myBean)
return new MyBean(hi, bye);
}
@Override
public void configure(CamelContext camelContext) {
// this method is optional and can be removed if no additional configuration is needed.
}
}
| 1,710 |
0 | Create_ds/camel-examples/main-yaml/src/main/java/org/apache/camel | Create_ds/camel-examples/main-yaml/src/main/java/org/apache/camel/example/MyApplication.java | /*
* 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.example;
import org.apache.camel.main.Main;
/**
* Main class that boot the Camel application
*/
public class MyApplication {
public static void main(String[] args) throws Exception {
// use Camels Main class
Main main = new Main(MyApplication.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
main.run(args);
}
}
| 1,711 |
0 | Create_ds/camel-examples/main-yaml/src/main/java/org/apache/camel | Create_ds/camel-examples/main-yaml/src/main/java/org/apache/camel/example/MyBean.java | /*
* 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.example;
public class MyBean {
private String hi;
private String bye;
public MyBean(String hi, String bye) {
this.hi = hi;
this.bye = bye;
}
public String hello() {
return hi + " how are you?";
}
public String bye() {
return bye + " World";
}
}
| 1,712 |
0 | Create_ds/camel-examples/loadbalancing/src/test/java/org/apache/camel | Create_ds/camel-examples/loadbalancing/src/test/java/org/apache/camel/example/LoadBalancingTest.java | /*
* 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.example;
import org.apache.camel.Predicate;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.example.model.Report;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test allowing to check that Camel can load balance the load.
*/
@CamelSpringTest
@ContextConfiguration(locations = { "test-camel-context.xml" })
class LoadBalancingTest {
@Autowired
ModelCamelContext context;
@Test
void should_support_load_balancing() {
final String[] minaServers = {"localhost:9991", "localhost:9992"};
final Predicate predicate = exchange -> {
final Report report = exchange.getIn().getBody(Report.class);
return report.getReply().contains(minaServers[(report.getId() - 1) % 2]);
};
NotifyBuilder notify = new NotifyBuilder(context).fromRoute("sendMessage").whenCompleted(4)
.whenAllDoneMatches(predicate)
.create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "4 messages should be completed"
);
}
}
| 1,713 |
0 | Create_ds/camel-examples/loadbalancing/src/main/java/org/apache/camel/example | Create_ds/camel-examples/loadbalancing/src/main/java/org/apache/camel/example/model/Report.java | /*
* 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.example.model;
import java.io.Serializable;
public class Report implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String title;
private String content;
private String reply;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getReply() {
return reply;
}
public void setReply(String reply) {
this.reply = reply;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("\n>> ***********************************************\n");
result.append(">> Report id: " + this.id + "\n");
result.append(">> Report title: " + this.title + "\n");
result.append(">> Report content: " + this.content + "\n");
result.append(">> Report reply: " + this.reply + "\n");
result.append(">> ***********************************************\n");
return result.toString();
}
}
| 1,714 |
0 | Create_ds/camel-examples/loadbalancing/src/main/java/org/apache/camel/example | Create_ds/camel-examples/loadbalancing/src/main/java/org/apache/camel/example/service/Reporting.java | /*
* 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.example.service;
import org.apache.camel.Body;
import org.apache.camel.Header;
import org.apache.camel.example.model.Report;
public class Reporting {
public Report updateReport(@Body Report report, @Header("minaServer") String name) {
report.setReply("Report updated from MINA server running on: " + name);
// send the report updated
return report;
}
}
| 1,715 |
0 | Create_ds/camel-examples/loadbalancing/src/main/java/org/apache/camel/example | Create_ds/camel-examples/loadbalancing/src/main/java/org/apache/camel/example/service/Generator.java | /*
* 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.example.service;
import org.apache.camel.example.model.Report;
public class Generator {
private int count;
public Report createReport() {
int counter = ++count;
// Create a Report object
Report report = new Report();
report.setId(counter);
report.setTitle("Report Title: " + counter);
report.setContent("This is a dummy report");
// Add the report to the Body
return report;
}
}
| 1,716 |
0 | Create_ds/camel-examples/spring-security/src/test/java/org/apache/camel | Create_ds/camel-examples/spring-security/src/test/java/org/apache/camel/example/SpringSecurityIT.java | /*
* 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.example;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.io.File;
import java.net.URL;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
/**
* A basic integration test checking that Camel can leverage Spring Security to secure the endpoints.
*/
@ExtendWith(ArquillianExtension.class)
public class SpringSecurityIT {
@Deployment
public static WebArchive createDeployment() {
// build the .war with all the resources and libraries
return ShrinkWrap.create(WebArchive.class, "camel-example-spring-security.war")
.setWebXML(new File("./src/main/webapp/WEB-INF/web.xml"))
.addAsResource("log4j2.properties")
.addAsResource("camel-context.xml")
.addAsLibraries(
Maven.resolver().loadPomFromFile("pom.xml").importRuntimeDependencies().resolve()
.withTransitivity().asFile()
);
}
@ArquillianResource
URL url;
@Test
@RunAsClient
void should_prevent_anonymous_access_to_admin() {
given()
.baseUri(url.toString())
.when()
.get("/camel/admin")
.then()
.statusCode(401);
}
@Test
@RunAsClient
void should_prevent_bob_to_access_to_admin() {
given()
.baseUri(url.toString())
.auth().basic("bob", "bobspassword")
.when()
.get("/camel/admin")
.then()
.body(containsString("Access Denied with the Policy"));
}
@Test
@RunAsClient
void should_allow_jim_to_access_to_admin() {
given()
.baseUri(url.toString())
.auth().basic("jim", "jimspassword")
.when()
.get("/camel/admin")
.then()
.statusCode(200)
.body(containsString("OK"));
}
@Test
@RunAsClient
void should_prevent_anonymous_access_to_user() {
given()
.baseUri(url.toString())
.when()
.get("/camel/user")
.then()
.statusCode(401);
}
@Test
@RunAsClient
void should_allow_bob_to_access_to_user() {
given()
.baseUri(url.toString())
.auth().basic("bob", "bobspassword")
.when()
.get("/camel/user")
.then()
.statusCode(200)
.body(containsString("Normal user"));
}
@Test
@RunAsClient
void should_allow_jim_to_access_to_user() {
given()
.baseUri(url.toString())
.auth().basic("jim", "jimspassword")
.when()
.get("/camel/user")
.then()
.statusCode(200)
.body(containsString("Normal user"));
}
}
| 1,717 |
0 | Create_ds/camel-examples/minio/src/test/java/org/apache/camel | Create_ds/camel-examples/minio/src/test/java/org/apache/camel/example/MainMinioTest.java | /*
* 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.example;
import io.minio.MinioClient;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.component.minio.MinioComponent;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.test.infra.minio.services.MinioService;
import org.apache.camel.test.infra.minio.services.MinioServiceFactory;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MainMinioTest extends CamelMainTestSupport {
@RegisterExtension
private static final MinioService MINIO_SERVICE = MinioServiceFactory.createService();
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
MinioComponent minio = camelContext.getComponent("minio", MinioComponent.class);
minio.getConfiguration().setMinioClient(MinioClient.builder()
.endpoint("http://" + MINIO_SERVICE.host(), MINIO_SERVICE.port(), false)
.credentials(MINIO_SERVICE.accessKey(), MINIO_SERVICE.secretKey())
.build());
return camelContext;
}
@Test
void should_consume_and_poll_minio_bucket() {
NotifyBuilder notify = new NotifyBuilder(context).fromRoute("minio-consumer").whenCompleted(1).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
);
}
@Test
void should_produce_and_put_in_minio_bucket() {
NotifyBuilder notify = new NotifyBuilder(context).fromRoute("minio-producer").whenCompleted(1).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 file should be created"
);
}
@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.addRoutesBuilder(MinioConsumer.class);
configuration.addRoutesBuilder(MinioProducer.class);
}
}
| 1,718 |
0 | Create_ds/camel-examples/minio/src/main/java/org/apache/camel | Create_ds/camel-examples/minio/src/main/java/org/apache/camel/example/MinioConsumer.java | /*
* 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.example;
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
/**
* To use the endpoint DSL then we must extend EndpointRouteBuilder instead of RouteBuilder
*/
public class MinioConsumer extends EndpointRouteBuilder {
@Override
public void configure() throws Exception {
from(minio("{{bucketName}}").delay(1000L).deleteAfterRead(false)).routeId("minio-consumer").log("the content is ${body}");
}
} | 1,719 |
0 | Create_ds/camel-examples/minio/src/main/java/org/apache/camel | Create_ds/camel-examples/minio/src/main/java/org/apache/camel/example/MinioProducer.java | /*
* 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.example;
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.component.minio.MinioConstants;
/**
* To use the endpoint DSL then we must extend EndpointRouteBuilder instead of RouteBuilder
*/
public class MinioProducer extends EndpointRouteBuilder {
@Override
public void configure() throws Exception {
from(timer("fire").repeatCount("1"))
.routeId("minio-producer")
.process(exchange -> {
exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, "camel-content-type.txt");
exchange.getIn().setHeader(MinioConstants.CONTENT_TYPE, "application/text");
exchange.getIn().setBody("Camel MinIO rocks!");
})
.to(minio("{{bucketName}}").autoCreateBucket(true));
}
}
| 1,720 |
0 | Create_ds/camel-examples/minio/src/main/java/org/apache/camel | Create_ds/camel-examples/minio/src/main/java/org/apache/camel/example/MyApplication.java | /*
* 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.example;
import org.apache.camel.main.Main;
/**
* Main class that boot the Camel application
*/
public final class MyApplication {
private MyApplication() {
}
public static void main(String[] args) throws Exception {
// use Camels Main class
Main main = new Main(MyApplication.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
main.run(args);
}
} | 1,721 |
0 | Create_ds/camel-examples/spring-pulsar/src/test/java/org/apache/camel | Create_ds/camel-examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringPulsarTest.java | /*
* 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.example;
import java.util.concurrent.TimeUnit;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.infra.pulsar.services.PulsarService;
import org.apache.camel.test.infra.pulsar.services.PulsarServiceFactory;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.apache.camel.example.pulsar.client.CamelClient.ENDPOINT_URI;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can exchange messages with Apache Pulsar.
*/
class SpringPulsarTest extends CamelSpringTestSupport {
@RegisterExtension
private static final PulsarService SERVICE = PulsarServiceFactory.createService();
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml");
}
@Test
void should_exchange_messages() {
template.sendBody(ENDPOINT_URI, 22);
NotifyBuilder notify = new NotifyBuilder(context)
.whenCompleted(1).wereSentTo("log:*").whenBodiesDone(66).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
);
}
}
| 1,722 |
0 | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/Treble.java | /*
* 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.example.pulsar.server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is the implementation of the business service.
*/
public class Treble implements Multiplier {
private static final Logger LOGGER = LoggerFactory.getLogger(Treble.class);
@Override
public int multiply(final int originalNumber) {
LOGGER.info("Number to multiply received {}", originalNumber);
return originalNumber * 3;
}
}
| 1,723 |
0 | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/ServerRoutes.java | /*
* 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.example.pulsar.server;
import org.apache.camel.builder.RouteBuilder;
/**
* This class defines the routes on the Server. The class extends a base class in Camel {@link RouteBuilder}
* that can be used to easily setup the routes in the configure() method.
*/
public class ServerRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
// route from the numbers queue to our business that is a spring bean registered with the id=multiplier
// Camel will introspect the multiplier bean and find the best candidate of the method to invoke.
// As our multiplier bean only have one method its easy for Camel to find the method to use.
from("pulsar:non-persistent://tn1/ns1/cameltest?subscriptionName=serversub&numberOfConsumers=1&consumerQueueSize=1")
.to("bean:multiplier")
.to("log:INFO?showBody=true");
}
}
| 1,724 |
0 | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/Multiplier.java | /*
* 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.example.pulsar.server;
/**
* Our business service.
*/
// START SNIPPET: e1
public interface Multiplier {
/**
* Multiplies the given number by a pre-defined constant.
*
* @param originalNumber The number to be multiplied
* @return The result of the multiplication
*/
int multiply(int originalNumber);
}
// END SNIPPET: e1
| 1,725 |
0 | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/Beans.java | /*
* 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.example.pulsar.common;
import org.apache.pulsar.client.admin.PulsarAdmin;
import org.apache.pulsar.client.api.PulsarClientException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* The class holding all the beans required to access to Apache Pulsar that are not easy to create from
* a pure XML configuration.
*/
@Configuration
public class Beans {
@Bean
public PulsarAdmin pulsarAdmin(@Value("#{pulsarAdminHost}") String pulsarAdminHost) throws PulsarClientException {
return PulsarAdmin.builder().serviceHttpUrl(pulsarAdminHost).build();
}
}
| 1,726 |
0 | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/TypeConverters.java | /*
* 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.example.pulsar.common;
import java.nio.ByteBuffer;
import org.apache.camel.Converter;
public class TypeConverters implements org.apache.camel.TypeConverters {
// In Camel 3.17 and later, this will not be called because overridden by
// built-in Bulk Converter which handles byte array to Integer conversion
// by first converting the byte array to a String
// @Converter
public int intFromByteArray(byte[] bytes) {
return ByteBuffer.wrap(bytes).getInt();
}
@Converter
public byte[] intToByteArray(Integer value) {
// Write it as a string since that is how Bulk Converter will handle it
return value.toString().getBytes();
}
}
| 1,727 |
0 | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar | Create_ds/camel-examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClient.java | /*
* 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.example.pulsar.client;
import java.util.Random;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Client that uses the {@link ProducerTemplate} to easily exchange messages with the Server.
* <p/>
* Requires that the Pulsar broker is running, as well as CamelServer
*/
public final class CamelClient {
public static final String ENDPOINT_URI = "pulsar:non-persistent://tn1/ns1/cameltest?producerName=clientProd";
private CamelClient() {
// Helper class
}
public static void main(final String[] args) throws Exception {
System.out.println("Notice this client requires that the CamelServer is already running!");
try (AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml")) {
// get the camel template for Spring template style sending of messages (= producer)
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
for (int i=0; i<10;i++) {
int input = new Random().nextInt(100);
System.out.printf("Invoking the multiply with %d%n", input);
camelTemplate.sendBody(ENDPOINT_URI, ExchangePattern.InOnly, input);
}
}
}
}
| 1,728 |
0 | Create_ds/camel-examples/main-joor/src/test/java/org/apache/camel | Create_ds/camel-examples/main-joor/src/test/java/org/apache/camel/example/MainJOORTest.java | /*
* 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.example;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import static org.apache.camel.util.PropertiesHelper.asProperties;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel supports jOOR language in the Camel DSL.
*/
class MainJOORTest extends CamelMainTestSupport {
@Override
protected Properties useOverridePropertiesWithPropertiesComponent() {
return asProperties("myPeriod", Integer.toString(500));
}
@Test
void should_support_joor_in_dsl() {
NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(10).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "10 messages should be completed"
);
}
@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.addRoutesBuilder(MyRouteBuilder.class);
}
}
| 1,729 |
0 | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel/example/MyUser.java | /*
* 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.example;
public class MyUser {
private String name;
private int age;
public MyUser(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return name;
}
}
| 1,730 |
0 | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel/example/UserFactoryBean.java | /*
* 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.example;
import java.util.Random;
public class UserFactoryBean {
private UserFactoryBean() {
}
private static final MyUser user1 = new MyUser("Tony", 44);
private static final MyUser user2 = new MyUser("Scott", 23);
private static final MyUser user3 = new MyUser("Jack", 14);
private static final Random RANDOM = new Random();
public static MyUser createUser() {
int ran = RANDOM.nextInt(3);
if (ran == 0) {
return user1;
} else if (ran == 1) {
return user2;
} else {
return user3;
}
}
}
| 1,731 |
0 | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel/example/MyApplication.java | /*
* 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.example;
import org.apache.camel.main.Main;
/**
* Main class that boot the Camel application
*/
public final class MyApplication {
private MyApplication() {
}
public static void main(String[] args) throws Exception {
// use Camels Main class
Main main = new Main(MyApplication.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
main.run(args);
}
}
| 1,732 |
0 | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel | Create_ds/camel-examples/main-joor/src/main/java/org/apache/camel/example/MyRouteBuilder.java | /*
* 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.example;
import org.apache.camel.builder.RouteBuilder;
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:foo?period={{myPeriod}}")
.bean(UserFactoryBean.class, "createUser")
.choice()
.when(joor("var user = bodyAs(MyUser); return user.getName() != null && user.getAge() > 21"))
.log("User ${body} can enter bar")
.otherwise()
.log("User ${body} cannot enter bar");
}
}
| 1,733 |
0 | Create_ds/camel-examples/kamelet/src/test/java/org/apache/camel | Create_ds/camel-examples/kamelet/src/test/java/org/apache/camel/example/KameletTest.java | /*
* 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.example;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can build routes thanks to Kamelet.
*/
class KameletTest extends CamelMainTestSupport {
@Test
void should_build_routes_from_kamelets() {
NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(3).wereSentTo("log:myKamelet1").and()
.whenCompleted(3).wereSentTo("log:myKamelet2").create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "3 messages should be completed"
);
}
@Override
protected Class<?> getMainClass() {
return MyApplication.class;
}
}
| 1,734 |
0 | Create_ds/camel-examples/kamelet/src/main/java/org/apache/camel | Create_ds/camel-examples/kamelet/src/main/java/org/apache/camel/example/MyApplication.java | /*
* 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.example;
import org.apache.camel.main.Main;
/**
* Main class that boot the Camel application
*/
public final class MyApplication {
private MyApplication() {
}
public static void main(String[] args) throws Exception {
// use Camels Main class
Main main = new Main(MyApplication.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
main.run(args);
}
}
| 1,735 |
0 | Create_ds/camel-examples/kamelet/src/main/java/org/apache/camel | Create_ds/camel-examples/kamelet/src/main/java/org/apache/camel/example/MyRoutes.java | /*
* 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.example;
import org.apache.camel.builder.RouteBuilder;
public class MyRoutes extends RouteBuilder {
/**
* Configure and adds routes.
*/
public void configure() {
// create two routes from the template
from("kamelet:myTemplate?name=myKamelet1&greeting=hello")
.to("log:myKamelet1");
from("kamelet:myTemplate?name=myKamelet2&greeting=hi")
.to("log:myKamelet2");
}
}
| 1,736 |
0 | Create_ds/camel-examples/kamelet/src/main/java/org/apache/camel | Create_ds/camel-examples/kamelet/src/main/java/org/apache/camel/example/MyRouteTemplates.java | /*
* 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.example;
import org.apache.camel.builder.RouteBuilder;
/**
* Route templates using {@link RouteBuilder} which allows
* us to define a number of templates (parameterized routes)
* which we can create routes from.
*/
public class MyRouteTemplates extends RouteBuilder {
@Override
public void configure() throws Exception {
// create a route template with the given name
routeTemplate("myTemplate")
// here we define the required input parameters (can have default values)
.templateParameter("name")
.templateParameter("greeting")
.templateParameter("myPeriod", "3s")
// here comes the route in the template
// notice how we use {{name}} to refer to the template parameters
// we can also use {{propertyName}} to refer to property placeholders
.from("timer:{{name}}?period={{myPeriod}}")
.setBody(simple("{{greeting}}"))
.to("kamelet:sink");
}
}
| 1,737 |
0 | Create_ds/camel-examples/mongodb/src/test/java/org/apache/camel/example | Create_ds/camel-examples/mongodb/src/test/java/org/apache/camel/example/mongodb/MongoDBTest.java | /*
* 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.example.mongodb;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.mongodb.client.MongoClients;
import io.restassured.response.Response;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.spi.Registry;
import org.apache.camel.test.infra.mongodb.services.MongoDBService;
import org.apache.camel.test.infra.mongodb.services.MongoDBServiceFactory;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can execute CRUD operations against MongoDB.
*/
class MongoDBTest extends CamelMainTestSupport {
private static final String BASE_URI = "http://localhost:8081";
@RegisterExtension
private static final MongoDBService SERVICE = MongoDBServiceFactory.createService();
@Override
protected void bindToRegistry(Registry registry) throws Exception {
registry.bind("myDb", MongoClients.create(SERVICE.getReplicaSetUrl()));
}
@Test
void should_execute_crud_operations() throws Exception {
// Insert a Document
Response response = given()
.baseUri(BASE_URI)
.when()
.contentType("application/json")
.body("{\"text\":\"Hello from Camel\"}")
.post("/hello")
.then()
.body(matchesPattern("Document\\{\\{text=Hello from Camel, _id=(.*)}}"))
.extract()
.response();
Matcher matcher = Pattern.compile(".*_id=(.*)}}.*").matcher(response.asString());
assertTrue(matcher.find(), "The response should match the regular expression");
String id = matcher.group(1);
// Find By Id
given()
.baseUri(BASE_URI)
.when()
.queryParam("id", id)
.get("/hello")
.then()
.body(containsString(String.format("_id=%s", id)));
// Find All
given()
.baseUri(BASE_URI)
.when()
.get("/")
.then()
.body(containsString(String.format("_id=%s", id)));
}
@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.addRoutesBuilder(new MongoDBFindByIDRouteBuilder());
configuration.addRoutesBuilder(new MongoDBFindAllRouteBuilder());
configuration.addRoutesBuilder(new MongoDBInsertRouteBuilder());
}
}
| 1,738 |
0 | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example/mongodb/MongoDBInsertRouteBuilder.java | /*
* 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.example.mongodb;
import org.apache.camel.builder.RouteBuilder;
public class MongoDBInsertRouteBuilder extends RouteBuilder {
@Override
public void configure() {
from("jetty:http://0.0.0.0:8081/hello?httpMethodRestrict=POST")
.log("Called insert API")
.to("mongodb:myDb?database=test&collection=test&operation=insert")
.setBody(simple("${body}"));
}
}
| 1,739 |
0 | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example/mongodb/Application.java | /*
* 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.example.mongodb;
import com.mongodb.client.MongoClients;
import org.apache.camel.main.Main;
public final class Application {
private Main main;
private Application() {
// noop
}
public static void main(String[] args) throws Exception {
Application app = new Application();
app.start();
}
private void start() throws Exception {
main = new Main();
// bind connectionBean used by the component
main.bind("myDb", MongoClients.create("mongodb://localhost"));
main.configure().addRoutesBuilder(new MongoDBFindByIDRouteBuilder());
main.configure().addRoutesBuilder(new MongoDBFindAllRouteBuilder());
main.configure().addRoutesBuilder(new MongoDBInsertRouteBuilder());
System.out.println("Starting Camel. Use CTRL + C to terminate the process.\n");
main.run();
}
}
| 1,740 |
0 | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example/mongodb/MongoDBFindByIDRouteBuilder.java | /*
* 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.example.mongodb;
import org.apache.camel.builder.RouteBuilder;
import org.bson.types.ObjectId;
public class MongoDBFindByIDRouteBuilder extends RouteBuilder {
@Override
public void configure() {
from("jetty:http://0.0.0.0:8081/hello?httpMethodRestrict=GET")
.log("Called findById API")
.setBody(header("id"))
.convertBodyTo(ObjectId.class)
.to("mongodb:myDb?database=test&collection=test&operation=findById")
.setBody(simple("${body}"));
}
}
| 1,741 |
0 | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example | Create_ds/camel-examples/mongodb/src/main/java/org/apache/camel/example/mongodb/MongoDBFindAllRouteBuilder.java | /*
* 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.example.mongodb;
import org.apache.camel.builder.RouteBuilder;
public class MongoDBFindAllRouteBuilder extends RouteBuilder {
@Override
public void configure() {
from("jetty:http://0.0.0.0:8081/?httpMethodRestrict=GET")
.log("Called findAll API")
.to("mongodb:myDb?database=test&collection=test&operation=findAll")
.setBody(simple("${body}"));
}
}
| 1,742 |
0 | Create_ds/camel-examples/jdbc/src/test/java/org/apache/camel/example | Create_ds/camel-examples/jdbc/src/test/java/org/apache/camel/example/jdbc/JdbcTest.java | /*
* 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.example.jdbc;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test allowing to check that the CRUD operations can be executed thanks to the Camel jdbc component.
*/
@CamelSpringTest
@ContextConfiguration("/META-INF/spring/camel-context.xml")
class JdbcTest {
@Autowired
ModelCamelContext context;
@Test
void should_execute_crud_operations() {
NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(10).wereSentTo("log:updateDone").create();
assertTrue(
notify.matches(30, TimeUnit.SECONDS), "10 messages should be completed"
);
}
}
| 1,743 |
0 | Create_ds/camel-examples/jdbc/src/main/java/org/apache/camel/example | Create_ds/camel-examples/jdbc/src/main/java/org/apache/camel/example/jdbc/RecordProcessor.java | /*
* 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.example.jdbc;
import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Just a demo bean to show we are ready to process each record polled from the
* database.
*/
public class RecordProcessor implements Processor {
static Logger log = LoggerFactory.getLogger(RecordProcessor.class);
@Override
public void process(Exchange msg) {
log.trace("Processing msg {}", msg);
Map<String, Object> record = msg.getIn().getBody(Map.class);
log.info("Processing record {}", record);
// Do something useful with this record.
}
}
| 1,744 |
0 | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example/bigxml/TestUtils.java | /*
* 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.example.bigxml;
import java.io.File;
import java.io.FileOutputStream;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class TestUtils {
private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
private static final String BASEPATH = System.getProperty("user.dir") + "/target/data";
private static final int NUM_RECORDS = 40000;
private static final int MAX_WAIT_TIME = 5000;
private TestUtils() {
}
public static String getBasePath() {
return BASEPATH;
}
public static int getNumOfRecords() {
return NUM_RECORDS;
}
public static int getMaxWaitTime() {
return MAX_WAIT_TIME;
}
public static void buildTestXml() throws Exception {
new File(BASEPATH).mkdir();
File f = new File(BASEPATH + "/test.xml");
if (!f.exists()) {
LOG.info("Building test XML file...");
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xof.createXMLStreamWriter(new FileOutputStream(f), "UTF-8");
try {
xsw.writeStartDocument("UTF-8", "1.0");
xsw.writeStartElement("records");
xsw.writeAttribute("xmlns", "http://fvaleri.it/records");
for (int i = 0; i < NUM_RECORDS; i++) {
xsw.writeStartElement("record");
xsw.writeStartElement("key");
xsw.writeCharacters("" + i);
xsw.writeEndElement();
xsw.writeStartElement("value");
xsw.writeCharacters("The quick brown fox jumps over the lazy dog");
xsw.writeEndElement();
xsw.writeEndElement();
}
xsw.writeEndElement();
xsw.writeEndDocument();
} finally {
LOG.info("Test XML file ready (size: {} kB)", f.length() / 1024);
xsw.flush();
xsw.close();
}
}
}
}
| 1,745 |
0 | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example/bigxml/XmlTokenizerTest.java | /*
* 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.example.bigxml;
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertTrue;
class XmlTokenizerTest extends CamelTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(XmlTokenizerTest.class);
@BeforeAll
public static void beforeClass() throws Exception {
TestUtils.buildTestXml();
}
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
ctx.disableJMX();
return ctx;
}
@Override
protected int getShutdownTimeout() {
return 300;
}
@Test
void test() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(TestUtils.getNumOfRecords()).create();
boolean matches = notify.matches(TestUtils.getMaxWaitTime(), TimeUnit.MILLISECONDS);
LOG.info("Processed XML file with {} records", TestUtils.getNumOfRecords());
assertTrue(matches, "Test completed");
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:" + TestUtils.getBasePath() + "?readLock=changed&noop=true")
.split(body().tokenizeXML("record", "records")).streaming().stopOnException()
.log(LoggingLevel.TRACE, "org.apache.camel.example.bigxml", "${body}")
.to("log:org.apache.camel.example.bigxml?level=DEBUG&groupInterval=100&groupDelay=100&groupActiveOnly=false")
.end();
}
};
}
}
| 1,746 |
0 | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example/bigxml/Record.java | /*
* 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.example.bigxml;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "record", propOrder = { "key", "value" })
public class Record {
@XmlElement(required = true)
protected String key;
@XmlElement(required = true)
protected String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "{key='" + getKey()
+ "', value='" + getValue() + "'}";
}
}
| 1,747 |
0 | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example | Create_ds/camel-examples/bigxml-split/src/test/java/org/apache/camel/example/bigxml/StaxTokenizerTest.java | /*
* 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.example.bigxml;
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.camel.component.stax.StAXBuilder.stax;
import static org.junit.jupiter.api.Assertions.assertTrue;
class StaxTokenizerTest extends CamelTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(StaxTokenizerTest.class);
@BeforeAll
public static void beforeClass() throws Exception {
TestUtils.buildTestXml();
}
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
ctx.disableJMX();
return ctx;
}
@Override
protected int getShutdownTimeout() {
return 300;
}
@Test
void test() throws Exception {
NotifyBuilder notify = new NotifyBuilder(context).whenDone(TestUtils.getNumOfRecords()).create();
boolean matches = notify.matches(TestUtils.getMaxWaitTime(), TimeUnit.MILLISECONDS);
LOG.info("Processed XML file with {} records", TestUtils.getNumOfRecords());
assertTrue(matches, "Test completed");
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:" + TestUtils.getBasePath() + "?readLock=changed&noop=true")
.split(stax(Record.class)).streaming().stopOnException()
.log(LoggingLevel.TRACE, "org.apache.camel.example.bigxml", "${body}")
.to("log:org.apache.camel.example.bigxml?level=DEBUG&groupInterval=100&groupDelay=100&groupActiveOnly=false")
.end();
}
};
}
}
| 1,748 |
0 | Create_ds/camel-examples/spring-xquery/src/test/java/org/apache/camel | Create_ds/camel-examples/spring-xquery/src/test/java/org/apache/camel/example/SpringXQueryTest.java | /*
* 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.example;
import org.apache.camel.EndpointInject;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringTest;
import org.apache.camel.test.spring.junit5.MockEndpoints;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ContextConfiguration;
/**
* A unit test allowing to check that Camel can transform messages using XQuery.
*/
@CamelSpringTest
@ContextConfiguration("/META-INF/spring/camelContext.xml")
@MockEndpoints("file:target/outputFiles")
class SpringXQueryTest {
@EndpointInject("mock:file:target/outputFiles")
MockEndpoint result;
@Test
void should_transform_messages_with_xquery() throws Exception {
result.expectedBodiesReceived("<employee id=\"james\"><name>James Strachan</name><location>London</location></employee>");
result.expectedMessageCount(1);
result.assertIsSatisfied();
}
}
| 1,749 |
0 | Create_ds/camel-examples/billboard-aggregate/src/test/java/org/apache/camel/example | Create_ds/camel-examples/billboard-aggregate/src/test/java/org/apache/camel/example/billboard/SongRecord.java | /*
* 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.example.billboard;
import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
import org.apache.camel.dataformat.bindy.annotation.DataField;
@CsvRecord(separator = ",", crlf = "UNIX")
public class SongRecord {
@DataField(pos = 1)
private int rank;
@DataField(pos = 2, trim = true)
private String song;
@DataField(pos = 3, trim = true)
private String artist;
@DataField(pos = 4)
private int year;
@DataField(pos = 5, trim = true)
private String lyrics;
@DataField(pos = 6)
private String source;
public SongRecord() {
}
public SongRecord(int rank, String song, String artist, int year, String lyrics, String source) {
this.rank = rank;
this.song = song;
this.artist = artist;
this.year = year;
this.lyrics = lyrics;
this.source = source;
}
public int getRank() {
return this.rank;
}
public void setRank(int rank) {
this.rank = rank;
}
public String getSong() {
return this.song;
}
public void setSong(String song) {
this.song = song;
}
public String getArtist() {
return this.artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public int getYear() {
return this.year;
}
public void setYear(int year) {
this.year = year;
}
public String getLyrics() {
return this.lyrics;
}
public void setLyrics(String lyrics) {
this.lyrics = lyrics;
}
public String getSource() {
return this.source;
}
public void setSource(String source) {
this.source = source;
}
@Override
public String toString() {
return "{"
+ " rank='" + getRank() + "'"
+ ", song='" + getSong() + "'"
+ ", artist='" + getArtist() + "'"
+ ", year='" + getYear() + "'"
+ ", lyrics='" + getLyrics() + "'"
+ ", source='" + getSource() + "'"
+ "}";
}
} | 1,750 |
0 | Create_ds/camel-examples/billboard-aggregate/src/test/java/org/apache/camel/example | Create_ds/camel-examples/billboard-aggregate/src/test/java/org/apache/camel/example/billboard/BillboardAggrTest.java | /*
* 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.example.billboard;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import org.apache.camel.AggregationStrategy;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.engine.PooledExchangeFactory;
import org.apache.camel.model.dataformat.BindyType;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class BillboardAggrTest extends CamelTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(BillboardAggrTest.class);
private static final String BASE_PATH = System.getProperty("user.dir") + "/src/test/data";
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext ctx = super.createCamelContext();
ctx.getCamelContextExtension().setExchangeFactory(new PooledExchangeFactory());
ctx.getCamelContextExtension().getExchangeFactory().setStatisticsEnabled(true);
ctx.disableJMX();
return ctx;
}
@Test
public void test() throws Exception {
MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
mock.assertIsSatisfied();
Map<String, Integer> top20 = ((MyAggregationStrategy)
mock.getReceivedExchanges().get(0).getIn().getHeader("myAggregation")).getTop20Artists();
top20.forEach((k, v) -> LOG.info("{}, {}", k, v));
assertEquals(20, top20.size());
assertEquals(35, (int) top20.get("madonna"));
assertEquals(26, (int) top20.get("elton john"));
assertEquals(17, (int) top20.get("the beatles"));
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:" + BASE_PATH + "?noop=true&idempotent=true")
.split(body().tokenize("\n")).streaming().parallelProcessing()
// skip first line with headers
.choice().when(simple("${exchangeProperty.CamelSplitIndex} > 0"))
.doTry()
.unmarshal().bindy(BindyType.Csv, SongRecord.class)
.to("seda:aggregate")
.doCatch(Exception.class)
// malformed record trace
.setBody(simple("${exchangeProperty.CamelSplitIndex}:${body}"))
.transform(body().append("\n"))
.to("file:" + BASE_PATH + "?fileName=waste.log&fileExist=append")
.end();
from("seda:aggregate?concurrentConsumers=10")
.bean(MyAggregationStrategy.class, "setArtistHeader")
.aggregate(new MyAggregationStrategy()).header("artist")
.completionPredicate(header("CamelSplitComplete").isEqualTo(true))
.to("mock:result");
}
};
}
public static class MyAggregationStrategy implements AggregationStrategy {
private static Map<String, Integer> map = new ConcurrentHashMap<>();
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Message newIn = newExchange.getIn();
String artist = (String) newIn.getHeader("artist");
if (map.containsKey(artist)) {
map.put(artist, map.get(artist) + 1);
} else {
map.put(artist, 1);
}
newIn.setHeader("myAggregation", this);
return newExchange;
}
public void setArtistHeader(Exchange exchange, SongRecord song) {
exchange.getMessage().setHeader("artist", song.getArtist());
}
public Map<String, Integer> getTop20Artists() {
return map.entrySet()
.stream()
.sorted(Map.Entry.<String, Integer>comparingByValue().reversed())
.limit(20)
.collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}
}
}
| 1,751 |
0 | Create_ds/camel-examples/routetemplate/src/test/java/org/apache/camel | Create_ds/camel-examples/routetemplate/src/test/java/org/apache/camel/example/RouteTemplateTest.java | /*
* 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.example;
import java.util.concurrent.TimeUnit;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel supports parameterized routes.
*/
class RouteTemplateTest extends CamelMainTestSupport {
@Test
void should_support_parameterized_routes() {
NotifyBuilder notify = new NotifyBuilder(context).from("timer:*").whenCompleted(2).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "2 messages should be completed"
);
}
@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.addRoutesBuilder(MyRouteTemplates.class);
}
}
| 1,752 |
0 | Create_ds/camel-examples/routetemplate/src/main/java/org/apache/camel | Create_ds/camel-examples/routetemplate/src/main/java/org/apache/camel/example/MyApplication.java | /*
* 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.example;
import org.apache.camel.main.Main;
/**
* Main class that boots up the Camel application
*/
public final class MyApplication {
private MyApplication() {
}
public static void main(String[] args) throws Exception {
// use Camels Main class
Main main = new Main();
// and add route templates via routes builder
main.configure().addRoutesBuilder(MyRouteTemplates.class);
// add configuration class which set up the routes from the route templates
// to configure route templates we can use java code as below from a template builder class,
// gives more power as its java code.
// or we can configure as well from application.properties,
// less power as its key value pair properties
// and you can also use both java and properties together
// in this example we use properties by default and have disabled java
// main.configure().addRoutesBuilder(MyTemplateBuilder.class);
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
main.run(args);
}
}
| 1,753 |
0 | Create_ds/camel-examples/routetemplate/src/main/java/org/apache/camel | Create_ds/camel-examples/routetemplate/src/main/java/org/apache/camel/example/MyTemplateBuilder.java | /*
* 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.example;
import org.apache.camel.builder.RouteBuilder;
public class MyTemplateBuilder extends RouteBuilder {
/**
* Configure and adds routes from route templates.
*/
public void configure() {
// create two routes from the template
templatedRoute("myTemplate")
.parameter("name", "one")
.parameter("greeting", "Hello");
templatedRoute("myTemplate")
.parameter("name", "deux")
.parameter("greeting", "Bonjour")
.parameter("myPeriod", "5s");
}
}
| 1,754 |
0 | Create_ds/camel-examples/routetemplate/src/main/java/org/apache/camel | Create_ds/camel-examples/routetemplate/src/main/java/org/apache/camel/example/MyRouteTemplates.java | /*
* 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.example;
import org.apache.camel.builder.RouteBuilder;
/**
* Route templates using {@link RouteBuilder} which allows
* us to define a number of templates (parameterized routes)
* which we can create routes from.
*/
public class MyRouteTemplates extends RouteBuilder {
@Override
public void configure() throws Exception {
// create a route template with the given name
routeTemplate("myTemplate")
// here we define the required input parameters (can have default values)
.templateParameter("name")
.templateParameter("greeting")
.templateParameter("myPeriod", "3s")
// here comes the route in the template
// notice how we use {{name}} to refer to the template parameters
// we can also use {{propertyName}} to refer to property placeholders
.from("timer:{{name}}?period={{myPeriod}}")
.setBody(simple("{{greeting}} {{name}}"))
.log("${body}");
}
}
| 1,755 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/test/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/test/java/org/apache/camel/example/cafe/CafeRouteBuilderTest.java | /*
* 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.example.cafe;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.example.cafe.stuff.Barista;
import org.apache.camel.example.cafe.stuff.CafeAggregationStrategy;
import org.apache.camel.example.cafe.stuff.OrderSplitter;
import org.apache.camel.example.cafe.test.TestDrinkRouter;
import org.apache.camel.example.cafe.test.TestWaiter;
import org.apache.camel.spi.Registry;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
class CafeRouteBuilderTest extends CamelTestSupport {
protected TestWaiter waiter = new TestWaiter();
protected TestDrinkRouter driverRouter = new TestDrinkRouter();
@Override
protected void bindToRegistry(Registry registry) throws Exception {
registry.bind("drinkRouter", driverRouter);
registry.bind("orderSplitter", new OrderSplitter());
registry.bind("barista", new Barista());
registry.bind("waiter", waiter);
registry.bind("aggregatorStrategy", new CafeAggregationStrategy());
}
@Test
void testSplitter() throws InterruptedException {
MockEndpoint coldDrinks = context.getEndpoint("mock:coldDrinks", MockEndpoint.class);
MockEndpoint hotDrinks = context.getEndpoint("mock:hotDrinks", MockEndpoint.class);
Order order = new Order(1);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 2, false);
coldDrinks.expectedBodiesReceived(new OrderItem(order, DrinkType.ESPRESSO, 2, true));
hotDrinks.expectedBodiesReceived(new OrderItem(order, DrinkType.CAPPUCCINO, 2, false));
template.sendBody("direct:cafe", order);
MockEndpoint.assertIsSatisfied(context);
}
@Test
void testCafeRoute() throws Exception {
driverRouter.setTestModel(false);
List<Drink> drinks = new ArrayList<>();
Order order = new Order(2);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
drinks.add(new Drink(2, DrinkType.ESPRESSO, true, 2));
drinks.add(new Drink(2, DrinkType.CAPPUCCINO, false, 4));
drinks.add(new Drink(2, DrinkType.LATTE, false, 4));
drinks.add(new Drink(2, DrinkType.MOCHA, false, 2));
waiter.setVerfiyDrinks(drinks);
template.sendBody("direct:cafe", order);
// wait enough time to let the aggregate complete
Thread.sleep(10000);
waiter.verifyDrinks();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new CafeRouteBuilder();
}
}
| 1,756 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/test/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/test/java/org/apache/camel/example/cafe/test/TestWaiter.java | /*
* 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.example.cafe.test;
import java.util.List;
import org.apache.camel.example.cafe.Delivery;
import org.apache.camel.example.cafe.Drink;
import org.apache.camel.example.cafe.stuff.Waiter;
public class TestWaiter extends Waiter {
protected List<Drink> expectDrinks;
protected List<Drink> deliveredDrinks;
public void setVerfiyDrinks(List<Drink> drinks) {
this.expectDrinks = drinks;
}
@Override
public void deliverCafes(Delivery delivery) {
super.deliverCafes(delivery);
deliveredDrinks = delivery.getDeliveredDrinks();
}
public void verifyDrinks() {
if (deliveredDrinks == null || expectDrinks.size() != deliveredDrinks.size()) {
throw new AssertionError("Did not deliver expected number of drinks " + expectDrinks.size() + " was "
+ (deliveredDrinks != null ? deliveredDrinks.size() : "null"));
}
for (Drink drink : expectDrinks) {
if (!deliveredDrinks.contains(drink)) {
throw new AssertionError("Cannot find expected drink " + drink + " in the delivered drinks");
}
}
}
}
| 1,757 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/test/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/test/java/org/apache/camel/example/cafe/test/TestDrinkRouter.java | /*
* 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.example.cafe.test;
import org.apache.camel.example.cafe.OrderItem;
import org.apache.camel.example.cafe.stuff.DrinkRouter;
public class TestDrinkRouter extends DrinkRouter {
private boolean testModel = true;
public void setTestModel(boolean testModel) {
this.testModel = testModel;
}
@Override
public String resolveOrderItemChannel(OrderItem orderItem) {
if (testModel) {
return (orderItem.isIced()) ? "mock:coldDrinks" : "mock:hotDrinks";
} else {
return super.resolveOrderItemChannel(orderItem);
}
}
}
| 1,758 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/Drink.java | /*
* 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.example.cafe;
import org.apache.camel.util.ObjectHelper;
public class Drink {
private boolean iced;
private int shots;
private DrinkType drinkType;
private int orderNumber;
public Drink(int orderNumber, DrinkType drinkType, boolean hot, int shots) {
this.orderNumber = orderNumber;
this.drinkType = drinkType;
this.iced = hot;
this.shots = shots;
}
public int getOrderNumber() {
return orderNumber;
}
@Override
public String toString() {
return (iced ? "Iced" : "Hot") + " " + drinkType.toString() + ", " + shots + " shots.";
}
@Override
public boolean equals(Object o) {
if (o instanceof Drink) {
Drink that = (Drink)o;
return ObjectHelper.equal(this.drinkType, that.drinkType)
&& ObjectHelper.equal(this.orderNumber, that.orderNumber)
&& ObjectHelper.equal(this.iced, that.iced)
&& ObjectHelper.equal(this.shots, that.shots);
}
return false;
}
@Override
public int hashCode() {
if (iced) {
return drinkType.hashCode() + orderNumber * 1000 + shots * 100;
} else {
return drinkType.hashCode() + orderNumber * 1000 + shots * 100 + 5;
}
}
}
| 1,759 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/Order.java | /*
* 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.example.cafe;
import java.util.ArrayList;
import java.util.List;
public class Order {
private List<OrderItem> orderItems = new ArrayList<>();
private int number;
public Order(int number) {
this.number = number;
}
public void addItem(DrinkType drinkType, int shots, boolean iced) {
this.orderItems.add(new OrderItem(this, drinkType, shots, iced));
}
public int getNumber() {
return number;
}
public List<OrderItem> getItems() {
return this.orderItems;
}
}
| 1,760 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/OrderItem.java | /*
* 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.example.cafe;
import org.apache.camel.util.ObjectHelper;
public class OrderItem {
private DrinkType type;
private int shots = 1;
private boolean iced;
private final Order order;
public OrderItem(Order order, DrinkType type, int shots, boolean iced) {
this.order = order;
this.type = type;
this.shots = shots;
this.iced = iced;
}
public Order getOrder() {
return this.order;
}
public boolean isIced() {
return this.iced;
}
public int getShots() {
return shots;
}
public DrinkType getDrinkType() {
return this.type;
}
@Override
public String toString() {
return ((this.iced) ? "iced " : "hot ") + this.shots + " shot " + this.type;
}
@Override
public boolean equals(Object o) {
if (o instanceof OrderItem) {
OrderItem that = (OrderItem)o;
return ObjectHelper.equal(this.type, that.type)
&& ObjectHelper.equal(this.order.getNumber(), that.order.getNumber())
&& ObjectHelper.equal(this.iced, that.iced)
&& ObjectHelper.equal(this.shots, that.shots);
}
return false;
}
@Override
public int hashCode() {
if (iced) {
return type.hashCode() + order.getNumber() * 10000 + shots * 100;
} else {
return type.hashCode() + order.getNumber() * 10000 + shots * 100 + 5;
}
}
}
| 1,761 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/CafeRouteBuilder.java | /*
* 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.example.cafe;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.example.cafe.stuff.Barista;
import org.apache.camel.example.cafe.stuff.CafeAggregationStrategy;
import org.apache.camel.example.cafe.stuff.DrinkRouter;
import org.apache.camel.example.cafe.stuff.OrderSplitter;
import org.apache.camel.example.cafe.stuff.Waiter;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.Registry;
/**
* A simple example router from Cafe Demo.
*
* Notice how this RouteBuilder extends {@link EndpointRouteBuilder} which provides the support
* for Camel Endpoint DSL.
*/
public class CafeRouteBuilder extends EndpointRouteBuilder {
protected AtomicInteger orderId = new AtomicInteger();
public static void main(String[] args) throws Exception {
CafeRouteBuilder builder = new CafeRouteBuilder();
builder.runCafeRouteDemo();
}
protected void bindBeans(Registry registry) throws Exception {
registry.bind("drinkRouter", new DrinkRouter());
registry.bind("orderSplitter", new OrderSplitter());
registry.bind("barista", new Barista());
registry.bind("waiter", new Waiter());
registry.bind("aggregatorStrategy", new CafeAggregationStrategy());
}
public void runCafeRouteDemo() throws Exception {
// create CamelContext
CamelContext camelContext = new DefaultCamelContext();
// bind beans to the Camel
bindBeans(camelContext.getRegistry());
// add the routes
camelContext.addRoutes(this);
// add additional routes using inlined RouteBuilder
// where we can access the Camel Endpoint DSL from this class
RouteBuilder.addRoutes(camelContext, rb ->
rb.from(timer("myTimer").fixedRate(true).period(500).advanced().synchronous(false))
.delay(simple("${random(250,1000)}"))
.process(this::newOrder)
.to(direct("cafe")));
// start Camel
camelContext.start();
// just run for 10 seconds and stop
System.out.println("Running for 10 seconds and then stopping");
Thread.sleep(10000);
// stop and shutdown Camel
camelContext.stop();
}
protected void newOrder(Exchange exchange) {
Order order = new Order(orderId.incrementAndGet());
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
exchange.getIn().setBody(order);
}
//START SNIPPET: RouteConfig
@Override
public void configure() {
from(direct("cafe"))
.split().method("orderSplitter").to(direct("drink"));
from(direct("drink")).recipientList().method("drinkRouter");
from(seda("coldDrinks").concurrentConsumers(2)).to(bean("barista").method("prepareColdDrink")).to(direct("deliveries"));
from(seda("hotDrinks").concurrentConsumers(3)).to(bean("barista").method("prepareHotDrink")).to(direct("deliveries"));
from(direct("deliveries"))
.aggregate(new CafeAggregationStrategy()).method("waiter", "checkOrder").completionInterval(1000L)
.to(bean("waiter").method("prepareDelivery"))
.to(bean("waiter").method("deliverCafes"));
}
//END SNIPPET: RouteConfig
}
| 1,762 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/Delivery.java | /*
* 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.example.cafe;
import java.util.List;
public class Delivery {
private static final String SEPARATOR = "-----------------------";
private List<Drink> deliveredDrinks;
private int orderNumber;
public Delivery(List<Drink> deliveredDrinks) {
assert deliveredDrinks.size() > 0;
this.deliveredDrinks = deliveredDrinks;
this.orderNumber = deliveredDrinks.get(0).getOrderNumber();
}
public int getOrderNumber() {
return orderNumber;
}
public List<Drink> getDeliveredDrinks() {
return deliveredDrinks;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder(SEPARATOR + "\n");
buffer.append("Order #").append(getOrderNumber()).append("\n");
for (Drink drink : getDeliveredDrinks()) {
buffer.append(drink).append("\n");
}
buffer.append(SEPARATOR + "\n");
return buffer.toString();
}
}
| 1,763 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/DrinkType.java | /*
* 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.example.cafe;
public enum DrinkType {
ESPRESSO,
LATTE,
CAPPUCCINO,
MOCHA
}
| 1,764 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/stuff/Waiter.java | /*
* 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.example.cafe.stuff;
import java.util.List;
import org.apache.camel.example.cafe.Delivery;
import org.apache.camel.example.cafe.Drink;
public class Waiter {
public Delivery prepareDelivery(List<Drink> drinks) {
return new Delivery(drinks);
}
public void deliverCafes(Delivery delivery) {
System.out.println(delivery);
}
public int checkOrder(Drink drink) {
return drink.getOrderNumber();
}
}
| 1,765 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/stuff/Barista.java | /*
* 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.example.cafe.stuff;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.camel.example.cafe.Drink;
import org.apache.camel.example.cafe.OrderItem;
public class Barista {
private long hotDrinkDelay = 300;
private long coldDrinkDelay = 100;
private AtomicInteger hotDrinkCounter = new AtomicInteger();
private AtomicInteger coldDrinkCounter = new AtomicInteger();
public void setHotDrinkDelay(long hotDrinkDelay) {
this.hotDrinkDelay = hotDrinkDelay;
}
public void setColdDrinkDelay(long coldDrinkDelay) {
this.coldDrinkDelay = coldDrinkDelay;
}
public Drink prepareHotDrink(OrderItem orderItem) {
try {
Thread.sleep(this.hotDrinkDelay);
System.out.println(Thread.currentThread().getName() + " prepared hot drink #"
+ hotDrinkCounter.incrementAndGet() + " for order #"
+ orderItem.getOrder().getNumber() + ": " + orderItem);
return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
}
public Drink prepareColdDrink(OrderItem orderItem) {
try {
Thread.sleep(this.coldDrinkDelay);
System.out.println(Thread.currentThread().getName() + " prepared cold drink #"
+ coldDrinkCounter.incrementAndGet() + " for order #"
+ orderItem.getOrder().getNumber() + ": " + orderItem);
return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
}
}
| 1,766 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/stuff/CafeAggregationStrategy.java | /*
* 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.example.cafe.stuff;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.AggregationStrategy;
import org.apache.camel.Exchange;
import org.apache.camel.example.cafe.Drink;
public class CafeAggregationStrategy implements AggregationStrategy {
@Override
@SuppressWarnings("unchecked")
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
List<Drink> drinks;
if (oldExchange == null) {
drinks = new ArrayList<>();
} else {
drinks = (List<Drink>) oldExchange.getIn().getBody();
}
drinks.add(newExchange.getIn().getBody(Drink.class));
newExchange.getIn().setBody(drinks);
return newExchange;
}
}
| 1,767 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/stuff/DrinkRouter.java | /*
* 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.example.cafe.stuff;
import org.apache.camel.example.cafe.OrderItem;
public class DrinkRouter {
public String resolveOrderItemChannel(OrderItem orderItem) {
return (orderItem.isIced()) ? "seda:coldDrinks" : "seda:hotDrinks";
}
}
| 1,768 |
0 | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe-endpointdsl/src/main/java/org/apache/camel/example/cafe/stuff/OrderSplitter.java | /*
* 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.example.cafe.stuff;
import java.util.List;
import org.apache.camel.example.cafe.Order;
import org.apache.camel.example.cafe.OrderItem;
public class OrderSplitter {
public List<OrderItem> split(Order order) {
return order.getItems();
}
}
| 1,769 |
0 | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example/cafe/CafeRouteSpringTest.java | /*
* 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.example.cafe;
import org.apache.camel.CamelContext;
import org.apache.camel.example.cafe.test.TestDrinkRouter;
import org.apache.camel.example.cafe.test.TestWaiter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
class CafeRouteSpringTest extends CafeRouteBuilderTest {
private AbstractApplicationContext applicationContext;
@Override
@BeforeEach
public void setUp() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("META-INF/camel-routes.xml");
setUseRouteBuilder(false);
super.setUp();
waiter = applicationContext.getBean("waiter", TestWaiter.class);
driverRouter = applicationContext.getBean("drinkRouter", TestDrinkRouter.class);
}
@Override
@AfterEach
public void tearDown() throws Exception {
super.tearDown();
if (applicationContext != null) {
applicationContext.stop();
}
}
@Override
protected CamelContext createCamelContext() throws Exception {
return applicationContext.getBean("camel", CamelContext.class);
}
}
| 1,770 |
0 | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example/cafe/CafeRouteBuilderTest.java | /*
* 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.example.cafe;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.example.cafe.stuff.Barista;
import org.apache.camel.example.cafe.stuff.CafeAggregationStrategy;
import org.apache.camel.example.cafe.stuff.OrderSplitter;
import org.apache.camel.example.cafe.test.TestDrinkRouter;
import org.apache.camel.example.cafe.test.TestWaiter;
import org.apache.camel.spi.Registry;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.Test;
import static org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied;
class CafeRouteBuilderTest extends CamelTestSupport {
protected TestWaiter waiter = new TestWaiter();
protected TestDrinkRouter driverRouter = new TestDrinkRouter();
@Override
protected void bindToRegistry(Registry registry) throws Exception {
registry.bind("drinkRouter", driverRouter);
registry.bind("orderSplitter", new OrderSplitter());
registry.bind("barista", new Barista());
registry.bind("waiter", waiter);
registry.bind("aggregatorStrategy", new CafeAggregationStrategy());
}
@Test
void testSplitter() throws InterruptedException {
MockEndpoint coldDrinks = context.getEndpoint("mock:coldDrinks", MockEndpoint.class);
MockEndpoint hotDrinks = context.getEndpoint("mock:hotDrinks", MockEndpoint.class);
Order order = new Order(1);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 2, false);
coldDrinks.expectedBodiesReceived(new OrderItem(order, DrinkType.ESPRESSO, 2, true));
hotDrinks.expectedBodiesReceived(new OrderItem(order, DrinkType.CAPPUCCINO, 2, false));
template.sendBody("direct:cafe", order);
assertIsSatisfied(context);
}
@Test
void testCafeRoute() throws Exception {
driverRouter.setTestModel(false);
List<Drink> drinks = new ArrayList<>();
Order order = new Order(2);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
drinks.add(new Drink(2, DrinkType.ESPRESSO, true, 2));
drinks.add(new Drink(2, DrinkType.CAPPUCCINO, false, 4));
drinks.add(new Drink(2, DrinkType.LATTE, false, 4));
drinks.add(new Drink(2, DrinkType.MOCHA, false, 2));
waiter.setVerfiyDrinks(drinks);
template.sendBody("direct:cafe", order);
// wait enough time to let the aggregate complete
Thread.sleep(10000);
waiter.verifyDrinks();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new CafeRouteBuilder();
}
}
| 1,771 |
0 | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example/cafe/test/TestWaiter.java | /*
* 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.example.cafe.test;
import java.util.List;
import org.apache.camel.example.cafe.Delivery;
import org.apache.camel.example.cafe.Drink;
import org.apache.camel.example.cafe.stuff.Waiter;
public class TestWaiter extends Waiter {
protected List<Drink> expectDrinks;
protected List<Drink> deliveredDrinks;
public void setVerfiyDrinks(List<Drink> drinks) {
this.expectDrinks = drinks;
}
@Override
public void deliverCafes(Delivery delivery) {
super.deliverCafes(delivery);
deliveredDrinks = delivery.getDeliveredDrinks();
}
public void verifyDrinks() {
if (deliveredDrinks == null || expectDrinks.size() != deliveredDrinks.size()) {
throw new AssertionError("Did not deliver expected number of drinks " + expectDrinks.size() + " was "
+ (deliveredDrinks != null ? deliveredDrinks.size() : "null"));
}
for (Drink drink : expectDrinks) {
if (!deliveredDrinks.contains(drink)) {
throw new AssertionError("Cannot find expected drink " + drink + " in the delivered drinks");
}
}
}
}
| 1,772 |
0 | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/test/java/org/apache/camel/example/cafe/test/TestDrinkRouter.java | /*
* 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.example.cafe.test;
import org.apache.camel.example.cafe.OrderItem;
import org.apache.camel.example.cafe.stuff.DrinkRouter;
public class TestDrinkRouter extends DrinkRouter {
private boolean testModel = true;
public void setTestModel(boolean testModel) {
this.testModel = testModel;
}
@Override
public String resolveOrderItemChannel(OrderItem orderItem) {
if (testModel) {
return (orderItem.isIced()) ? "mock:coldDrinks" : "mock:hotDrinks";
} else {
return super.resolveOrderItemChannel(orderItem);
}
}
}
| 1,773 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/Drink.java | /*
* 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.example.cafe;
import org.apache.camel.util.ObjectHelper;
public class Drink {
private boolean iced;
private int shots;
private DrinkType drinkType;
private int orderNumber;
public Drink(int orderNumber, DrinkType drinkType, boolean hot, int shots) {
this.orderNumber = orderNumber;
this.drinkType = drinkType;
this.iced = hot;
this.shots = shots;
}
public int getOrderNumber() {
return orderNumber;
}
@Override
public String toString() {
return (iced ? "Iced" : "Hot") + " " + drinkType.toString() + ", " + shots + " shots.";
}
@Override
public boolean equals(Object o) {
if (o instanceof Drink) {
Drink that = (Drink)o;
return ObjectHelper.equal(this.drinkType, that.drinkType)
&& ObjectHelper.equal(this.orderNumber, that.orderNumber)
&& ObjectHelper.equal(this.iced, that.iced)
&& ObjectHelper.equal(this.shots, that.shots);
}
return false;
}
@Override
public int hashCode() {
if (iced) {
return drinkType.hashCode() + orderNumber * 1000 + shots * 100;
} else {
return drinkType.hashCode() + orderNumber * 1000 + shots * 100 + 5;
}
}
}
| 1,774 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/Order.java | /*
* 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.example.cafe;
import java.util.ArrayList;
import java.util.List;
public class Order {
private List<OrderItem> orderItems = new ArrayList<>();
private int number;
public Order(int number) {
this.number = number;
}
public void addItem(DrinkType drinkType, int shots, boolean iced) {
this.orderItems.add(new OrderItem(this, drinkType, shots, iced));
}
public int getNumber() {
return number;
}
public List<OrderItem> getItems() {
return this.orderItems;
}
}
| 1,775 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/OrderItem.java | /*
* 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.example.cafe;
import org.apache.camel.util.ObjectHelper;
public class OrderItem {
private DrinkType type;
private int shots = 1;
private boolean iced;
private final Order order;
public OrderItem(Order order, DrinkType type, int shots, boolean iced) {
this.order = order;
this.type = type;
this.shots = shots;
this.iced = iced;
}
public Order getOrder() {
return this.order;
}
public boolean isIced() {
return this.iced;
}
public int getShots() {
return shots;
}
public DrinkType getDrinkType() {
return this.type;
}
@Override
public String toString() {
return ((this.iced) ? "iced " : "hot ") + this.shots + " shot " + this.type;
}
@Override
public boolean equals(Object o) {
if (o instanceof OrderItem) {
OrderItem that = (OrderItem)o;
return ObjectHelper.equal(this.type, that.type)
&& ObjectHelper.equal(this.order.getNumber(), that.order.getNumber())
&& ObjectHelper.equal(this.iced, that.iced)
&& ObjectHelper.equal(this.shots, that.shots);
}
return false;
}
@Override
public int hashCode() {
if (iced) {
return type.hashCode() + order.getNumber() * 10000 + shots * 100;
} else {
return type.hashCode() + order.getNumber() * 10000 + shots * 100 + 5;
}
}
}
| 1,776 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/Customer.java | /*
* 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.example.cafe;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.InitializingBean;
public class Customer extends RouteBuilder implements InitializingBean, CamelContextAware {
private CamelContext camelContext;
@Override
public CamelContext getCamelContext() {
return camelContext;
}
@Override
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
@Override
public void afterPropertiesSet() throws Exception {
if (camelContext != null) {
// setup a timer to send the cafe order
camelContext.addRoutes(this);
}
}
@Override
public void configure() throws Exception {
from("timer://myTimer?fixedRate=true&period=60000")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
Order order = new Order(2);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
exchange.getIn().setBody(order);
}
})
.to("direct:cafe");
}
}
| 1,777 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/CafeRouteBuilder.java | /*
* 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.example.cafe;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.example.cafe.stuff.Barista;
import org.apache.camel.example.cafe.stuff.CafeAggregationStrategy;
import org.apache.camel.example.cafe.stuff.DrinkRouter;
import org.apache.camel.example.cafe.stuff.OrderSplitter;
import org.apache.camel.example.cafe.stuff.Waiter;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.Registry;
/**
* A simple example router from Cafe Demo
*/
public class CafeRouteBuilder extends RouteBuilder {
public static void main(String[] args) throws Exception {
CafeRouteBuilder builder = new CafeRouteBuilder();
builder.runCafeRouteDemo();
}
protected void bindBeans(Registry registry) throws Exception {
registry.bind("drinkRouter", new DrinkRouter());
registry.bind("orderSplitter", new OrderSplitter());
registry.bind("barista", new Barista());
registry.bind("waiter", new Waiter());
registry.bind("aggregatorStrategy", new CafeAggregationStrategy());
}
public void runCafeRouteDemo() throws Exception {
// create CamelContext
DefaultCamelContext camelContext = new DefaultCamelContext();
// bind beans to the Camel
bindBeans(camelContext.getRegistry());
// add the routes
camelContext.addRoutes(this);
// start Camel
camelContext.start();
// create a producer so we can send messages to Camel
ProducerTemplate template = camelContext.createProducerTemplate();
Order order = new Order(2);
order.addItem(DrinkType.ESPRESSO, 2, true);
order.addItem(DrinkType.CAPPUCCINO, 4, false);
order.addItem(DrinkType.LATTE, 4, false);
order.addItem(DrinkType.MOCHA, 2, false);
template.sendBody("direct:cafe", order);
// wait 6 seconds and stop
Thread.sleep(6000);
camelContext.stop();
}
//START SNIPPET: RouteConfig
@Override
public void configure() {
from("direct:cafe")
.split().method("orderSplitter").to("direct:drink");
from("direct:drink").recipientList().method("drinkRouter");
from("seda:coldDrinks?concurrentConsumers=2").to("bean:barista?method=prepareColdDrink").to("direct:deliveries");
from("seda:hotDrinks?concurrentConsumers=3").to("bean:barista?method=prepareHotDrink").to("direct:deliveries");
from("direct:deliveries")
.aggregate(new CafeAggregationStrategy()).method("waiter", "checkOrder").completionTimeout(5 * 1000L)
.to("bean:waiter?method=prepareDelivery")
.to("bean:waiter?method=deliverCafes");
}
//END SNIPPET: RouteConfig
}
| 1,778 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/Delivery.java | /*
* 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.example.cafe;
import java.util.List;
public class Delivery {
private static final String SEPARATOR = "-----------------------";
private List<Drink> deliveredDrinks;
private int orderNumber;
public Delivery(List<Drink> deliveredDrinks) {
assert deliveredDrinks.size() > 0;
this.deliveredDrinks = deliveredDrinks;
this.orderNumber = deliveredDrinks.get(0).getOrderNumber();
}
public int getOrderNumber() {
return orderNumber;
}
public List<Drink> getDeliveredDrinks() {
return deliveredDrinks;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder(SEPARATOR + "\n");
buffer.append("Order #" + getOrderNumber() + "\n");
for (Drink drink : getDeliveredDrinks()) {
buffer.append(drink);
buffer.append("\n");
}
buffer.append(SEPARATOR + "\n");
return buffer.toString();
}
}
| 1,779 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/DrinkType.java | /*
* 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.example.cafe;
public enum DrinkType {
ESPRESSO,
LATTE,
CAPPUCCINO,
MOCHA
}
| 1,780 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/stuff/Waiter.java | /*
* 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.example.cafe.stuff;
import java.util.List;
import org.apache.camel.example.cafe.Delivery;
import org.apache.camel.example.cafe.Drink;
public class Waiter {
public Delivery prepareDelivery(List<Drink> drinks) {
return new Delivery(drinks);
}
public void deliverCafes(Delivery delivery) {
System.out.println(delivery);
}
public int checkOrder(Drink drink) {
return drink.getOrderNumber();
}
}
| 1,781 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/stuff/Barista.java | /*
* 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.example.cafe.stuff;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.camel.example.cafe.Drink;
import org.apache.camel.example.cafe.OrderItem;
public class Barista {
private long hotDrinkDelay = 300;
private long coldDrinkDelay = 100;
private AtomicInteger hotDrinkCounter = new AtomicInteger();
private AtomicInteger coldDrinkCounter = new AtomicInteger();
public void setHotDrinkDelay(long hotDrinkDelay) {
this.hotDrinkDelay = hotDrinkDelay;
}
public void setColdDrinkDelay(long coldDrinkDelay) {
this.coldDrinkDelay = coldDrinkDelay;
}
public Drink prepareHotDrink(OrderItem orderItem) {
try {
Thread.sleep(this.hotDrinkDelay);
System.out.println(Thread.currentThread().getName() + " prepared hot drink #"
+ hotDrinkCounter.incrementAndGet() + " for order #"
+ orderItem.getOrder().getNumber() + ": " + orderItem);
return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
}
public Drink prepareColdDrink(OrderItem orderItem) {
try {
Thread.sleep(this.coldDrinkDelay);
System.out.println(Thread.currentThread().getName() + " prepared cold drink #"
+ coldDrinkCounter.incrementAndGet() + " for order #"
+ orderItem.getOrder().getNumber() + ": " + orderItem);
return new Drink(orderItem.getOrder().getNumber(), orderItem.getDrinkType(), orderItem.isIced(),
orderItem.getShots());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
}
}
}
| 1,782 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/stuff/CafeAggregationStrategy.java | /*
* 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.example.cafe.stuff;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.AggregationStrategy;
import org.apache.camel.Exchange;
import org.apache.camel.example.cafe.Drink;
public class CafeAggregationStrategy implements AggregationStrategy {
@Override
@SuppressWarnings("unchecked")
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
List<Drink> drinks;
if (oldExchange == null) {
drinks = new ArrayList<>();
} else {
drinks = (List<Drink>) oldExchange.getIn().getBody();
}
drinks.add(newExchange.getIn().getBody(Drink.class));
newExchange.getIn().setBody(drinks);
return newExchange;
}
}
| 1,783 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/stuff/DrinkRouter.java | /*
* 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.example.cafe.stuff;
import org.apache.camel.example.cafe.OrderItem;
public class DrinkRouter {
public String resolveOrderItemChannel(OrderItem orderItem) {
return (orderItem.isIced()) ? "seda:coldDrinks" : "seda:hotDrinks";
}
}
| 1,784 |
0 | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe | Create_ds/camel-examples/cafe/src/main/java/org/apache/camel/example/cafe/stuff/OrderSplitter.java | /*
* 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.example.cafe.stuff;
import java.util.List;
import org.apache.camel.example.cafe.Order;
import org.apache.camel.example.cafe.OrderItem;
public class OrderSplitter {
public List<OrderItem> split(Order order) {
return order.getItems();
}
}
| 1,785 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/savedsearch/SplunkSavedSearchRouteBuilder.java | /*
* 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.example.splunk.savedsearch;
import org.apache.camel.builder.RouteBuilder;
public class SplunkSavedSearchRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
log.info("About to setup Splunk 'saved-search' route:Splunk Server --> log{results}");
// configure properties component
getContext().getPropertiesComponent().setLocation("classpath:application.properties");
from("splunk://savedsearch?host={{splunk.host}}&port={{splunk.port}}&delay=10000"
+ "&username={{splunk.username}}&password={{splunk.password}}&initEarliestTime=08/17/13 08:35:46:456"
+ "&savedSearch=failed_password")
.log("${body}");
}
}
| 1,786 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/savedsearch/SplunkSavedSearchClient.java | /*
* 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.example.splunk.savedsearch;
import org.apache.camel.main.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class SplunkSavedSearchClient {
private static final Logger LOG = LoggerFactory.getLogger(SplunkSavedSearchClient.class);
private SplunkSavedSearchClient() {
}
public static void main(String[] args) throws Exception {
LOG.info("About to run splunk-camel integration...");
Main main = new Main(SplunkSavedSearchClient.class);
main.run();
}
}
| 1,787 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/search/SplunkSearchRouteBuilder.java | /*
* 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.example.splunk.search;
import org.apache.camel.builder.RouteBuilder;
public class SplunkSearchRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
log.info("About to setup Splunk search route: Splunk Server --> log{results}");
// configure properties component
getContext().getPropertiesComponent().setLocation("classpath:application.properties");
from("splunk://normal?host={{splunk.host}}&port={{splunk.port}}&delay=10000"
+ "&username={{splunk.username}}&password={{splunk.password}}&initEarliestTime=08/17/13 08:35:46:456"
+ "&sourceType=access_combined_wcookie&search=search Code=D | head 5")
.log("${body}");
}
}
| 1,788 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/search/SplunkSearchClient.java | /*
* 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.example.splunk.search;
import org.apache.camel.main.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class SplunkSearchClient {
private static final Logger LOG = LoggerFactory.getLogger(SplunkSearchClient.class);
private SplunkSearchClient() {
}
public static void main(String[] args) throws Exception {
LOG.info("About to run splunk-camel integration...");
Main main = new Main(SplunkSearchClient.class);
main.run();
}
}
| 1,789 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/publish/SplunkPublishEventRouteBuilder.java | /*
* 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.example.splunk.publish;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.splunk.event.SplunkEvent;
public class SplunkPublishEventRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
log.info("About to start route: direct --> Splunk Server");
// configure properties component
getContext().getPropertiesComponent().setLocation("classpath:application.properties");
from("direct:start")
.convertBodyTo(SplunkEvent.class)
.to("splunk://submit?host={{splunk.host}}&port={{splunk.port}}"
+ "&username={{splunk.username}}&password={{splunk.password}}&sourceType=secure&source=myAppName");
}
}
| 1,790 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/publish/SplunkPublishEventClient.java | /*
* 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.example.splunk.publish;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class SplunkPublishEventClient {
private static final Logger LOG = LoggerFactory.getLogger(SplunkPublishEventClient.class);
private SplunkPublishEventClient() {
}
public static void main(String[] args) throws Exception {
LOG.info("About to run splunk-camel integration...");
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new SplunkPublishEventRouteBuilder());
ProducerTemplate eventProducer = camelContext.createProducerTemplate();
camelContext.start();
eventProducer.request("direct:start", new SplunkEventProcessor());
LOG.info("Successfully published event to Splunk.");
camelContext.stop();
}
}
| 1,791 |
0 | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk | Create_ds/camel-examples/splunk/src/main/java/org/apache/camel/example/splunk/publish/SplunkEventProcessor.java | /*
* 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.example.splunk.publish;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.splunk.event.SplunkEvent;
public class SplunkEventProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
SplunkEvent splunkEvent = new SplunkEvent();
splunkEvent.addPair("ERRORKEY", "AVUA123");
splunkEvent.addPair("ERRORMSG", "Service ABC Failed");
splunkEvent.addPair("ERRORDESC", "BusinessException: Username and password don't match");
splunkEvent.addPair(SplunkEvent.COMMON_START_TIME, "Thu Aug 15 2014 00:15:06");
exchange.getIn().setBody(splunkEvent, SplunkEvent.class);
}
}
| 1,792 |
0 | Create_ds/camel-examples/kafka/src/test/java/org/apache/camel/example | Create_ds/camel-examples/kafka/src/test/java/org/apache/camel/example/kafka/KafkaTest.java | /*
* 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.example.kafka;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.test.infra.kafka.services.KafkaService;
import org.apache.camel.test.infra.kafka.services.KafkaServiceFactory;
import org.apache.camel.test.junit5.CamelTestSupport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static org.apache.camel.example.kafka.MessagePublisherClient.setUpKafkaComponent;
import static org.apache.camel.util.PropertiesHelper.asProperties;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can produce and consume messages to / from a Kafka broker.
*/
class KafkaTest extends CamelTestSupport {
@RegisterExtension
private static final KafkaService SERVICE = KafkaServiceFactory.createService();
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
// Set the location of the configuration
camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
// Override the host and port of the broker
camelContext.getPropertiesComponent().setOverrideProperties(
asProperties(
"kafka.brokers", SERVICE.getBootstrapServers()
)
);
setUpKafkaComponent(camelContext);
return camelContext;
}
@BeforeEach
public void setUp() throws Exception {
// Replace the from endpoint to send messages easily
replaceRouteFromWith("input", "direct:in");
super.setUp();
}
@Test
void should_exchange_messages_with_a_kafka_broker() throws Exception {
String message = UUID.randomUUID().toString();
template.sendBody("direct:in", message);
NotifyBuilder notify = new NotifyBuilder(context).fromRoute("FromKafka")
.whenCompleted(1).whenBodiesReceived(message).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
);
}
@Override
protected RoutesBuilder[] createRouteBuilders() {
return new RoutesBuilder[]{
MessageConsumerClient.createRouteBuilder(), MessagePublisherClient.createRouteBuilder()
};
}
}
| 1,793 |
0 | Create_ds/camel-examples/kafka/src/main/java/org/apache/camel/example | Create_ds/camel-examples/kafka/src/main/java/org/apache/camel/example/kafka/StringPartitioner.java | /*
* 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.example.kafka;
import java.util.Map;
import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;
public class StringPartitioner implements Partitioner {
public StringPartitioner() {
// noop
}
@Override
public void configure(Map<String, ?> configs) {
// noop
}
@Override
public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
int partId = 0;
if (key instanceof String) {
String sKey = (String) key;
int len = sKey.length();
// This will return either 1 or zero
partId = len % 2;
}
return partId;
}
@Override
public void close() {
// noop
}
}
| 1,794 |
0 | Create_ds/camel-examples/kafka/src/main/java/org/apache/camel/example | Create_ds/camel-examples/kafka/src/main/java/org/apache/camel/example/kafka/MessagePublisherClient.java | /*
* 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.example.kafka;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.builder.component.ComponentsBuilderFactory;
import org.apache.camel.component.kafka.KafkaConstants;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class MessagePublisherClient {
private static final Logger LOG = LoggerFactory.getLogger(MessagePublisherClient.class);
public static final String DIRECT_KAFKA_START = "direct:kafkaStart";
public static final String DIRECT_KAFKA_START_WITH_PARTITIONER = "direct:kafkaStartWithPartitioner";
public static final String HEADERS = "${headers}";
private MessagePublisherClient() { }
public static void main(String[] args) throws Exception {
LOG.info("About to run Kafka-camel integration...");
String testKafkaMessage = "Test Message from MessagePublisherClient " + Calendar.getInstance().getTime();
try (CamelContext camelContext = new DefaultCamelContext()) {
// Set the location of the configuration
camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
// Set up the Kafka component
setUpKafkaComponent(camelContext);
// Add route to send messages to Kafka
camelContext.addRoutes(createRouteBuilder());
try (ProducerTemplate producerTemplate = camelContext.createProducerTemplate()) {
camelContext.start();
Map<String, Object> headers = new HashMap<>();
headers.put(KafkaConstants.PARTITION_KEY, 0);
headers.put(KafkaConstants.KEY, "1");
producerTemplate.sendBodyAndHeaders(DIRECT_KAFKA_START, testKafkaMessage, headers);
// Send with topicName in header
testKafkaMessage = "TOPIC " + testKafkaMessage;
headers.put(KafkaConstants.KEY, "2");
headers.put(KafkaConstants.TOPIC, "TestLog");
producerTemplate.sendBodyAndHeaders("direct:kafkaStartNoTopic", testKafkaMessage, headers);
testKafkaMessage = "PART 0 : " + testKafkaMessage;
Map<String, Object> newHeader = new HashMap<>();
newHeader.put(KafkaConstants.KEY, "AB"); // This should go to partition 0
producerTemplate.sendBodyAndHeaders(DIRECT_KAFKA_START_WITH_PARTITIONER, testKafkaMessage, newHeader);
testKafkaMessage = "PART 1 : " + testKafkaMessage;
newHeader.put(KafkaConstants.KEY, "ABC"); // This should go to partition 1
producerTemplate.sendBodyAndHeaders(DIRECT_KAFKA_START_WITH_PARTITIONER, testKafkaMessage, newHeader);
}
LOG.info("Successfully published event to Kafka.");
System.out.println("Enter text on the line below : [Press Ctrl-C to exit.] ");
Thread.sleep(5L * 60 * 1000);
}
}
static RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(DIRECT_KAFKA_START).routeId("DirectToKafka")
.to("kafka:{{producer.topic}}").log(HEADERS);
// Topic can be set in header as well.
from("direct:kafkaStartNoTopic").routeId("kafkaStartNoTopic")
.to("kafka:dummy")
.log(HEADERS);
// Use custom partitioner based on the key.
from(DIRECT_KAFKA_START_WITH_PARTITIONER).routeId("kafkaStartWithPartitioner")
.to("kafka:{{producer.topic}}?partitioner={{producer.partitioner}}")
.log(HEADERS);
// Takes input from the command line.
from("stream:in").id("input").setHeader(KafkaConstants.PARTITION_KEY, simple("0"))
.setHeader(KafkaConstants.KEY, simple("1")).to(DIRECT_KAFKA_START);
}
};
}
static void setUpKafkaComponent(CamelContext camelContext) {
// setup kafka component with the brokers
ComponentsBuilderFactory.kafka()
.brokers("{{kafka.brokers}}")
.register(camelContext, "kafka");
}
}
| 1,795 |
0 | Create_ds/camel-examples/kafka/src/main/java/org/apache/camel/example | Create_ds/camel-examples/kafka/src/main/java/org/apache/camel/example/kafka/MessageConsumerClient.java | /*
* 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.example.kafka;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.camel.example.kafka.MessagePublisherClient.setUpKafkaComponent;
public final class MessageConsumerClient {
private static final Logger LOG = LoggerFactory.getLogger(MessageConsumerClient.class);
private MessageConsumerClient() {
}
public static void main(String[] args) throws Exception {
LOG.info("About to run Kafka-camel integration...");
try (CamelContext camelContext = new DefaultCamelContext()) {
LOG.info("About to start route: Kafka Server -> Log ");
// Set the location of the configuration
camelContext.getPropertiesComponent().setLocation("classpath:application.properties");
// Set up the Kafka component
setUpKafkaComponent(camelContext);
// Add route to send messages to Kafka
camelContext.addRoutes(createRouteBuilder());
camelContext.start();
// let it run for 5 minutes before shutting down
Thread.sleep(5L * 60 * 1000);
}
}
static RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("kafka:{{consumer.topic}}"
+ "?maxPollRecords={{consumer.maxPollRecords}}"
+ "&consumersCount={{consumer.consumersCount}}"
+ "&seekTo={{consumer.seekTo}}"
+ "&groupId={{consumer.group}}")
.routeId("FromKafka")
.log("${body}");
}
};
}
}
| 1,796 |
0 | Create_ds/camel-examples/kamelet-main/src/test/java/org/apache/camel | Create_ds/camel-examples/kamelet-main/src/test/java/org/apache/camel/example/KameletMainTest.java | /*
* 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.example;
import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.component.kamelet.KameletComponent;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* A unit test checking that Camel can use a simple Kamelet from the catalog.
*/
class KameletMainTest extends CamelMainTestSupport {
@Test
void should_use_a_simple_kamelet_from_catalog() {
NotifyBuilder notify = new NotifyBuilder(context).whenCompleted(1).create();
assertTrue(
notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
);
}
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
KameletComponent component = camelContext.getComponent("kamelet", KameletComponent.class);
// Indicates where the kamelet should be found
component.setLocation("github:apache:camel-kamelets/kamelets");
return camelContext;
}
@Override
protected void configure(MainConfigurationProperties configuration) {
configuration.withRoutesIncludePattern("camel/*");
}
}
| 1,797 |
0 | Create_ds/camel-examples/telegram/src/main/java/org/apache/camel/example | Create_ds/camel-examples/telegram/src/main/java/org/apache/camel/example/telegram/TelegramExamplesRunner.java | /*
* 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.example.telegram;
import org.apache.camel.CamelContext;
import org.apache.camel.StartupListener;
import org.apache.camel.example.telegram.usage.GetUpdatesUsage;
import org.apache.camel.example.telegram.usage.LiveLocationUsage;
import org.apache.camel.example.telegram.usage.SendMessageUsage;
import org.apache.camel.example.telegram.usage.SendVenueUsage;
public class TelegramExamplesRunner implements StartupListener {
@Override
public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
System.out.println("Camel is started. Ready to run examples!");
// Methods usage examples
new SendMessageUsage().run(context);
new LiveLocationUsage().run(context);
new GetUpdatesUsage().run(context);
new SendVenueUsage().run(context);
}
}
| 1,798 |
0 | Create_ds/camel-examples/telegram/src/main/java/org/apache/camel/example | Create_ds/camel-examples/telegram/src/main/java/org/apache/camel/example/telegram/Application.java | /*
* 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.example.telegram;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
public final class Application {
public static final String AUTHORIZATION_TOKEN;
public static final String CHAT_ID;
static {
Properties properties = new Properties();
ClassLoader loader = Application.class.getClassLoader();
try (InputStream resourceStream = loader.getResourceAsStream("application.properties")) {
properties.load(resourceStream);
} catch (IOException e) {
e.printStackTrace();
}
AUTHORIZATION_TOKEN = properties.getProperty("authorizationToken");
CHAT_ID = properties.getProperty("chatId");
}
private Application() {
// noop
}
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
context.start();
context.addRoutes(new TelegramRouteBuilder());
context.addStartupListener(new TelegramExamplesRunner());
}
}
| 1,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.