GithubHelp home page GithubHelp logo

camelcookbook / camel-cookbook-examples Goto Github PK

View Code? Open in Web Editor NEW
261.0 30.0 187.0 6.75 MB

Example source code for Apache Camel Developer's Cookbook

Home Page: http://www.packtpub.com/apache-camel-developers-cookbook/book

License: Apache License 2.0

Java 98.78% XSLT 0.21% Shell 0.59% Batchfile 0.42%
apache-camel packtpub integration examples

camel-cookbook-examples's Introduction

Apache Camel Developer's Cookbook, 2nd Edition Samples

Build Status Stories in Ready

This project contains the sample code for the Apache Camel Developer's Cookbook, 2nd Edition (Packt Publishing, TBD 2017) by Scott Cranton, Jakub Korab, and Christian Posta. The latest version of this code is available on GitHub.

This project is up to date with Apache Camel 2.20.0.

All of the examples are driven through JUnit tests, and are collectively structured as a set of Apache Maven projects. To execute them, you will need a copy of the Java 8 JDK and an Apache Maven 3 installation. Maven will download all of the appropriate project dependencies.

In order to execute all the tests, all you need to do is run:

$ mvn clean install

camel-cookbook-examples's People

Contributors

christian-posta avatar jkorab avatar scranton avatar taidan19 avatar waffle-iron avatar willemjiang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

camel-cookbook-examples's Issues

enrich XMl format changed

Was:

  <enrich uri="direct:expander"
          strategyRef="myMerger"/>

Now:

  <enrich strategyRef="myMerger">
    <constant>direct:expander</constant>
  </enrich>

camel-cookbook-transformation/..spring/enrich-aggregator-context.xml
camel-cookbook-transformation/..spring/enrich-context.xml
camel-cookbook-transformation/..spring/enrich-xslt-context.xml

transformation/normalizer/NormalizerRouteBuilder

BindyDataFormat needs fully qualified class name. Was:

    final DataFormat bindy = new BindyCsvDataFormat("org.camelcookbook.transformation.csv.model");

now:

    final DataFormat bindy = new BindyCsvDataFormat(org.camelcookbook.transformation.csv.model.BookModel.class);

OnCompletionRouteBuilder

.when(simple("${exception} == null"))
becomes
// Since CAMEL-7707 we cannot get exception here, but onWhen still work
.when(simple("${body} contains 'complete'"))

Affects oncompletion

monitoring/managed/ManagedTest

    // setup the ManagementAgent to include the hostname
    camelContext.getManagementStrategy().getManagementAgent().setIncludeHostName(true);

Build fails on Transformation for Norwegian locale

Building with :
mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T22:58:10+02:00)
Maven home: /usr/local/Cellar/maven/3.2.3/libexec
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
Default locale: nb_NO, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac"

Tests in error:
CsvSpringTest.testCsvUnmarshal:81 » CamelExecution Exception occurred during e...
CsvSpringTest.testCsvMarshal:52 » Parse Unparseable date: "Dec-2010"
CsvTest.testCsvUnmarshal:80 » CamelExecution Exception occurred during executi...
CsvTest.testCsvMarshal:51 » Parse Unparseable date: "Dec-2010"
MyNormalizerTest.testBookModelToJaxb:40->createCsvModel:58 » Parse Unparseable...
NormalizerSpringTest.testNormalizeCsv:84 » CamelExecution Exception occurred d...
NormalizerTest.testNormalizeCsv:83 » CamelExecution Exception occurred during ...

Tests run: 47, Failures: 0, Errors: 7, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Camel Cookbook Examples ............................ SUCCESS [ 0.134 s]
[INFO] Camel Cookbook Examples :: Structuring Routes ...... SUCCESS [ 34.287 s]
[INFO] Camel Cookbook Examples :: Message Routing ......... SUCCESS [ 21.291 s]
[INFO] Camel Cookbook Examples :: Routing to your Code .... SUCCESS [ 11.594 s]
[INFO] Camel Cookbook Examples :: Transformation .......... FAILURE [ 10.429 s]
[INFO] Camel Cookbook Examples :: Splitting & Aggregating . SKIPPED
[INFO] Camel Cookbook Examples :: Parallel Processing ..... SKIPPED
[INFO] Camel Cookbook Examples :: Error Handling .......... SKIPPED
[INFO] Camel Cookbook Examples :: Transactions ............ SKIPPED
[INFO] Camel Cookbook Examples :: Testing ................. SKIPPED
[INFO] Camel Cookbook Examples :: Monitoring & Debugging .. SKIPPED
[INFO] Camel Cookbook Examples :: Security ................ SKIPPED
[INFO] Camel Cookbook Examples :: Web Services ............ SKIPPED
[INFO] Camel Cookbook Examples :: Web Services :: API ..... SKIPPED
[INFO] Camel Cookbook Examples :: Web Services :: Routes .. SKIPPED
[INFO] ------------------------------------------------------------------------

transformation/csv/CsvRouteBuilder

BindyFormat needs full class name. Was

    final DataFormat bindy = new BindyCsvDataFormat("org.camelcookbook.transformation.csv.model");

now

    final DataFormat bindy = new BindyCsvDataFormat(org.camelcookbook.transformation.csv.model.BookModel.class);

Intermittent failure on XATransactionSpringTest

Only happens when doing a full test from the project root:

Tests in error: 
 XATransactionSpringTest>CamelTestSupport.setUp:216->CamelSpringTestSupport.doPreSetup:80->CamelSpringTestSupport.doCreateApplicationContext:90->createApplicationContext:37 » BeanCreation

This does not occur when building camel-cookbook-transactions, or when running the test individually off the command line.

Problem appears to lie in com.atomikos.jms.AtomikosConnectionFactoryBean.init() method throwing AtomikosJMSException. Having trouble reproducing reliably.

Add locale to transformation/csv/CsvSpringTest

Bug appeared when running the system in a no_NO locale.

Also affect
CsvTest
transformation/normalizer/MyNormalizerTest
transformation/normalizer/NormalizerSpringTest
transformation/normalizer/NormalizerTest

transformation/normalizer/MyNormalizer

Method signature simplified. Affected code block, was:

public Bookstore bookModelToJaxb(List<Map<String, Object>> books) {
    final Bookstore bookstore = new Bookstore();

    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");

    for (Map<String, Object> bookEntry : books) {
        final Book book = new Book();
        final Book.Title title = new Book.Title();

        final BookModel bookModel = (BookModel) bookEntry.get(BookModel.class.getCanonicalName());

now

public Bookstore bookModelToJaxb(List<BookModel> books) {
    final Bookstore bookstore = new Bookstore();

    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");

    for (BookModel bookModel : books) {
        final Book book = new Book();
        final Book.Title title = new Book.Title();

Update whole class in example.

monitoring/jmx/JmxConfigureCamelApplication

    // Configure JMX settings
    final ManagementStrategy managementStrategy = context.getManagementStrategy();

/*
managementStrategy.setStatisticsLevel(ManagementStatisticsLevel.All);
managementStrategy.setLoadStatisticsEnabled(true);
*/

    // TODO: double check this is right way to get and configure Management Agent
    final ManagementAgent managementAgent = managementStrategy.getManagementAgent();
    managementAgent.setConnectorPort(1099);
    managementAgent.setServiceUrlPath("/jmxrmi/camel");
    managementAgent.setCreateConnector(false);
    managementAgent.setUsePlatformMBeanServer(true);

    // TODO: check that level Extended is same/better as ALL
    managementAgent.setStatisticsLevel(ManagementStatisticsLevel.Extended);
    managementAgent.setLoadStatisticsEnabled(true);

end()->endChoice

endChoice()
becomes
end()

DynamicOnCompletionRouteBuilder
transactions/rollback/RollbackMarkRollbackOnlyLastRouteBuilder
transactions/rollback/RollbackMarkRollbackOnlyRouteBuilder

Affects synchronizations recipe

Build broken

Hello,

I just grabbed the latest version of the code and ran a "mvn clean install" and the build is broken.
Maybe not everything is compatible with Camel 2.13?

Regards,
Jean-Marc.

Investigate useOriginalMessage and nested direct: routes

With nested direct: routes, useOriginalMessage(true) will use outer most original message versus original message in the innermost route that threw the exception. innermost original message is what is returned for seda: and other route types...

allowStreaming in ws/proxy/ProxyRouteBuilder

    from(paymentServiceProxyUri + "&dataFormat=PAYLOAD&allowStreaming=false") // here
            .id("wsProxy")
            .errorHandler(defaultErrorHandler().maximumRedeliveries(2))
        .to("log:wsProxyRequest?showAll=true&multiline=true")
        .to(paymentServiceBackendUri + "&dataFormat=PAYLOAD&allowStreaming=false") //here
        .to("log:wsProxyResponse?showAll=true&multiline=true") // was wsProxyRequest

Bindy XML change from packages to classType

Was:

  <bindy id="bookModel" type="Csv" packages="org.camelcookbook.transformation.csv.model"/>

Now:

  <bindy id="bookModel" type="Csv" classType="org.camelcookbook.transformation.csv.model.BookModel"/>

camel-cookbook-transformation/..spring/csv-context.xml
camel-cookbook-transformation/..spring/normalizer-context.xml

XPathFactory#newInstance() failed to create an XPathFactory

All tests within org/camelcookbook/security/xmlsecurity fail with similar stacktraces:

XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: jar:file:/hdd/m2/repository/net/sf/saxon/Saxon-HE/9.5.0.2/Saxon-HE-9.5.0.2.jar!/META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax

org.apache.camel.FailedToCreateRouteException: Failed to create route decrypt at: >>> Unmarshal[org.apache.camel.model.dataformat.XMLSecurityDataFormat@101cf747] <<< in route: Route(decrypt)[[From[direct:decrypt]] -> [Unmarshal[org.apac... because of Error creating bean with name 'org.apache.camel.dataformat.xmlsecurity.XMLSecurityDataFormat': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.camel.dataformat.xmlsecurity.XMLSecurityDataFormat]: Constructor threw exception; nested exception is java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: jar:file:/hdd/m2/repository/net/sf/saxon/Saxon-HE/9.5.0.2/Saxon-HE-9.5.0.2.jar!/META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1072)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:944)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3245)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2968)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:172)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2799)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2795)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2818)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2795)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2764)
at org.camelcookbook.security.xmlsecurity.SecurityAsymNamespacesSpringTest.testXmlEncryptionDecryption(SecurityAsymNamespacesSpringTest.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runners.Suite.runChild(Suite.java:127)
at org.junit.runners.Suite.runChild(Suite.java:26)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.camel.dataformat.xmlsecurity.XMLSecurityDataFormat': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.camel.dataformat.xmlsecurity.XMLSecurityDataFormat]: Constructor threw exception; nested exception is java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: jar:file:/hdd/m2/repository/net/sf/saxon/Saxon-HE/9.5.0.2/Saxon-HE-9.5.0.2.jar!/META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:275)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1139)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:342)
at org.apache.camel.spring.spi.SpringInjector.newInstance(SpringInjector.java:39)
at org.apache.camel.impl.DefaultDataFormatResolver.resolveDataFormat(DefaultDataFormatResolver.java:57)
at org.apache.camel.impl.DefaultCamelContext.resolveDataFormat(DefaultCamelContext.java:3911)
at org.apache.camel.model.DataFormatDefinition.createDataFormat(DataFormatDefinition.java:124)
at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:103)
at org.apache.camel.model.DataFormatDefinition.getDataFormat(DataFormatDefinition.java:88)
at org.apache.camel.model.UnmarshalDefinition.createProcessor(UnmarshalDefinition.java:179)
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:534)
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:495)
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:219)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1069)
... 52 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.camel.dataformat.xmlsecurity.XMLSecurityDataFormat]: Constructor threw exception; nested exception is java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: jar:file:/hdd/m2/repository/net/sf/saxon/Saxon-HE/9.5.0.2/Saxon-HE-9.5.0.2.jar!/META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:267)
... 68 more
Caused by: java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: java.util.ServiceConfigurationError: javax.xml.xpath.XPathFactory: jar:file:/hdd/m2/repository/net/sf/saxon/Saxon-HE/9.5.0.2/Saxon-HE-9.5.0.2.jar!/META-INF/services/javax.xml.xpath.XPathFactory:2: Illegal configuration-file syntax
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:102)
at org.apache.camel.builder.xml.DefaultNamespaceContext.(DefaultNamespaceContext.java:41)
at org.apache.camel.dataformat.xmlsecurity.XMLSecurityDataFormat.(XMLSecurityDataFormat.java:143)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 70 more

Re-edit idempotent consumer recipe

Something got messed up in the editing process, and the recipe looks as though it has been cut and pasted around. Could be made clearer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.