├── How-to-download:run-activemq.md ├── How-to-install-Postgres-in-Mac.md ├── How-to-install-Postgres-in-Windows.md ├── README.md ├── camel-students-help ├── .gitignore ├── camel-students-help.iml ├── camel.log ├── data │ └── output │ │ └── output.txt ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── learncamel │ │ │ │ ├── model │ │ │ │ └── Student.java │ │ │ │ ├── processor │ │ │ │ ├── ClassX.java │ │ │ │ ├── ClassY.java │ │ │ │ └── StudentProcessor.java │ │ │ │ └── route │ │ │ │ ├── StudentRoute.java │ │ │ │ └── XYRoute.java │ │ └── resources │ │ │ └── log4j.properties │ └── test │ │ └── java │ │ └── com │ │ └── learncamel │ │ └── route │ │ ├── StudentRouteTest.java │ │ └── XYRouteTest.java └── target │ ├── classes │ └── com │ │ └── learncamel │ │ ├── model │ │ └── Student.class │ │ ├── processor │ │ └── StudentProcessor.class │ │ └── route │ │ └── StudentRoute.class │ └── test-classes │ └── com │ └── learncamel │ └── route │ └── StudentRouteTest.class ├── folder-polling-camelapp ├── .gitignore ├── camel.log ├── data │ ├── input │ │ ├── file1.txt │ │ ├── file2.txt │ │ ├── file3.txt │ │ └── file3.txt.camelLock │ └── output │ │ ├── file1.txt │ │ ├── file2.txt │ │ └── file3.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── launcher │ │ │ └── AppLauncher.java │ │ │ └── route │ │ │ └── CopyFilesRoute.java │ └── resources │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ └── route │ └── CopyFilesRouteTest.java ├── learn-camel-eips ├── .gitignore ├── all │ ├── Employee.json │ ├── Index.html │ ├── System.log │ └── input.txt ├── camel.log ├── debug │ ├── Employee.json │ ├── Index.html │ ├── System.log │ └── input.txt ├── input │ ├── Employee.json │ ├── Index.html │ ├── System.log │ └── input.txt ├── output1 │ ├── Employee.json │ ├── Index.html │ ├── System.log │ └── input.txt ├── output2 │ ├── Employee.json │ ├── Index.html │ ├── System.log │ └── input.txt ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── learncamel │ │ │ │ └── eip │ │ │ │ ├── aggregator │ │ │ │ ├── AggregatorEIPRoute.java │ │ │ │ └── CustomAggregatorStrategy.java │ │ │ │ ├── contentbasesrouter │ │ │ │ └── ContentBasedRouterRoute.java │ │ │ │ ├── multicast │ │ │ │ └── MultiCastRoute.java │ │ │ │ ├── recipientlisteip │ │ │ │ ├── RecipientEIPProcessor.java │ │ │ │ └── RecipientListRoute.java │ │ │ │ ├── splitter │ │ │ │ └── SplitterEIP.java │ │ │ │ └── wiretap │ │ │ │ └── WireTapRoute.java │ │ └── resources │ │ │ └── log4j.properties │ └── test │ │ └── java │ │ └── com │ │ └── learncamel │ │ └── eip │ │ ├── aggregator │ │ └── AggregatorEIPRouteTest.java │ │ ├── contentbasedrouter │ │ └── ContentBasedRouterTest.java │ │ ├── multicast │ │ └── MultiCastRouteTest.java │ │ ├── recipientlisteip │ │ └── RecipientListRouteTest.java │ │ └── wiretap │ │ └── WireTapRouteTest.java └── xmlinput │ ├── employee1.xml │ └── employee2.xml ├── learncamel-activemq2db ├── .gitignore ├── camel.log ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── launch │ │ │ └── AppLauncher.java │ │ │ └── routes │ │ │ ├── exception │ │ │ └── ExceptionProcessor.java │ │ │ ├── jdbc │ │ │ ├── DBPostgresRoute.java │ │ │ └── InsertProcessor.java │ │ │ ├── jms │ │ │ └── JmsReadRoute.java │ │ │ └── jms2jdbc │ │ │ └── Jms2DBRoute.java │ └── resources │ │ ├── Sql-Script.sql │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ └── routes │ ├── jdbc │ └── DBPostgresRouteTest.java │ ├── jms │ └── JmsReadRouteTest.java │ └── jms2jdbc │ └── Jms2DBRouteTest.java ├── learncamel-aggregate-EIP ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── aggregator │ │ │ ├── AggregatorPredicateStrategy.java │ │ │ └── AggregatorSimpleRouteStrategy.java │ │ │ ├── domain │ │ │ └── Order.java │ │ │ ├── routes │ │ │ ├── AggregateWithCompletionPredicateRoute.java │ │ │ ├── AggregatorSimpleRoute.java │ │ │ ├── AggregatorWithCompletionTimeoutRoute.java │ │ │ └── AggregatorWithGroupedExchangeRoute.java │ │ │ └── util │ │ │ └── SampleCamelUtil.java │ └── resources │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ └── routes │ ├── AggregateWithCompletionPredicateRouteTest.java │ ├── AggregatorSimpleRouteTest.java │ ├── AggregatorWithCompletionTimeoutRouteTest.java │ └── AggregatorWithGroupedExchangeRouteTest.java ├── learncamel-boilerplate ├── .gitignore ├── learncamel-boilerplate.iml ├── pom.xml └── src │ └── main │ └── resources │ └── log4j.properties ├── learncamel-error-handling ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── bean │ │ │ └── DataModifier.java │ │ │ ├── exception │ │ │ ├── ApplicationException.java │ │ │ └── GenerateErrorResponseProcessor.java │ │ │ └── route │ │ │ ├── defaulterrorhandler │ │ │ └── DefaultErrorHandlerRoute.java │ │ │ └── onexception │ │ │ └── OnExceptionHandlerRoute.java │ └── resources │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ └── route │ ├── DefaultErrorHandlerRouteTest.java │ └── OnExceptionHandlerRouteTest.java ├── learncamel-kafka2DB ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── launch │ │ │ └── AppLauncher.java │ │ │ └── routes │ │ │ ├── exception │ │ │ └── ExceptionProcessor.java │ │ │ ├── jdbc │ │ │ ├── DBPostgresRoute.java │ │ │ └── InsertProcessor.java │ │ │ ├── kafka │ │ │ └── KafkaConsumerRoute.java │ │ │ └── kafka2jdbc │ │ │ └── Kafka2JdbcRoute.java │ └── resources │ │ ├── Sql-Script.sql │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ └── routes │ ├── jdbc │ └── DBPostgresRouteTest.java │ ├── kafka │ └── KafkaConsumerRouteTest.java │ └── kafka2jdbc │ └── Kafka2JdbcRouteTest.java ├── learncamel-rest2DB ├── .idea │ ├── compiler.xml │ ├── kotlinc.xml │ ├── libraries │ │ ├── Maven__com_googlecode_json_simple_json_simple_1_1_1.xml │ │ ├── Maven__com_sun_xml_bind_jaxb_core_2_2_11.xml │ │ ├── Maven__com_sun_xml_bind_jaxb_impl_2_2_11.xml │ │ ├── Maven__commons_codec_commons_codec_1_10.xml │ │ ├── Maven__commons_dbcp_commons_dbcp_1_4.xml │ │ ├── Maven__commons_httpclient_commons_httpclient_3_1.xml │ │ ├── Maven__commons_logging_commons_logging_1_0_4.xml │ │ ├── Maven__commons_pool_commons_pool_1_5_4.xml │ │ ├── Maven__javax_servlet_javax_servlet_api_3_1_0.xml │ │ ├── Maven__junit_junit_4_12.xml │ │ ├── Maven__org_apache_camel_camel_core_2_18_3.xml │ │ ├── Maven__org_apache_camel_camel_http_2_18_3.xml │ │ ├── Maven__org_apache_camel_camel_http_common_2_18_3.xml │ │ ├── Maven__org_apache_camel_camel_jdbc_2_10_4.xml │ │ ├── Maven__org_apache_camel_camel_sql_2_14_0.xml │ │ ├── Maven__org_apache_camel_camel_test_2_20_0_SNAPSHOT.xml │ │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ │ ├── Maven__org_postgresql_postgresql_9_4_1212.xml │ │ ├── Maven__org_slf4j_slf4j_api_1_7_10.xml │ │ ├── Maven__org_slf4j_slf4j_simple_1_7_10.xml │ │ ├── Maven__org_springframework_spring_beans_3_2_11_RELEASE.xml │ │ ├── Maven__org_springframework_spring_core_3_2_11_RELEASE.xml │ │ ├── Maven__org_springframework_spring_jdbc_3_2_11_RELEASE.xml │ │ └── Maven__org_springframework_spring_tx_3_2_11_RELEASE.xml │ ├── misc.xml │ ├── modules.xml │ ├── sqldialects.xml │ ├── uiDesigner.xml │ └── workspace.xml ├── learncamel-rest2DB.iml ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── learncamel │ │ │ │ ├── launch │ │ │ │ └── AppLauncher.java │ │ │ │ └── routes │ │ │ │ ├── excetion │ │ │ │ └── ExceptionProcessor.java │ │ │ │ ├── jdbc │ │ │ │ ├── DBPostgresRoute.java │ │ │ │ └── InsertProcessor.java │ │ │ │ ├── rest │ │ │ │ └── RestRoute.java │ │ │ │ └── rest2DB │ │ │ │ └── Rest2DBRoute.java │ │ └── resources │ │ │ ├── Sql-Script.sql │ │ │ └── log4j.properties │ └── test │ │ └── java │ │ └── com │ │ └── learncamel │ │ └── routes │ │ ├── jdbc │ │ └── DBPostgresRouteTest.java │ │ ├── rest │ │ └── RestRouteTest.java │ │ └── rest2jdbc │ │ └── Rest2DBRouteTest.java └── target │ ├── classes │ ├── Sql-Script.sql │ ├── com │ │ └── learncamel │ │ │ ├── launch │ │ │ └── AppLauncher.class │ │ │ └── routes │ │ │ ├── excetion │ │ │ └── ExceptionProcessor.class │ │ │ ├── jdbc │ │ │ ├── DBPostgresRoute.class │ │ │ └── InsertProcessor.class │ │ │ ├── rest │ │ │ └── RestRoute.class │ │ │ └── rest2DB │ │ │ └── Rest2DBRoute.class │ └── log4j.properties │ ├── dependency-jars │ ├── camel-core-2.18.3.jar │ ├── camel-http-2.18.3.jar │ ├── camel-http-common-2.18.3.jar │ ├── camel-jdbc-2.10.4.jar │ ├── camel-sql-2.14.0.jar │ ├── camel-test-2.20.0-SNAPSHOT.jar │ ├── commons-codec-1.10.jar │ ├── commons-dbcp-1.4.jar │ ├── commons-httpclient-3.1.jar │ ├── commons-logging-1.0.4.jar │ ├── commons-pool-1.5.4.jar │ ├── hamcrest-core-1.3.jar │ ├── javax.servlet-api-3.1.0.jar │ ├── jaxb-core-2.2.11.jar │ ├── jaxb-impl-2.2.11.jar │ ├── json-simple-1.1.1.jar │ ├── junit-4.12.jar │ ├── postgresql-9.4.1212.jar │ ├── slf4j-api-1.7.10.jar │ ├── slf4j-simple-1.7.10.jar │ ├── spring-beans-3.2.11.RELEASE.jar │ ├── spring-core-3.2.11.RELEASE.jar │ ├── spring-jdbc-3.2.11.RELEASE.jar │ └── spring-tx-3.2.11.RELEASE.jar │ ├── learncamel-rest2DB-1.0-SNAPSHOT.jar │ ├── maven-archiver │ └── pom.properties │ ├── maven-status │ └── maven-compiler-plugin │ │ ├── compile │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── testCompile │ │ └── default-testCompile │ │ ├── createdFiles.lst │ │ └── inputFiles.lst │ └── test-classes │ └── com │ └── learncamel │ └── routes │ ├── jdbc │ └── DBPostgresRouteTest.class │ ├── rest │ └── RestRouteTest.class │ └── rest2jdbc │ └── Rest2DBRouteTest.class ├── learncamel-simple-file ├── .gitignore ├── camel.log ├── data │ ├── anothetdestination │ │ ├── file1.txt │ │ └── file2.txt │ ├── input │ │ ├── file1.txt │ │ └── file2.txt │ ├── input1 │ │ ├── file3.txt │ │ └── file4.txt │ ├── nextoutput │ │ ├── file3.txt │ │ └── file4.txt │ └── output │ │ ├── file1.txt │ │ └── file2.txt ├── pom.xml ├── sampleOutput │ ├── output.txt │ └── output.txt.camelLock └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── direct │ │ │ ├── SampleDirectRoute.java │ │ │ └── SampleMockRoute.java │ │ │ └── file │ │ │ ├── CopyFilesCamel.java │ │ │ ├── CopyFilesCamelLogging.java │ │ │ ├── CopyFilesMultiRoute.java │ │ │ ├── CopyFilesRoute.java │ │ │ └── CopyFilesWithoutCamel.java │ └── resources │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ ├── direct │ ├── SampleDirectRouteTest.java │ └── SampleMockRouteTest.java │ └── file │ └── CopyFilesCamelTest.java ├── learncamel-transform-bindy ├── .gitignore ├── data │ ├── csv │ │ ├── input │ │ │ ├── file1.txt │ │ │ ├── file2.txt │ │ │ ├── file3.txt │ │ │ ├── file4.txt │ │ │ └── fileWithAddress.txt │ │ └── output │ │ │ ├── output.txt │ │ │ └── outputWithAddress.txt │ ├── fixedposition │ │ ├── input │ │ │ ├── FixedPositionFile-Date.txt │ │ │ ├── FixedPositionFile-Delimiter-salary.txt │ │ │ ├── FixedPositionFile-Delimiter.txt │ │ │ └── FixedPositionFile.txt │ │ └── output │ │ │ └── FixedPositionFile.txt │ ├── headerandfooter │ │ └── input │ │ │ └── samplefile │ └── keyValue │ │ ├── input │ │ └── key-value-file1.txt │ │ └── output │ │ └── key-value-file-output.txt ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── learncamel │ │ │ ├── domain │ │ │ ├── Address.java │ │ │ ├── Employee.java │ │ │ ├── EmployeeWithAddress.java │ │ │ ├── EmployeeWithFixedLength.java │ │ │ └── Student.java │ │ │ ├── processor │ │ │ └── EmployeeProcessor.java │ │ │ └── routes │ │ │ ├── csv │ │ │ ├── CSVMarshalRoute.java │ │ │ ├── CSVMarshalWithLinkRoute.java │ │ │ ├── CSVUnMarshalRoute.java │ │ │ └── CSVUnMarshalWithLinkRoute.java │ │ │ ├── fixedlength │ │ │ ├── FixedPositionMarshalRoute.java │ │ │ ├── FixedPositionUnMarshalRoute.java │ │ │ ├── FixedPositionUnMarshalRouteDate.java │ │ │ ├── FixedPositionUnMarshalRouteDelimiter.java │ │ │ └── FixedPositionUnMarshalRouteDelimiterSalary.java │ │ │ ├── headerandfooter │ │ │ └── HeaderAndFooterRoute.java │ │ │ └── keyvaluepair │ │ │ ├── KeyValueMarshalRoute.java │ │ │ └── KeyValueUnMarshalRoute.java │ └── resources │ │ └── log4j.properties │ └── test │ └── java │ └── com │ └── learncamel │ └── routes │ ├── csv │ ├── CSVMarshalRouteTest.java │ ├── CSVMarshalWithLinkRouteTest.java │ ├── CSVUnMarshalRouteTest.java │ └── CSVUnMarshalWithLinkRouteTest.java │ ├── fixedlength │ ├── FixedPositionMarshalRouteTest.java │ ├── FixedPositionUnMarshalRouteDateTest.java │ ├── FixedPositionUnMarshalRouteDelimiterSalaryTest.java │ ├── FixedPositionUnMarshalRouteDelimiterTest.java │ └── FixedPositionUnMarshalRouteTest.java │ ├── headerandfooter │ └── HeaderAndFooterRouteTest.java │ └── keyvaluepair │ ├── KeyValueMarshalRouteTest.java │ └── KeyValueUnMarshalRouteTest.java └── learncamel-transform ├── .gitignore ├── data ├── input │ └── input.txt └── output │ └── output.txt ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── learncamel │ │ ├── bean │ │ └── CamelBean.java │ │ ├── domain │ │ ├── Employee.java │ │ └── Student.java │ │ ├── processor │ │ ├── CamelDirectExampleProcessor.java │ │ ├── CamelFileExampleProcessor.java │ │ └── CustomProcessorXStream.java │ │ └── route │ │ ├── bean │ │ └── CamelModifyBeanRoute.java │ │ ├── gson │ │ ├── MarshalUsingGson.java │ │ └── UnMarshalUsingGson.java │ │ ├── process │ │ ├── CamelModifyDirectProcessorRoute.java │ │ └── CamelModifyFileProcessorRoute.java │ │ ├── transform │ │ └── CamelModifyTransformRoute.java │ │ ├── xml2json │ │ └── XML2JSONRoute.java │ │ └── xmlxstream │ │ ├── MarshalUsingXStream.java │ │ └── UnMarshalUsingXStream.java └── resources │ └── log4j.properties └── test └── java └── com └── learncamel └── route ├── CamelModifyDirectProcessorRouteTest.java ├── CamelModifyFileProcessorRouteTest.java ├── bean └── CamelModifyBeanRouteTest.java ├── gson ├── MarshalGsonTest.java └── UnMarshalUsingGsonTest.java ├── transform └── CamelModifyTransformRouteTest.java ├── xml2json └── XML2JSONRouteTest.java └── xmlxstream ├── MarshalUsingXStreamTest.java └── UnMarshalUsingXStreamTest.java /How-to-download:run-activemq.md: -------------------------------------------------------------------------------- 1 | ## Apache ActiveMQ 2 | Apache ActiveMQ is the most popular and powerful open source messaging server. 3 | 4 | Step 1: Download Active MQ. 5 | 6 | ``` 7 | http://activemq.apache.org/activemq-5145-release.html 8 | ``` 9 | 10 | Step 2: Navigate to the bin directory and run the following command. 11 | 12 | ``` 13 | ./activemq console 14 | ``` 15 | 16 | Step 3: Below link has the steps to run Active MQ in your machine. 17 | 18 | ``` 19 | http://activemq.apache.org/getting-started.html#GettingStarted-StartingActiveMQStartingActiveMQ 20 | ``` 21 | 22 | Step 4: 23 | 24 | Console URL: 25 | 26 | ``` 27 | http://127.0.0.1:8161/admin/ 28 | ``` 29 | -------------------------------------------------------------------------------- /How-to-install-Postgres-in-Mac.md: -------------------------------------------------------------------------------- 1 | # PostGresSql 2 | 3 | ## How to install PostGres? 4 | 5 | Run the below command : 6 | 7 | ``` 8 | brew install postgres 9 | 10 | ``` 11 | 12 | How to check the postgres version? 13 | 14 | ``` 15 | postgres --version 16 | ``` 17 | 18 | How to Start PostGres? 19 | 20 | ``` 21 | brew services start postgresql 22 | ``` 23 | 24 | How to Stop PostGres? 25 | 26 | ``` 27 | brew services stop postgresql 28 | 29 | ``` 30 | 31 | #### How to create a DB in Postgres via command line? 32 | 33 | https://www.postgresql.org/docs/9.1/static/app-createdb.html 34 | 35 | ``` 36 | createdb -p 5432 -h localhost -e localDB 37 | 38 | ``` 39 | 40 | ## How to connect to Postgres DB server from Terminal: 41 | 42 | ``` 43 | psql -h -U -W "sslmode=require" 44 | ``` 45 | 46 | By Default user id postgres will be created. 47 | 48 | Conmmand to connect to Localhost: 49 | 50 | ``` 51 | psql localDB localhost -U postgres 52 | ``` 53 | 54 | ## How to connect to Postgres from Intellij: 55 | 56 | Step 1: 57 | 58 | **Mac :** 59 | 60 | ``` 61 | Intellij IDEA -> Preferences -> Plugins 62 | ``` 63 | 64 | **Windows:** 65 | 66 | ``` 67 | File -> Settings-> Plugins 68 | ``` 69 | 70 | Below steps are the same for windows and Mac. 71 | Step 2: 72 | 73 | Search for **DataBase Navigator**. 74 | 75 | Step 3: 76 | 77 | Install the plugin and restart the Intellij. 78 | 79 | Step 4: 80 | 81 | There will be a **Database Navigator** in the Menu bar. 82 | 83 | Step 5: 84 | 85 | Click on **DataBase Navigator**. 86 | 87 | Click on **Open SQL Console**. 88 | -------------------------------------------------------------------------------- /How-to-install-Postgres-in-Windows.md: -------------------------------------------------------------------------------- 1 | # PostGresSql 2 | 3 | ## How to install PostGres? 4 | 5 | Download postgres from the below link. 6 | 7 | ``` 8 | https://www.enterprisedb.com/downloads/postgres-postgresql-downloads#windows 9 | ``` 10 | 11 | ## Postgres GUI client 12 | 13 | The installer will provide you the **pgAdmin** client as part of the installation. 14 | 15 | We can use this client to connect to the database. 16 | 17 | ## How to connect to Postgres from Intellij: 18 | 19 | Step 1: 20 | 21 | **Mac :** 22 | 23 | ``` 24 | Intellij IDEA -> Preferences -> Plugins 25 | ``` 26 | 27 | **Windows:** 28 | 29 | ``` 30 | File -> Settings-> Plugins 31 | ``` 32 | 33 | Below steps are the same for windows and Mac. 34 | Step 2: 35 | 36 | Search for **DataBase Navigator**. 37 | 38 | Step 3: 39 | 40 | Install the plugin and restart the Intellij. 41 | 42 | Step 4: 43 | 44 | There will be a **Database Navigator** in the Menu bar. 45 | 46 | Step 5: 47 | 48 | Click on **DataBase Navigator**. 49 | 50 | Click on **Open SQL Console**. 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ApacheCamel 2 | 3 | ## **learncamel-simple-file:** 4 | 5 | ## How to download/run ActiveMQ in your machine 6 | 7 | Please click the below link to install and run the ActiveMQ in your local. 8 | 9 | [Run ActiveMQ](https://github.com/dilipSundar/TeachApacheCamel/blob/master/How-to-download:run-activemq.md) 10 | 11 | ## How to install Postgres in your machine 12 | 13 | Postgres is an opensource DB server. 14 | 15 | **Mac:** 16 | 17 | [Run Postgres in Mac](https://github.com/dilipSundar/TeachApacheCamel/blob/master/How-to-install-Postgres-in-Mac.md) 18 | 19 | **Windows** 20 | 21 | [Run Postgres in Windows](https://github.com/dilipSundar/TeachApacheCamel/blob/master/How-to-install-Postgres-in-Windows.md) 22 | 23 | ## How to download/install/run Kafka in your machine. 24 | 25 | [Run Kafka in your machine](https://github.com/dilipSundar/TeachApacheCamel/blob/master/learncamel-kafka2DB/README.md) 26 | 27 | ## Rest Endpoint: 28 | 29 | ``` 30 | https://restcountries.eu/ 31 | ``` 32 | -------------------------------------------------------------------------------- /camel-students-help/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /camel-students-help/data/output/output.txt: -------------------------------------------------------------------------------- 1 | AB -------------------------------------------------------------------------------- /camel-students-help/src/main/java/com/learncamel/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.model; 2 | 3 | /** 4 | * Created by Dilip on 12/14/17. 5 | */ 6 | public class Student { 7 | 8 | private int id; 9 | private String name; 10 | private String phonenumber; 11 | 12 | public int getId() { 13 | return id; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "Student{" + 19 | "id=" + id + 20 | ", name='" + name + '\'' + 21 | ", phonenumber='" + phonenumber + '\'' + 22 | '}'; 23 | } 24 | 25 | public void setId(int id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getPhonenumber() { 38 | return phonenumber; 39 | } 40 | 41 | public void setPhonenumber(String phonenumber) { 42 | this.phonenumber = phonenumber; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /camel-students-help/src/main/java/com/learncamel/processor/ClassX.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 1/2/18. 7 | */ 8 | public class ClassX implements org.apache.camel.Processor { 9 | public void process(Exchange exchange) throws Exception { 10 | exchange.getIn().setBody("X"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /camel-students-help/src/main/java/com/learncamel/processor/ClassY.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 1/2/18. 7 | */ 8 | public class ClassY implements org.apache.camel.Processor { 9 | public void process(Exchange exchange) throws Exception { 10 | exchange.getIn().setBody("Y"); 11 | 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /camel-students-help/src/main/java/com/learncamel/processor/StudentProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.learncamel.model.Student; 5 | import org.apache.camel.Exchange; 6 | 7 | /** 8 | * Created by Dilip on 12/14/17. 9 | */ 10 | public class StudentProcessor implements org.apache.camel.Processor { 11 | 12 | public void process(Exchange exchange) throws Exception { 13 | 14 | 15 | 16 | Student student = (Student) exchange.getIn().getBody(); 17 | 18 | System.out.println("Student Obj is : " + student); 19 | 20 | 21 | if(student.getName().equals("Sudheer")){ 22 | //you can write your logic here 23 | }else if (student.getName().equals("sandu")){ 24 | //you can write your logic here 25 | } 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /camel-students-help/src/main/java/com/learncamel/route/StudentRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.model.Student; 4 | import com.learncamel.processor.StudentProcessor; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.component.gson.GsonDataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/14/17. 10 | */ 11 | public class StudentRoute extends RouteBuilder { 12 | 13 | 14 | public void configure() throws Exception { 15 | 16 | 17 | GsonDataFormat format = new GsonDataFormat(Student.class); 18 | 19 | /* from("direct:rest"). 20 | process(new StudentProcessor()) 21 | .to("mock:output");*/ 22 | from("direct:rest").unmarshal(format).process(new StudentProcessor()); 23 | 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /camel-students-help/src/main/java/com/learncamel/route/XYRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.processor.ClassX; 4 | import com.learncamel.processor.ClassY; 5 | import org.apache.camel.builder.RouteBuilder; 6 | 7 | /** 8 | * Created by Dilip on 1/2/18. 9 | */ 10 | public class XYRoute extends RouteBuilder { 11 | 12 | public void configure() throws Exception { 13 | 14 | from("direct:A") 15 | .log("Message is ${body}") 16 | .to("file:data/output?fileName=output.txt") 17 | .log("Message is ${body}") 18 | .process(new ClassX()) 19 | .log("Message is ${body}") 20 | .process(new ClassY()) 21 | .log("Message is ${body}"); 22 | 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /camel-students-help/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n 17 | -------------------------------------------------------------------------------- /camel-students-help/src/test/java/com/learncamel/route/StudentRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.model.Student; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.component.mock.MockEndpoint; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | /** 11 | * Created by Dilip on 12/14/17. 12 | */ 13 | public class StudentRouteTest extends CamelTestSupport { 14 | 15 | 16 | @Override 17 | protected RouteBuilder createRouteBuilder(){ 18 | return new StudentRoute(); 19 | } 20 | 21 | @Test 22 | public void testStudentRoute1() throws InterruptedException { 23 | 24 | 25 | String jsonInput = "{ \"id\":\"1\" ,\"name\":\"sudheer\",\"phonenumber\" :\"123456789\"}"; 26 | 27 | Student student = (Student) template.requestBody("direct:rest", jsonInput); 28 | 29 | assertEquals(1,student.getId()); 30 | 31 | 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /camel-students-help/src/test/java/com/learncamel/route/XYRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Dilip on 1/2/18. 12 | */ 13 | public class XYRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RoutesBuilder createRouteBuilder(){ 17 | return new XYRoute(); 18 | } 19 | 20 | 21 | @Test 22 | public void xyTest() throws InterruptedException { 23 | 24 | String input = "AB"; 25 | template.sendBody("direct:A", input); 26 | Thread.sleep(2000); 27 | File file = new File("data/output"); 28 | assertTrue(file.isDirectory()); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /camel-students-help/target/classes/com/learncamel/model/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/camel-students-help/target/classes/com/learncamel/model/Student.class -------------------------------------------------------------------------------- /camel-students-help/target/classes/com/learncamel/processor/StudentProcessor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/camel-students-help/target/classes/com/learncamel/processor/StudentProcessor.class -------------------------------------------------------------------------------- /camel-students-help/target/classes/com/learncamel/route/StudentRoute.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/camel-students-help/target/classes/com/learncamel/route/StudentRoute.class -------------------------------------------------------------------------------- /camel-students-help/target/test-classes/com/learncamel/route/StudentRouteTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/camel-students-help/target/test-classes/com/learncamel/route/StudentRouteTest.class -------------------------------------------------------------------------------- /folder-polling-camelapp/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /folder-polling-camelapp/data/input/file1.txt: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /folder-polling-camelapp/data/input/file2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/folder-polling-camelapp/data/input/file2.txt -------------------------------------------------------------------------------- /folder-polling-camelapp/data/input/file3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/folder-polling-camelapp/data/input/file3.txt -------------------------------------------------------------------------------- /folder-polling-camelapp/data/input/file3.txt.camelLock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/folder-polling-camelapp/data/input/file3.txt.camelLock -------------------------------------------------------------------------------- /folder-polling-camelapp/data/output/file1.txt: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /folder-polling-camelapp/data/output/file2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/folder-polling-camelapp/data/output/file2.txt -------------------------------------------------------------------------------- /folder-polling-camelapp/data/output/file3.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/folder-polling-camelapp/data/output/file3.txt -------------------------------------------------------------------------------- /folder-polling-camelapp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.learncamel 8 | folder-polling-camel-app 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.camel 14 | camel-core 15 | 2.18.1 16 | 17 | 18 | 19 | 20 | 21 | org.slf4j 22 | slf4j-api 23 | 1.7.12 24 | 25 | 26 | org.slf4j 27 | slf4j-log4j12 28 | 1.7.12 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.apache.camel 36 | camel-test 37 | 2.20.0-SNAPSHOT 38 | test 39 | 40 | 41 | 42 | junit 43 | junit 44 | 4.12 45 | test 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /folder-polling-camelapp/src/main/java/com/learncamel/launcher/AppLauncher.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.launcher; 2 | 3 | import com.learncamel.route.CopyFilesRoute; 4 | import org.apache.camel.main.Main; 5 | 6 | /** 7 | * Created by Dilip on 1/9/18. 8 | */ 9 | public class AppLauncher { 10 | 11 | 12 | public static void main(String[] args) throws Exception { 13 | Main main = new Main(); 14 | 15 | main.addRouteBuilder(new CopyFilesRoute()); 16 | 17 | System.out.println("Starting fo routelder polling app"); 18 | 19 | main.run(); 20 | 21 | 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /folder-polling-camelapp/src/main/java/com/learncamel/route/CopyFilesRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 1/9/18. 7 | */ 8 | public class CopyFilesRoute extends RouteBuilder { 9 | public void configure() throws Exception { 10 | from("timer:CSVReader?period=10s" ) 11 | .log("Timer Triggered") 12 | .pollEnrich("file:data/input?noop=true") 13 | .to("log:?Level=INFO&showBody=true&showHeaders=true") 14 | .to("file:data/output"); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /folder-polling-camelapp/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /folder-polling-camelapp/src/test/java/com/learncamel/route/CopyFilesRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import org.apache.camel.RoutesBuilder; 4 | import org.apache.camel.test.junit4.CamelTestSupport; 5 | import org.junit.Test; 6 | 7 | import java.io.File; 8 | 9 | /** 10 | * Created by Dilip on 1/9/18. 11 | */ 12 | public class CopyFilesRouteTest extends CamelTestSupport{ 13 | 14 | @Override 15 | public RoutesBuilder createRouteBuilder(){ 16 | return new CopyFilesRoute(); 17 | } 18 | 19 | @Test 20 | public void testFolderLoop() throws InterruptedException { 21 | 22 | Thread.sleep(3000); 23 | File file = new File("data/output"); 24 | assertTrue(file.isDirectory()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /learn-camel-eips/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /learn-camel-eips/all/Employee.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"John", 3 | "age":30, 4 | "cars":[ "Ford", "BMW", "Fiat" ] 5 | } 6 | -------------------------------------------------------------------------------- /learn-camel-eips/all/Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /learn-camel-eips/all/System.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learn-camel-eips/all/System.log -------------------------------------------------------------------------------- /learn-camel-eips/all/input.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | How are you? -------------------------------------------------------------------------------- /learn-camel-eips/debug/Employee.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"John", 3 | "age":30, 4 | "cars":[ "Ford", "BMW", "Fiat" ] 5 | } 6 | -------------------------------------------------------------------------------- /learn-camel-eips/debug/Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /learn-camel-eips/debug/System.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learn-camel-eips/debug/System.log -------------------------------------------------------------------------------- /learn-camel-eips/debug/input.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | How are you? -------------------------------------------------------------------------------- /learn-camel-eips/input/Employee.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"John", 3 | "age":30, 4 | "cars":[ "Ford", "BMW", "Fiat" ] 5 | } 6 | -------------------------------------------------------------------------------- /learn-camel-eips/input/Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /learn-camel-eips/input/System.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learn-camel-eips/input/System.log -------------------------------------------------------------------------------- /learn-camel-eips/input/input.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | How are you? -------------------------------------------------------------------------------- /learn-camel-eips/output1/Employee.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"John", 3 | "age":30, 4 | "cars":[ "Ford", "BMW", "Fiat" ] 5 | } 6 | -------------------------------------------------------------------------------- /learn-camel-eips/output1/Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /learn-camel-eips/output1/System.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learn-camel-eips/output1/System.log -------------------------------------------------------------------------------- /learn-camel-eips/output1/input.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | How are you? -------------------------------------------------------------------------------- /learn-camel-eips/output2/Employee.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"John", 3 | "age":30, 4 | "cars":[ "Ford", "BMW", "Fiat" ] 5 | } 6 | -------------------------------------------------------------------------------- /learn-camel-eips/output2/Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /learn-camel-eips/output2/System.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learn-camel-eips/output2/System.log -------------------------------------------------------------------------------- /learn-camel-eips/output2/input.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | How are you? -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/aggregator/AggregatorEIPRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.aggregator; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.apache.camel.processor.*; 5 | /** 6 | * Created by Dilip on 6/1/17. 7 | */ 8 | public class AggregatorEIPRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | from("direct:input") 13 | .log("Body : ${body} correlation id : ${header.myId}") 14 | .aggregate(header("id"), new CustomAggregatorStrategy()).completionSize(3) 15 | .log("Sending out ${body}") 16 | .to("mock:output"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/aggregator/CustomAggregatorStrategy.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.aggregator; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 6/2/17. 7 | */ 8 | public class CustomAggregatorStrategy implements org.apache.camel.processor.aggregate.AggregationStrategy { 9 | 10 | public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { 11 | 12 | if(oldExchange==null) 13 | return newExchange; 14 | 15 | 16 | String oldBody = oldExchange.getIn().getBody(String.class); 17 | 18 | String newBody = newExchange.getIn().getBody(String.class); 19 | 20 | String body = oldBody + newBody; 21 | 22 | oldExchange.getIn().setBody(body); 23 | 24 | return oldExchange; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/contentbasesrouter/ContentBasedRouterRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.contentbasesrouter; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 7/19/17. 7 | */ 8 | public class ContentBasedRouterRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | from("file:input?noop=true") //noop - Dont perform any operation after moving the content. 13 | .to("log:?level=INFO&showBody=true&showHeaders=true") 14 | .choice() 15 | .when(header("CamelFileNameConsumed").endsWith(".html")) 16 | .to("file:html") 17 | .when(header("CamelFileNameConsumed").endsWith(".txt")) 18 | .to("file:text") 19 | .when(header("CamelFileNameConsumed").endsWith(".json")) 20 | .to("file:json") 21 | .otherwise() 22 | .to("file:other") 23 | //.to("file:other").stop() 24 | .end() 25 | .to("file:all"); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/multicast/MultiCastRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.multicast; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 7/22/17. 7 | */ 8 | public class MultiCastRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | /* from("file:input?noop=true").multicast() 13 | .to("file:output1", "file:output2");*/ 14 | 15 | //parallel Processing 16 | 17 | /*from("file:input?noop=true").multicast().parallelProcessing() 18 | .to("file:output1", "file:output2");*/ 19 | 20 | //Exception Handling 21 | from("file:input?noop=true").multicast().stopOnException() 22 | .parallelProcessing() 23 | .to("file:output1", "file:output2"); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/recipientlisteip/RecipientEIPProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.recipientlisteip; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 7/22/17. 7 | */ 8 | public class RecipientEIPProcessor implements org.apache.camel.Processor { 9 | 10 | public void process(Exchange exchange) throws Exception { 11 | 12 | String employeeType = 13 | exchange.getIn().getHeader("type", String.class); 14 | if (employeeType.equals("senior")) { 15 | exchange.getIn().setHeader("type", "file:xmlsenior"); 16 | } else { 17 | exchange.getIn().setHeader("type", "file:xmljunior"); 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/recipientlisteip/RecipientListRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.recipientlisteip; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 7/22/17. 7 | */ 8 | public class RecipientListRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | from("file:xmlinput?noop=true") 13 | .setHeader("type", xpath("/employee/@type")) 14 | .process(new RecipientEIPProcessor()) 15 | .recipientList(header("type")); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/splitter/SplitterEIP.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.splitter; 2 | 3 | /** 4 | * Created by Dilip on 6/1/17. 5 | */ 6 | public class SplitterEIP { 7 | } 8 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/java/com/learncamel/eip/wiretap/WireTapRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.wiretap; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 7/22/17. 7 | */ 8 | public class WireTapRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | from("file:input?noop=true") 12 | .wireTap("file:debug") 13 | .to("file:all"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /learn-camel-eips/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n 17 | -------------------------------------------------------------------------------- /learn-camel-eips/src/test/java/com/learncamel/eip/aggregator/AggregatorEIPRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.aggregator; 2 | 3 | import com.learncamel.eip.aggregator.AggregatorEIPRoute; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.component.mock.MockEndpoint; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | /** 11 | * Created by Dilip on 6/2/17. 12 | */ 13 | public class AggregatorEIPRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RouteBuilder createRouteBuilder(){ 17 | 18 | return new AggregatorEIPRoute(); 19 | } 20 | 21 | @Test 22 | public void testAggregate() throws InterruptedException { 23 | 24 | MockEndpoint mock = getMockEndpoint("mock:output"); 25 | mock.expectedBodiesReceived("123"); 26 | 27 | 28 | template.sendBodyAndHeader("direct:input", "1", "id", 1); 29 | template.sendBodyAndHeader("direct:input", "2", "id", 1); 30 | template.sendBodyAndHeader("direct:input", "3", "id", 1); 31 | 32 | assertMockEndpointsSatisfied(); 33 | 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /learn-camel-eips/src/test/java/com/learncamel/eip/contentbasedrouter/ContentBasedRouterTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.contentbasedrouter; 2 | 3 | import com.learncamel.eip.aggregator.AggregatorEIPRoute; 4 | import com.learncamel.eip.contentbasesrouter.ContentBasedRouterRoute; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * Created by Dilip on 7/19/17. 13 | */ 14 | public class ContentBasedRouterTest extends CamelTestSupport { 15 | 16 | @Override 17 | public RouteBuilder createRouteBuilder(){ 18 | 19 | return new ContentBasedRouterRoute(); 20 | } 21 | 22 | @Test 23 | public void contentBasedRouterTest() throws InterruptedException { 24 | 25 | Thread.sleep(5000); 26 | File file = new File("html"); 27 | 28 | assertTrue(file.isDirectory()); 29 | 30 | File file2 = new File("text"); 31 | assertTrue(file2.isDirectory()); 32 | File file3 = new File("json"); 33 | assertTrue(file3.isDirectory()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /learn-camel-eips/src/test/java/com/learncamel/eip/multicast/MultiCastRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.multicast; 2 | 3 | import com.learncamel.eip.contentbasesrouter.ContentBasedRouterRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Dilip on 7/22/17. 12 | */ 13 | public class MultiCastRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RouteBuilder createRouteBuilder(){ 17 | 18 | return new MultiCastRoute(); 19 | } 20 | 21 | @Test 22 | public void multicastRouteTest() throws InterruptedException { 23 | 24 | Thread.sleep(5000); 25 | File file = new File("output1"); 26 | 27 | assertTrue(file.isDirectory()); 28 | 29 | File file2 = new File("output1"); 30 | assertTrue(file2.isDirectory()); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /learn-camel-eips/src/test/java/com/learncamel/eip/recipientlisteip/RecipientListRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.recipientlisteip; 2 | 3 | import com.learncamel.eip.wiretap.WireTapRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Dilip on 7/22/17. 12 | */ 13 | public class RecipientListRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RouteBuilder createRouteBuilder(){ 17 | 18 | return new RecipientListRoute(); 19 | } 20 | 21 | @Test 22 | public void recipientListTest() throws InterruptedException { 23 | 24 | Thread.sleep(5000); 25 | 26 | File fileSenior = new File("xmlsenior"); 27 | assertTrue(fileSenior.isDirectory()); 28 | 29 | File fileJunior = new File("xmljunior"); 30 | assertTrue(fileJunior.isDirectory()); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /learn-camel-eips/src/test/java/com/learncamel/eip/wiretap/WireTapRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.eip.wiretap; 2 | 3 | import com.learncamel.eip.multicast.MultiCastRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Dilip on 7/22/17. 12 | */ 13 | public class WireTapRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RouteBuilder createRouteBuilder(){ 17 | 18 | return new WireTapRoute(); 19 | } 20 | 21 | @Test 22 | public void wireTapRoute() throws InterruptedException { 23 | 24 | Thread.sleep(5000); 25 | File file = new File("all"); 26 | 27 | assertTrue(file.isDirectory()); 28 | 29 | File fileDebug = new File("debug"); 30 | 31 | assertTrue(fileDebug.isDirectory()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /learn-camel-eips/xmlinput/employee1.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /learn-camel-eips/xmlinput/employee2.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /learncamel-activemq2db/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/java/com/learncamel/launch/AppLauncher.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.launch; 2 | 3 | import com.learncamel.routes.jms2jdbc.Jms2DBRoute; 4 | import org.apache.camel.CamelContext; 5 | import org.apache.camel.impl.DefaultCamelContext; 6 | import org.apache.camel.impl.SimpleRegistry; 7 | import org.apache.camel.main.Main; 8 | import org.apache.commons.dbcp.BasicDataSource; 9 | 10 | import javax.sql.DataSource; 11 | 12 | /** 13 | * Created by Dilip on 5/27/17. 14 | */ 15 | public class AppLauncher { 16 | 17 | public static void main(String[] args) throws Exception { 18 | Main main = new Main(); 19 | 20 | String url = "jdbc:postgresql://localhost:5432/localDB"; 21 | 22 | main.bind("myDataSource",setupDataSource(url)); //map based registry 23 | //main.bind(); 24 | 25 | main.addRouteBuilder(new Jms2DBRoute()); 26 | 27 | System.out.println("Starting Camel JMS to DB Route."); 28 | 29 | main.run(); 30 | 31 | 32 | } 33 | 34 | 35 | private static DataSource setupDataSource(String connectURI) { 36 | BasicDataSource ds = new BasicDataSource(); 37 | ds.setUsername("postgres"); 38 | ds.setDriverClassName("org.postgresql.Driver"); 39 | ds.setPassword("postgres"); 40 | ds.setUrl(connectURI); 41 | return ds; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/java/com/learncamel/routes/exception/ExceptionProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.exception; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 7/8/17. 7 | */ 8 | public class ExceptionProcessor implements org.apache.camel.Processor { 9 | 10 | public void process(Exchange exchange) throws Exception { 11 | 12 | Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); 13 | System.out.println("Acutal Exceptipn Message " + e.getMessage()); 14 | System.out.println("Acutal Exceptipn Class " + e.getClass()); 15 | 16 | String failedEndoint = (String) exchange.getProperty(Exchange.FAILURE_ENDPOINT); 17 | System.out.println("Failed Endpoint : " + failedEndoint); 18 | 19 | 20 | exchange.getIn().setBody("Exception happened in the route."); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/java/com/learncamel/routes/jdbc/DBPostgresRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jdbc; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.postgresql.util.PSQLException; 5 | 6 | /** 7 | * Created by Dilip on 5/26/17. 8 | */ 9 | public class DBPostgresRoute extends RouteBuilder { 10 | 11 | public void configure() throws Exception { 12 | 13 | onException(PSQLException.class).handled(true).log("Exception While inserting messages."); 14 | 15 | from("direct:dbInput") 16 | .to("log:?level=INFO&showBody=true") 17 | .process(new InsertProcessor()) 18 | .to("jdbc:myDataSource") 19 | .to("sql:select * from messages?dataSource=myDataSource") 20 | .to("log:?level=INFO&showBody=true"); 21 | 22 | 23 | 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/java/com/learncamel/routes/jdbc/InsertProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jdbc; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 5/26/17. 7 | */ 8 | public class InsertProcessor implements org.apache.camel.Processor { 9 | 10 | public void process(Exchange exchange) throws Exception { 11 | 12 | String input = (String) exchange.getIn().getBody(); 13 | System.out.println("Input to be persisted : " + input); 14 | 15 | String insertQuery = "INSERT INTO messages2 values ( '1','" + input+"')"; 16 | System.out.println("Insert Query is : " + insertQuery); 17 | exchange.getIn().setBody(insertQuery); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/java/com/learncamel/routes/jms/JmsReadRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jms; 2 | 3 | import org.apache.camel.CamelContext; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.component.jms.JmsComponent; 6 | import org.apache.camel.impl.DefaultCamelContext; 7 | import org.apache.activemq.ActiveMQConnectionFactory; 8 | import javax.jms.ConnectionFactory; 9 | 10 | import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent; 11 | 12 | /** 13 | * Created by Dilip on 5/26/17. 14 | */ 15 | public class JmsReadRoute extends RouteBuilder { 16 | 17 | public void configure() throws Exception { 18 | 19 | 20 | from("activemq:queue:testQueue") 21 | .to("log:?level=INFO&showBody=true") 22 | .to("direct:readQueue"); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/java/com/learncamel/routes/jms2jdbc/Jms2DBRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jms2jdbc; 2 | 3 | import com.learncamel.routes.exception.ExceptionProcessor; 4 | import com.learncamel.routes.jdbc.InsertProcessor; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.postgresql.util.PSQLException; 7 | 8 | import javax.jms.JMSException; 9 | 10 | /** 11 | * Created by Dilip on 5/27/17. 12 | */ 13 | public class Jms2DBRoute extends RouteBuilder { 14 | 15 | 16 | 17 | public void configure() throws Exception { 18 | 19 | onException(PSQLException.class).handled(true).log("Exception While inserting messages.").process(new ExceptionProcessor()); 20 | 21 | from("activemq:queue:testQueue") 22 | .to("log:?level=INFO&showBody=true") 23 | .process(new InsertProcessor()) 24 | .to("jdbc:myDataSource") 25 | .to("sql:select * from messages?dataSource=myDataSource") 26 | .to("log:?level=INFO&showBody=true"); 27 | //.to("direct:output"); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/resources/Sql-Script.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE messages 3 | ( 4 | id text , 5 | message text, 6 | create_date timestamp without time zone DEFAULT now() 7 | ) -------------------------------------------------------------------------------- /learncamel-activemq2db/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-activemq2db/src/test/java/com/learncamel/routes/jms/JmsReadRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jms; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.apache.camel.test.junit4.CamelTestSupport; 5 | import org.junit.Test; 6 | 7 | /** 8 | * Created by Dilip on 5/26/17. 9 | */ 10 | public class JmsReadRouteTest extends CamelTestSupport { 11 | 12 | @Override 13 | protected RouteBuilder createRouteBuilder() throws Exception { 14 | return new JmsReadRoute(); 15 | 16 | } 17 | 18 | @Test 19 | public void readMessageFromActiveMQ() throws InterruptedException { 20 | 21 | String expected = "123"; 22 | String response = consumer.receiveBody("direct:readQueue", String.class); 23 | System.out.println("The response is : " + response); 24 | assertEquals(expected,response); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | *.log 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.learncamel 8 | learncamel-boiler-plate 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.camel 15 | camel-core 16 | 2.20.1 17 | 18 | 19 | 20 | org.slf4j 21 | slf4j-api 22 | 1.7.12 23 | 24 | 25 | org.slf4j 26 | slf4j-log4j12 27 | 1.7.12 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/aggregator/AggregatorPredicateStrategy.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.aggregator; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by Dilip on 12/22/17. 10 | */ 11 | public class AggregatorPredicateStrategy implements org.apache.camel.processor.aggregate.AggregationStrategy { 12 | 13 | public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { 14 | if(oldExchange==null){ 15 | return newExchange; 16 | 17 | }else{ 18 | String oldBody = (String) oldExchange.getIn().getBody(); 19 | String newBody = (String) newExchange.getIn().getBody(); 20 | 21 | newBody = oldBody.concat(":").concat(newBody); 22 | 23 | newExchange.getIn().setBody(newBody); 24 | 25 | 26 | return newExchange; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/aggregator/AggregatorSimpleRouteStrategy.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.aggregator; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 12/21/17. 7 | */ 8 | public class AggregatorSimpleRouteStrategy implements org.apache.camel.processor.aggregate.AggregationStrategy { 9 | public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { 10 | 11 | if(oldExchange==null){ 12 | return newExchange; 13 | 14 | }else{ 15 | String oldBody = (String) oldExchange.getIn().getBody(); 16 | String newBody = (String) newExchange.getIn().getBody(); 17 | 18 | newBody = oldBody.concat(newBody); 19 | 20 | newExchange.getIn().setBody(newBody); 21 | 22 | 23 | return newExchange; 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/domain/Order.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.domain; 2 | 3 | /** 4 | * Created by Dilip on 12/22/17. 5 | */ 6 | public class Order { 7 | 8 | private String orderNum; 9 | private String item; 10 | private String orderStatus; 11 | 12 | @Override 13 | public String toString() { 14 | return "Order{" + 15 | "orderNum='" + orderNum + '\'' + 16 | ", item='" + item + '\'' + 17 | ", orderStatus='" + orderStatus + '\'' + 18 | '}'; 19 | } 20 | 21 | public String getOrderNum() { 22 | return orderNum; 23 | } 24 | 25 | public void setOrderNum(String orderNum) { 26 | this.orderNum = orderNum; 27 | } 28 | 29 | public String getItem() { 30 | return item; 31 | } 32 | 33 | public void setItem(String item) { 34 | this.item = item; 35 | } 36 | 37 | public String getOrderStatus() { 38 | return orderStatus; 39 | } 40 | 41 | public void setOrderStatus(String orderStatus) { 42 | this.orderStatus = orderStatus; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/routes/AggregateWithCompletionPredicateRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import com.learncamel.aggregator.AggregatorPredicateStrategy; 4 | import com.learncamel.aggregator.AggregatorSimpleRouteStrategy; 5 | import com.learncamel.domain.Order; 6 | import org.apache.camel.builder.RouteBuilder; 7 | import org.apache.camel.component.gson.GsonDataFormat; 8 | 9 | /** 10 | * Created by Dilip on 12/21/17. 11 | */ 12 | public class AggregateWithCompletionPredicateRoute extends RouteBuilder{ 13 | public void configure() throws Exception { 14 | 15 | GsonDataFormat dataFormat = new GsonDataFormat(Order.class); 16 | from("direct:completionPredicate") 17 | .log("Recieved Message is ${body} and key ${header.aggregatorId}") 18 | .aggregate(header("aggregatorId"), new AggregatorPredicateStrategy()) 19 | .log(" Message after Aggregation Strategy is ${body} and key ${header.aggregatorId}") 20 | .completionPredicate(body().contains("order-confirm")).eagerCheckCompletion() 21 | .log("Final Message is : ${body} ") 22 | .to("mock:output"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/routes/AggregatorSimpleRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import com.learncamel.aggregator.AggregatorSimpleRouteStrategy; 4 | import org.apache.camel.builder.RouteBuilder; 5 | 6 | /** 7 | * Created by Dilip on 12/21/17. 8 | */ 9 | public class AggregatorSimpleRoute extends RouteBuilder{ 10 | 11 | public void configure() throws Exception { 12 | from("direct:simpleAggregator") 13 | .log("Recieved Message is ${body} and key ${header.aggregatorId}") 14 | .aggregate(header("aggregatorId"), new AggregatorSimpleRouteStrategy()).completionSize(3) 15 | .log("Aggregated Message is ${body}") 16 | .to("mock:output"); 17 | 18 | 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/routes/AggregatorWithCompletionTimeoutRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import com.learncamel.aggregator.AggregatorSimpleRouteStrategy; 4 | import org.apache.camel.builder.RouteBuilder; 5 | 6 | /** 7 | * Created by Dilip on 12/21/17. 8 | */ 9 | public class AggregatorWithCompletionTimeoutRoute extends RouteBuilder { 10 | public void configure() throws Exception { 11 | from("direct:simpleAggregator") 12 | .log("Recieved Message is ${body} and key ${header.aggregatorId}") 13 | .aggregate(header("aggregatorId"), new AggregatorSimpleRouteStrategy()).completionSize(2).completionTimeout(3000) 14 | .log("Aggregated Message is ${body}") 15 | .to("mock:output"); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/routes/AggregatorWithGroupedExchangeRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy; 5 | 6 | /** 7 | * Created by Dilip on 12/22/17. 8 | */ 9 | public class AggregatorWithGroupedExchangeRoute extends RouteBuilder{ 10 | 11 | public void configure() throws Exception { 12 | 13 | from("direct:grpAggregator") 14 | .log("Received Message is ${body} and key ${header.aggregatorId}") 15 | .aggregate(header("aggregatorId"), new GroupedExchangeAggregationStrategy()).completionSize(3) 16 | .log("Aggregated Message is ${body} and key ${header.aggregatorId}") 17 | .to("mock:grpoutput"); 18 | 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/java/com/learncamel/util/SampleCamelUtil.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.util; 2 | 3 | /** 4 | * Created by Dilip on 12/16/17. 5 | */ 6 | public class SampleCamelUtil { 7 | } 8 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/test/java/com/learncamel/routes/AggregateWithCompletionPredicateRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import com.learncamel.routes.AggregateWithCompletionPredicateRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Dilip on 12/22/17. 14 | */ 15 | public class AggregateWithCompletionPredicateRouteTest extends CamelTestSupport { 16 | 17 | @Override 18 | public RouteBuilder createRouteBuilder(){ 19 | 20 | return new AggregateWithCompletionPredicateRoute(); 21 | 22 | } 23 | 24 | @Test 25 | public void predicateTest() throws InterruptedException { 26 | 27 | String orderCreate = "12345,samsung-phone,order-created"; 28 | String orderConfirm = "12345,samsung-phone,order-confirm"; 29 | 30 | MockEndpoint mock = getMockEndpoint("mock:output"); 31 | 32 | mock.expectedBodiesReceived(orderCreate.concat(":").concat(orderConfirm)); 33 | 34 | 35 | 36 | template.sendBodyAndHeader("direct:completionPredicate", orderCreate, "aggregatorId", 12345); 37 | template.sendBodyAndHeader("direct:completionPredicate", orderConfirm, "aggregatorId", 12345); 38 | 39 | assertMockEndpointsSatisfied(); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/test/java/com/learncamel/routes/AggregatorWithCompletionTimeoutRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import com.learncamel.routes.AggregatorWithCompletionTimeoutRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Created by Dilip on 12/21/17. 11 | */ 12 | public class AggregatorWithCompletionTimeoutRouteTest extends CamelTestSupport { 13 | 14 | @Override 15 | public RouteBuilder createRouteBuilder(){ 16 | 17 | return new AggregatorWithCompletionTimeoutRoute(); 18 | } 19 | 20 | @Test 21 | public void aggregateTimeout() throws InterruptedException { 22 | 23 | MockEndpoint mock = getMockEndpoint("mock:output"); 24 | 25 | mock.expectedBodiesReceived("12"); 26 | 27 | template.sendBodyAndHeader("direct:simpleAggregator", "1", "aggregatorId", 1); 28 | template.sendBodyAndHeader("direct:simpleAggregator", "2", "aggregatorId", 1); 29 | Thread.sleep(5000); 30 | template.sendBodyAndHeader("direct:simpleAggregator", "4", "aggregatorId", 2); 31 | template.sendBodyAndHeader("direct:simpleAggregator", "3", "aggregatorId", 1); 32 | assertMockEndpointsSatisfied(); 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /learncamel-aggregate-EIP/src/test/java/com/learncamel/routes/AggregatorWithGroupedExchangeRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes; 2 | 3 | import com.learncamel.routes.AggregatorWithGroupedExchangeRoute; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.component.mock.MockEndpoint; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Dilip on 12/22/17. 14 | */ 15 | public class AggregatorWithGroupedExchangeRouteTest extends CamelTestSupport { 16 | 17 | @Override 18 | public RouteBuilder createRouteBuilder(){ 19 | 20 | return new AggregatorWithGroupedExchangeRoute(); 21 | } 22 | 23 | @Test 24 | public void groupExchangeTest() throws InterruptedException { 25 | 26 | MockEndpoint mockEndpoint = getMockEndpoint("mock:grpoutput"); 27 | mockEndpoint.expectedBodiesReceived(1); 28 | 29 | 30 | template.sendBodyAndHeader("direct:grpAggregator", "1", "aggregatorId", 1); 31 | template.sendBodyAndHeader("direct:grpAggregator", "2", "aggregatorId", 1); 32 | template.sendBodyAndHeader("direct:grpAggregator", "3", "aggregatorId", 1); 33 | 34 | assertMockEndpointsSatisfied(); 35 | 36 | Exchange exchangeList = mockEndpoint.getExchanges().get(0); 37 | 38 | List exchangeList1 = (List) exchangeList.getProperty(Exchange.GROUPED_EXCHANGE); 39 | for (Exchange exchange : exchangeList1 ){ 40 | System.out.println("Exchange Body is : " + exchange.getIn().getBody()); 41 | } 42 | 43 | 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /learncamel-boilerplate/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | *.log 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | -------------------------------------------------------------------------------- /learncamel-boilerplate/learncamel-boilerplate.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /learncamel-boilerplate/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.learncamel 8 | learncamel-boiler-plate 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.camel 15 | camel-core 16 | 2.20.1 17 | 18 | 19 | 20 | org.slf4j 21 | slf4j-api 22 | 1.7.12 23 | 24 | 25 | org.slf4j 26 | slf4j-log4j12 27 | 1.7.12 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /learncamel-boilerplate/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-error-handling/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | *.log 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | -------------------------------------------------------------------------------- /learncamel-error-handling/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.learncamel 8 | learncamel-error-handling 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | 15 | 16 | org.apache.camel 17 | camel-core 18 | 2.18.3 19 | 20 | 21 | 22 | 23 | org.slf4j 24 | slf4j-api 25 | 1.7.12 26 | 27 | 28 | org.slf4j 29 | slf4j-log4j12 30 | 1.7.12 31 | 32 | 33 | org.apache.camel 34 | camel-test 35 | 2.20.0-SNAPSHOT 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.camel 44 | camel-test 45 | 2.18.3 46 | test 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/main/java/com/learncamel/bean/DataModifier.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.bean; 2 | 3 | 4 | import com.learncamel.exception.ApplicationException; 5 | 6 | import java.util.logging.Logger; 7 | 8 | /** 9 | * Created by Dilip on 7/1/17. 10 | */ 11 | public class DataModifier { 12 | 13 | Logger log = Logger.getLogger(DataModifier.class.getName()); 14 | 15 | public String map(String input) throws Exception { 16 | String newBody=null; 17 | try{ 18 | newBody = input.replace(",", "*"); 19 | }catch(RuntimeException e){ 20 | log.severe("RuntimeException : " + e); 21 | //throw e; 22 | } 23 | catch(Exception e){ 24 | log.severe("Exception : " + e); 25 | throw e; 26 | } 27 | return newBody; 28 | 29 | } 30 | 31 | public String mapOnException(String input) throws Exception { 32 | 33 | String newBody=null; 34 | try{ 35 | newBody = input.replace(",", "*"); 36 | }catch(RuntimeException e){ 37 | log.severe("RuntimeException : " + e); 38 | //throw e; 39 | throw new ApplicationException(e.getMessage()); 40 | } 41 | catch(Exception e){ 42 | log.severe("Exception : " + e); 43 | throw e; 44 | } 45 | return newBody; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/main/java/com/learncamel/exception/ApplicationException.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.exception; 2 | 3 | /** 4 | * Created by Dilip on 7/3/17. 5 | */ 6 | public class ApplicationException extends Exception { 7 | 8 | 9 | String message; 10 | 11 | @Override 12 | public String getMessage() { 13 | return message; 14 | } 15 | 16 | public void setMessage(String message) { 17 | this.message = message; 18 | } 19 | 20 | public ApplicationException(String s) { 21 | this.message=s; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/main/java/com/learncamel/exception/GenerateErrorResponseProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.exception; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.apache.camel.Processor; 5 | 6 | /** 7 | * Created by Dilip on 7/3/17. 8 | */ 9 | public class GenerateErrorResponseProcessor implements Processor { 10 | 11 | public void process(Exchange exchange) throws Exception { 12 | 13 | Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); 14 | System.out.println("Acutal Exceptipn Message " + e.getMessage()); 15 | System.out.println("Acutal Exceptipn Class " + e.getClass()); 16 | 17 | String failedEndoint = (String) exchange.getProperty(Exchange.FAILURE_ENDPOINT); 18 | System.out.println("Failed Endpoint : " + failedEndoint); 19 | 20 | 21 | exchange.getIn().setBody("Exception happened in the route."); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/main/java/com/learncamel/route/defaulterrorhandler/DefaultErrorHandlerRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.defaulterrorhandler; 2 | 3 | import com.learncamel.bean.DataModifier; 4 | import org.apache.camel.LoggingLevel; 5 | import org.apache.camel.builder.RouteBuilder; 6 | 7 | /** 8 | * Created by Dilip on 7/1/17. 9 | */ 10 | public class DefaultErrorHandlerRoute extends RouteBuilder { 11 | 12 | 13 | public void configure() throws Exception { 14 | 15 | //Error Logging 16 | //errorHandler(defaultErrorHandler().maximumRedeliveries(2).redeliveryDelay(3000).retryAttemptedLogLevel(LoggingLevel.WARN)); 17 | //Error Logging exponetial back off 18 | //errorHandler(defaultErrorHandler().maximumRedeliveries(2).redeliveryDelay(3000).backOffMultiplier(2).retryAttemptedLogLevel(LoggingLevel.WARN)); 19 | 20 | 21 | from("direct:exception") 22 | .bean(new DataModifier(), "map") 23 | .to("log:?level=INFO&showBody=true") 24 | .to("mock:errorqueue"); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss}| %p | %F %L | %m%n 17 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/test/java/com/learncamel/route/DefaultErrorHandlerRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.route.defaulterrorhandler.DefaultErrorHandlerRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Created by Dilip on 7/1/17. 11 | */ 12 | public class DefaultErrorHandlerRouteTest extends CamelTestSupport { 13 | 14 | @Override 15 | protected RouteBuilder createRouteBuilder() throws Exception { 16 | return new DefaultErrorHandlerRoute(); 17 | } 18 | 19 | @Test(expected = RuntimeException.class) 20 | public void exceptionCheck() throws InterruptedException { 21 | 22 | String expectedOutput = "123*dilip*12JAN17"; 23 | String input=null; 24 | 25 | MockEndpoint mock = getMockEndpoint("mock:errorqueue"); 26 | mock.expectedBodiesReceived(expectedOutput); 27 | 28 | template.sendBody("direct:exception",input); 29 | 30 | assertMockEndpointsSatisfied(); 31 | 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /learncamel-error-handling/src/test/java/com/learncamel/route/OnExceptionHandlerRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.exception.ApplicationException; 4 | import com.learncamel.route.defaulterrorhandler.DefaultErrorHandlerRoute; 5 | import com.learncamel.route.onexception.OnExceptionHandlerRoute; 6 | import org.apache.camel.builder.RouteBuilder; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Ignore; 9 | import org.junit.Test; 10 | 11 | /** 12 | * Created by Dilip on 7/3/17. 13 | */ 14 | public class OnExceptionHandlerRouteTest extends CamelTestSupport { 15 | 16 | @Override 17 | protected RouteBuilder createRouteBuilder() throws Exception { 18 | return new OnExceptionHandlerRoute(); 19 | } 20 | 21 | @Test(expected = RuntimeException.class) 22 | public void exceptionCheck_nohandled(){ 23 | 24 | String request=null; 25 | final String response = template.requestBody("direct:exception", request, String.class); 26 | System.out.println("Response is : " + response); 27 | 28 | } 29 | 30 | @Test 31 | public void exceptionCheck_handled_in_processor(){ 32 | 33 | String request=null; 34 | String expected ="Exception happened in the route."; 35 | final String response = template.requestBody("direct:exception", request, String.class); 36 | System.out.println("Response is : " + response); 37 | assertEquals(expected, response); 38 | } 39 | 40 | @Test 41 | public void exceptionCheck_continue(){ 42 | 43 | String request=null; 44 | String expected =null; 45 | final String response = template.requestBody("direct:exception", request, String.class); 46 | System.out.println("Response is : " + response); 47 | assertEquals(expected, response); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | *.log 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/java/com/learncamel/launch/AppLauncher.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.launch; 2 | 3 | import com.learncamel.routes.kafka2jdbc.Kafka2JdbcRoute; 4 | import org.apache.camel.main.Main; 5 | import org.apache.commons.dbcp.BasicDataSource; 6 | 7 | import javax.sql.DataSource; 8 | 9 | /** 10 | * Created by Dilip on 7/11/17. 11 | */ 12 | public class AppLauncher { 13 | 14 | 15 | public static void main(String[] args) throws Exception { 16 | Main main = new Main(); 17 | 18 | String url = "jdbc:postgresql://localhost:5432/localDB"; 19 | 20 | main.bind("myDataSource",setupDataSource(url)); //map based registry 21 | //main.bind(); 22 | 23 | main.addRouteBuilder(new Kafka2JdbcRoute()); 24 | 25 | System.out.println("Starting Camel JMS to DB Route."); 26 | 27 | main.run(); 28 | 29 | 30 | } 31 | 32 | 33 | private static DataSource setupDataSource(String connectURI) { 34 | BasicDataSource ds = new BasicDataSource(); 35 | ds.setUsername("postgres"); 36 | ds.setDriverClassName("org.postgresql.Driver"); 37 | ds.setPassword("postgres"); 38 | ds.setUrl(connectURI); 39 | return ds; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/java/com/learncamel/routes/exception/ExceptionProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.exception; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 7/12/17. 7 | */ 8 | public class ExceptionProcessor implements org.apache.camel.Processor { 9 | public void process(Exchange exchange) throws Exception { 10 | 11 | Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); 12 | System.out.println("Acutal Exceptipn Message " + e.getMessage()); 13 | System.out.println("Acutal Exceptipn Class " + e.getClass()); 14 | 15 | String failedEndoint = (String) exchange.getProperty(Exchange.FAILURE_ENDPOINT); 16 | System.out.println("Failed Endpoint : " + failedEndoint); 17 | 18 | 19 | exchange.getIn().setBody("Exception happened in the route."); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/java/com/learncamel/routes/jdbc/DBPostgresRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jdbc; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.postgresql.util.PSQLException; 5 | 6 | /** 7 | * Created by Dilip on 5/26/17. 8 | */ 9 | public class DBPostgresRoute extends RouteBuilder { 10 | 11 | public void configure() throws Exception { 12 | 13 | onException(PSQLException.class).handled(true).log("Exception While inserting messages."); 14 | 15 | from("direct:dbInput") 16 | .to("log:?level=INFO&showBody=true") 17 | .process(new InsertProcessor()) 18 | .to("jdbc:myDataSource") 19 | .to("sql:select * from messages?dataSource=myDataSource") 20 | .to("log:?level=INFO&showBody=true"); 21 | 22 | 23 | 24 | } 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/java/com/learncamel/routes/jdbc/InsertProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jdbc; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 5/26/17. 7 | */ 8 | public class InsertProcessor implements org.apache.camel.Processor { 9 | 10 | public void process(Exchange exchange) throws Exception { 11 | 12 | String input = (String) exchange.getIn().getBody(); 13 | System.out.println("Input to be persisted : " + input); 14 | 15 | String insertQuery = "INSERT INTO messages value ( '1','" + input+"')"; 16 | System.out.println("Insert Query is : " + insertQuery); 17 | exchange.getIn().setBody(insertQuery); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/java/com/learncamel/routes/kafka/KafkaConsumerRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.kafka; 2 | 3 | import org.apache.camel.Route; 4 | import org.apache.camel.builder.RouteBuilder; 5 | 6 | /** 7 | * Created by Dilip on 7/11/17. 8 | */ 9 | public class KafkaConsumerRoute extends RouteBuilder { 10 | 11 | public void configure() throws Exception { 12 | 13 | from("kafka:localhost:9092?topic=my-first-topic&groupId=group1&consumersCount=1&autoOffsetReset=latest") 14 | .log("${body}") 15 | .to("direct:readFromKafka"); 16 | 17 | //With SSL 18 | /*from("kafka:localhost:9092?topic=my-first-topic&groupId=group1&consumersCount=1&autoOffsetReset=latest&securityProtocol=SSL&sslKeystoreLocation=${sslKeystorePath}&sslKeystorePassword=${sslKeystorePassword}&sslTruststoreLocation=${sslTruststorePath}&sslTruststorePassword=${sslTruststorePassword}") 19 | .log("${body}") 20 | .to("direct:readFromKafka"); 21 | */ 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/java/com/learncamel/routes/kafka2jdbc/Kafka2JdbcRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.kafka2jdbc; 2 | 3 | import com.learncamel.routes.exception.ExceptionProcessor; 4 | import com.learncamel.routes.jdbc.InsertProcessor; 5 | import org.apache.camel.Exchange; 6 | import org.apache.camel.builder.RouteBuilder; 7 | import org.apache.kafka.common.KafkaException; 8 | import org.postgresql.util.PSQLException; 9 | 10 | /** 11 | * Created by Dilip on 7/11/17. 12 | */ 13 | public class Kafka2JdbcRoute extends RouteBuilder { 14 | 15 | public void configure() throws Exception { 16 | 17 | onException(PSQLException.class, Exception.class).handled(true).log("Exception While inserting messages.").process(new ExceptionProcessor()); 18 | 19 | from("kafka:localhost:9092?topic=my-first-topic&groupId=group1&consumersCount=1&autoOffsetReset=latest") 20 | .to("log:?level=INFO&showBody=true") 21 | .process(new InsertProcessor()) 22 | .to("jdbc:myDataSource") 23 | .to("sql:select * from messages?dataSource=myDataSource") 24 | .to("log:?level=INFO&showBody=true"); 25 | //.to("direct:output"); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/resources/Sql-Script.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE messages 3 | ( 4 | id text , 5 | message text, 6 | create_date timestamp without time zone DEFAULT now() 7 | ) -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-kafka2DB/src/test/java/com/learncamel/routes/kafka/KafkaConsumerRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.kafka; 2 | 3 | import com.learncamel.routes.kafka.KafkaConsumerRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by Dilip on 7/11/17. 10 | */ 11 | public class KafkaConsumerRouteTest extends CamelTestSupport { 12 | 13 | @Override 14 | protected RouteBuilder createRouteBuilder() throws Exception { 15 | return new KafkaConsumerRoute(); 16 | 17 | } 18 | 19 | @Test 20 | public void readMessageFromKafka(){ 21 | 22 | String expected = "123"; 23 | String response = consumer.receiveBody("direct:readFromKafka", String.class); 24 | System.out.println("The response is : " + response); 25 | assertEquals(expected,response); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__com_sun_xml_bind_jaxb_core_2_2_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__com_sun_xml_bind_jaxb_impl_2_2_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__commons_codec_commons_codec_1_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__commons_dbcp_commons_dbcp_1_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__commons_httpclient_commons_httpclient_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__commons_logging_commons_logging_1_0_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_apache_camel_camel_core_2_18_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_apache_camel_camel_http_2_18_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_apache_camel_camel_http_common_2_18_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_apache_camel_camel_jdbc_2_10_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_apache_camel_camel_sql_2_14_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_apache_camel_camel_test_2_20_0_SNAPSHOT.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1212.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_slf4j_slf4j_simple_1_7_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_springframework_spring_beans_3_2_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_springframework_spring_core_3_2_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_springframework_spring_jdbc_3_2_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/libraries/Maven__org_springframework_spring_tx_3_2_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /learncamel-rest2DB/.idea/sqldialects.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/java/com/learncamel/launch/AppLauncher.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.launch; 2 | 3 | import com.learncamel.routes.rest2DB.Rest2DBRoute; 4 | import org.apache.camel.main.Main; 5 | import org.apache.commons.dbcp.BasicDataSource; 6 | 7 | import javax.sql.DataSource; 8 | 9 | /** 10 | * Created by Dilip on 7/11/17. 11 | */ 12 | public class AppLauncher { 13 | 14 | 15 | public static void main(String[] args) throws Exception { 16 | Main main = new Main(); 17 | 18 | String url = "jdbc:postgresql://localhost:5432/localDB"; 19 | 20 | main.bind("myDataSource",setupDataSource(url)); //map based registry 21 | //main.bind(); 22 | 23 | main.addRouteBuilder(new Rest2DBRoute()); 24 | 25 | System.out.println("Starting Camel JMS to DB Route."); 26 | 27 | main.run(); 28 | 29 | 30 | } 31 | 32 | 33 | private static DataSource setupDataSource(String connectURI) { 34 | BasicDataSource ds = new BasicDataSource(); 35 | ds.setUsername("postgres"); 36 | ds.setDriverClassName("org.postgresql.Driver"); 37 | ds.setPassword("postgres"); 38 | ds.setUrl(connectURI); 39 | return ds; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/java/com/learncamel/routes/excetion/ExceptionProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.excetion; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 7/19/17. 7 | */ 8 | public class ExceptionProcessor implements org.apache.camel.Processor { 9 | 10 | public void process(Exchange exchange) throws Exception { 11 | 12 | Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class); 13 | System.out.println("Acutal Exceptipn Message " + e.getMessage()); 14 | System.out.println("Acutal Exceptipn Class " + e.getClass()); 15 | 16 | String failedEndoint = (String) exchange.getProperty(Exchange.FAILURE_ENDPOINT); 17 | System.out.println("Failed Endpoint : " + failedEndoint); 18 | 19 | 20 | exchange.getIn().setBody("Exception happened in the route."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/java/com/learncamel/routes/jdbc/DBPostgresRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jdbc; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.postgresql.util.PSQLException; 5 | 6 | /** 7 | * Created by Dilip on 5/26/17. 8 | */ 9 | public class DBPostgresRoute extends RouteBuilder { 10 | 11 | public void configure() throws Exception { 12 | 13 | onException(PSQLException.class).handled(true).log("Exception While inserting messages."); 14 | 15 | from("direct:dbInput") 16 | .to("log:?level=INFO&showBody=true") 17 | .process(new InsertProcessor()) 18 | .to("jdbc:myDataSource") 19 | .to("sql:select * from country_capital?dataSource=myDataSource") 20 | .to("log:?level=INFO&showBody=true"); 21 | 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/java/com/learncamel/routes/jdbc/InsertProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.jdbc; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.json.simple.JSONObject; 5 | import org.json.simple.parser.JSONParser; 6 | 7 | /** 8 | * Created by Dilip on 7/15/17. 9 | */ 10 | public class InsertProcessor implements org.apache.camel.Processor { 11 | 12 | public void process(Exchange exchange) throws Exception { 13 | 14 | String input = (String) exchange.getIn().getBody(); 15 | System.out.println("Input to be persisted : " + input); 16 | 17 | JSONParser parser = new JSONParser(); 18 | Object obj = parser.parse(input); 19 | 20 | JSONObject jsonObject = (JSONObject) obj; 21 | 22 | String name = (String) jsonObject.get("name"); 23 | 24 | String capital = (String) jsonObject.get("capital"); 25 | 26 | String insertQuery = "INSERT INTO country_capital values ( ".concat("'").concat(name).concat("'").concat(",").concat("'").concat(capital).concat("'").concat(" )"); 27 | System.out.println("Insert Query is : " + insertQuery); 28 | exchange.getIn().setBody(insertQuery); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/java/com/learncamel/routes/rest/RestRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.rest; 2 | 3 | import com.learncamel.routes.jdbc.InsertProcessor; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.builder.RouteBuilder; 6 | 7 | /** 8 | * Created by Dilip on 7/11/17. 9 | */ 10 | public class RestRoute extends RouteBuilder { 11 | 12 | public void configure() throws Exception { 13 | 14 | from("direct:restCall") 15 | .to("log:?level=INFO&showBody=true") 16 | .setHeader(Exchange.HTTP_METHOD, constant("GET")) 17 | .setHeader(Exchange.HTTP_URI, simple("https://restcountries.eu/rest/v2/alpha/${body}")) 18 | .to("https://restcountries.eu/rest/v2/alpha/${body}") 19 | .to("log:?level=INFO&showBody=true"); 20 | 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/java/com/learncamel/routes/rest2DB/Rest2DBRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.rest2DB; 2 | 3 | import com.learncamel.routes.excetion.ExceptionProcessor; 4 | import com.learncamel.routes.jdbc.InsertProcessor; 5 | import org.apache.camel.Exchange; 6 | import org.apache.camel.builder.RouteBuilder; 7 | import org.postgresql.util.PSQLException; 8 | 9 | /** 10 | * Created by Dilip on 7/16/17. 11 | */ 12 | public class Rest2DBRoute extends RouteBuilder { 13 | 14 | 15 | public void configure() throws Exception { 16 | 17 | onException(PSQLException.class, Exception.class).handled(true).log("Exception While inserting messages.").process(new ExceptionProcessor()); 18 | 19 | from("timer:learnTimer?period=10s") 20 | .to("log:?level=INFO&showBody=true") 21 | .setHeader(Exchange.HTTP_METHOD, constant("GET")) 22 | .setHeader(Exchange.HTTP_URI, simple("https://restcountries.eu/rest/v2/alpha/us")) 23 | .to("https://restcountries.eu/rest/v2/alpha/us").convertBodyTo(String.class) 24 | .to("log:?level=INFO&showBody=true") 25 | .process(new InsertProcessor()) 26 | .to("jdbc:myDataSource") 27 | .to("sql:select * from country_capital?dataSource=myDataSource"); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/resources/Sql-Script.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE country_capital 3 | ( 4 | countryName text , 5 | capital text, 6 | create_date timestamp without time zone DEFAULT now() 7 | ); -------------------------------------------------------------------------------- /learncamel-rest2DB/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-rest2DB/src/test/java/com/learncamel/routes/rest/RestRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.rest; 2 | 3 | import com.learncamel.routes.rest.RestRoute; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by Dilip on 7/13/17. 10 | */ 11 | public class RestRouteTest extends CamelTestSupport { 12 | 13 | 14 | @Override 15 | protected RouteBuilder createRouteBuilder() throws Exception { 16 | return new RestRoute(); 17 | } 18 | 19 | @Test 20 | public void restCall(){ 21 | 22 | String response = template.requestBody("direct:restCall","USA",String.class); 23 | System.out.println("response : " + response); 24 | assertNotNull(response); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/Sql-Script.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE country_capital 3 | ( 4 | countryName text , 5 | capital text, 6 | create_date timestamp without time zone DEFAULT now() 7 | ); -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/com/learncamel/launch/AppLauncher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/classes/com/learncamel/launch/AppLauncher.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/com/learncamel/routes/excetion/ExceptionProcessor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/classes/com/learncamel/routes/excetion/ExceptionProcessor.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/com/learncamel/routes/jdbc/DBPostgresRoute.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/classes/com/learncamel/routes/jdbc/DBPostgresRoute.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/com/learncamel/routes/jdbc/InsertProcessor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/classes/com/learncamel/routes/jdbc/InsertProcessor.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/com/learncamel/routes/rest/RestRoute.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/classes/com/learncamel/routes/rest/RestRoute.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/com/learncamel/routes/rest2DB/Rest2DBRoute.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/classes/com/learncamel/routes/rest2DB/Rest2DBRoute.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/classes/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/camel-core-2.18.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/camel-core-2.18.3.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/camel-http-2.18.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/camel-http-2.18.3.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/camel-http-common-2.18.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/camel-http-common-2.18.3.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/camel-jdbc-2.10.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/camel-jdbc-2.10.4.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/camel-sql-2.14.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/camel-sql-2.14.0.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/camel-test-2.20.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/camel-test-2.20.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/commons-codec-1.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/commons-codec-1.10.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/commons-dbcp-1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/commons-dbcp-1.4.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/commons-httpclient-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/commons-httpclient-3.1.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/commons-logging-1.0.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/commons-logging-1.0.4.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/commons-pool-1.5.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/commons-pool-1.5.4.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/javax.servlet-api-3.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/javax.servlet-api-3.1.0.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/jaxb-core-2.2.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/jaxb-core-2.2.11.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/jaxb-impl-2.2.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/jaxb-impl-2.2.11.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/json-simple-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/json-simple-1.1.1.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/junit-4.12.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/junit-4.12.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/postgresql-9.4.1212.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/postgresql-9.4.1212.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/slf4j-api-1.7.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/slf4j-api-1.7.10.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/slf4j-simple-1.7.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/slf4j-simple-1.7.10.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/spring-beans-3.2.11.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/spring-beans-3.2.11.RELEASE.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/spring-core-3.2.11.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/spring-core-3.2.11.RELEASE.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/spring-jdbc-3.2.11.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/spring-jdbc-3.2.11.RELEASE.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/dependency-jars/spring-tx-3.2.11.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/dependency-jars/spring-tx-3.2.11.RELEASE.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/learncamel-rest2DB-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/learncamel-rest2DB-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /learncamel-rest2DB/target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven 2 | #Tue Jul 11 13:09:51 CDT 2017 3 | version=1.0-SNAPSHOT 4 | groupId=com.learncamel 5 | artifactId=learncamel-rest2DB 6 | -------------------------------------------------------------------------------- /learncamel-rest2DB/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/learncamel/launch/AppLauncher.class 2 | -------------------------------------------------------------------------------- /learncamel-rest2DB/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/main/java/com/learncamel/routes/jdbc/DBPostgresRoute.java 2 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/main/java/com/learncamel/routes/jdbc/InsertProcessor.java 3 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/main/java/com/learncamel/routes/rest2DB/Rest2DBRoute.java 4 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/main/java/com/learncamel/routes/rest/RestRoute.java 5 | -------------------------------------------------------------------------------- /learncamel-rest2DB/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst -------------------------------------------------------------------------------- /learncamel-rest2DB/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/test/java/com/learncamel/routes/jdbc/DBPostgresRouteTest.java 2 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/test/java/com/learncamel/routes/rest/RestRouteTest.java 3 | /Dilip/Study/ApacheCamel/TeachApacheCamel/codebase/learncamel-rest2DB/src/test/java/com/learncamel/routes/rest2jdbc/Rest2DBRouteTest.java 4 | -------------------------------------------------------------------------------- /learncamel-rest2DB/target/test-classes/com/learncamel/routes/jdbc/DBPostgresRouteTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/test-classes/com/learncamel/routes/jdbc/DBPostgresRouteTest.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/test-classes/com/learncamel/routes/rest/RestRouteTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/test-classes/com/learncamel/routes/rest/RestRouteTest.class -------------------------------------------------------------------------------- /learncamel-rest2DB/target/test-classes/com/learncamel/routes/rest2jdbc/Rest2DBRouteTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-rest2DB/target/test-classes/com/learncamel/routes/rest2jdbc/Rest2DBRouteTest.class -------------------------------------------------------------------------------- /learncamel-simple-file/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /learncamel-simple-file/data/anothetdestination/file1.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/data/anothetdestination/file2.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/data/input/file1.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/data/input/file2.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/data/input1/file3.txt: -------------------------------------------------------------------------------- 1 | xyz 2 | 123 3 | -------------------------------------------------------------------------------- /learncamel-simple-file/data/input1/file4.txt: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | -------------------------------------------------------------------------------- /learncamel-simple-file/data/nextoutput/file3.txt: -------------------------------------------------------------------------------- 1 | xyz 2 | 123 3 | -------------------------------------------------------------------------------- /learncamel-simple-file/data/nextoutput/file4.txt: -------------------------------------------------------------------------------- 1 | 1234 2 | 4567 3 | -------------------------------------------------------------------------------- /learncamel-simple-file/data/output/file1.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/data/output/file2.txt: -------------------------------------------------------------------------------- 1 | Hi 2 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.learncamel 8 | learncamel-simple-file 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.apache.camel 15 | camel-core 16 | 2.20.1 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.slf4j 24 | slf4j-api 25 | 1.7.12 26 | 27 | 28 | org.slf4j 29 | slf4j-log4j12 30 | 1.7.12 31 | 32 | 33 | 34 | 35 | 36 | org.apache.camel 37 | camel-test 38 | 2.20.1 39 | test 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /learncamel-simple-file/sampleOutput/output.txt: -------------------------------------------------------------------------------- 1 | Hello -------------------------------------------------------------------------------- /learncamel-simple-file/sampleOutput/output.txt.camelLock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dilipsundarraj1/TeachApacheCamel/f33e155dbf1cb52b882e60ae092ac0c3608031ee/learncamel-simple-file/sampleOutput/output.txt.camelLock -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/direct/SampleDirectRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.direct; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 6/8/17. 7 | */ 8 | public class SampleDirectRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | from("direct:sampleInput") 13 | .log("Received Message is ${body} and Headers are ${headers}") 14 | .to("file:sampleOutput?fileName=output.txt"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/direct/SampleMockRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.direct; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 6/11/17. 7 | */ 8 | public class SampleMockRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | from("direct:sampleInput") 13 | .log("Received Message is ${body} and Headers are ${headers}") 14 | .to("mock:output"); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/file/CopyFilesCamel.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.file; 2 | 3 | import org.apache.camel.CamelContext; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.impl.DefaultCamelContext; 6 | 7 | /** 8 | * Created by Dilip on 5/30/17. 9 | */ 10 | public class CopyFilesCamel { 11 | 12 | public static void main(String[] args) { 13 | CamelContext context= new DefaultCamelContext(); 14 | 15 | try{ 16 | context.addRoutes(new RouteBuilder() { 17 | @Override 18 | public void configure() throws Exception { 19 | from("file:data/input?noop=true") 20 | .to("file:data/output"); 21 | } 22 | }); 23 | 24 | context.start(); 25 | Thread.sleep(5000); 26 | context.stop(); 27 | 28 | }catch(Exception e){ 29 | System.out.println("Inside Exception : " + e); 30 | } 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/file/CopyFilesCamelLogging.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.file; 2 | 3 | import org.apache.camel.CamelContext; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.impl.DefaultCamelContext; 6 | 7 | /** 8 | * Created by Dilip on 6/5/17. 9 | */ 10 | public class CopyFilesCamelLogging { 11 | 12 | public static void main(String[] args) { 13 | CamelContext context= new DefaultCamelContext(); 14 | 15 | try{ 16 | context.addRoutes(new RouteBuilder() { 17 | @Override 18 | public void configure() throws Exception { 19 | from("file:data/input?noop=true") 20 | .to("log:?level=INFO&showBody=true&showHeaders=true") 21 | //.log("Received Message is ${body} and Headers are ${headers}") 22 | .to("file:data/output"); 23 | 24 | 25 | } 26 | }); 27 | 28 | context.start(); 29 | Thread.sleep(5000); 30 | context.stop(); 31 | 32 | }catch(Exception e){ 33 | System.out.println("Inside Exception : " + e); 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/file/CopyFilesMultiRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.file; 2 | 3 | import org.apache.camel.CamelContext; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.impl.DefaultCamelContext; 6 | 7 | /** 8 | * Created by Dilip on 6/7/17. 9 | */ 10 | public class CopyFilesMultiRoute { 11 | 12 | public static void main(String[] args) { 13 | CamelContext context= new DefaultCamelContext(); 14 | 15 | try{ 16 | context.addRoutes(new RouteBuilder() { 17 | @Override 18 | public void configure() throws Exception { 19 | from("file:data/input?noop=true") 20 | //.to("log:?level=INFO&showBody=true&showHeaders=true") 21 | .log("Received Message is ${body} and Headers are ${headers}") 22 | .to("file:data/output") 23 | .to("file:data/anothetdestination"); 24 | 25 | from("file:data/input1?noop=true") 26 | .to("file:data/nextoutput"); 27 | 28 | 29 | } 30 | }); 31 | 32 | context.start(); 33 | Thread.sleep(5000); 34 | context.stop(); 35 | 36 | }catch(Exception e){ 37 | System.out.println("Inside Exception : " + e); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/file/CopyFilesRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.file; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 6/8/17. 7 | */ 8 | public class CopyFilesRoute extends RouteBuilder { 9 | 10 | 11 | public void configure() throws Exception { 12 | 13 | from("file:data/input?noop=true") 14 | .to("file:data/output"); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/java/com/learncamel/file/CopyFilesWithoutCamel.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.file; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * Created by Dilip on 4/14/17. 7 | */ 8 | public class CopyFilesWithoutCamel { 9 | 10 | public static void main(String[] args) throws IOException { 11 | 12 | //Step 1 - Create a file Object for the the directories to read and write. 13 | File inputDirectory = new File("data/input"); 14 | File outputDirectory = new File("data/output"); 15 | 16 | outputDirectory.mkdir(); 17 | 18 | //Step 2 - Read the files and Iterate the files 19 | File[] files = inputDirectory.listFiles(); 20 | 21 | for (File source : files) { 22 | if (source.isFile()) { 23 | File dest = new File( 24 | outputDirectory.getPath() 25 | + File.separator 26 | + source.getName()); 27 | //Step 3 : Create a Output Stream to write the files. 28 | 29 | OutputStream oStream = new FileOutputStream(dest); 30 | byte[] buffer = new byte[(int) source.length()]; 31 | FileInputStream iStream = new FileInputStream(source); 32 | iStream.read(buffer); 33 | try { 34 | oStream.write(buffer); 35 | } finally { 36 | oStream.close(); 37 | iStream.close(); 38 | } 39 | } 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n 17 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/test/java/com/learncamel/direct/SampleDirectRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.direct; 2 | 3 | import com.learncamel.file.CopyFilesRoute; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.RoutesBuilder; 6 | import org.apache.camel.component.mock.MockEndpoint; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | import java.io.File; 11 | 12 | /** 13 | * Created by Dilip on 6/8/17. 14 | */ 15 | public class SampleDirectRouteTest extends CamelTestSupport { 16 | @Override 17 | public RoutesBuilder createRouteBuilder() throws Exception { 18 | return new SampleDirectRoute(); 19 | } 20 | 21 | 22 | @Test 23 | public void sampleRouteTest() throws InterruptedException { 24 | 25 | /** 26 | * Producer Template. 27 | */ 28 | template.sendBodyAndHeader("direct:sampleInput","Hello", "hi" , 1); 29 | 30 | Thread.sleep(5000); 31 | 32 | File file = new File("sampleOutput"); 33 | 34 | assertTrue(file.isDirectory()); 35 | 36 | /** 37 | * Consumer Template. 38 | */ 39 | Exchange exchange = consumer.receive("file:sampleOutput"); 40 | 41 | System.out.println("Received body is :" + exchange.getIn().getBody()); 42 | System.out.println("File Name is :" + exchange.getIn().getHeader("CamelFileName")); 43 | 44 | assertEquals("output.txt", exchange.getIn().getHeader("CamelFileName")); 45 | 46 | 47 | 48 | } 49 | 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/test/java/com/learncamel/direct/SampleMockRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.direct; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * Created by Dilip on 6/11/17. 13 | */ 14 | public class SampleMockRouteTest extends CamelTestSupport { 15 | 16 | @Override 17 | public RoutesBuilder createRouteBuilder() throws Exception { 18 | return new SampleMockRoute(); 19 | } 20 | 21 | @Test 22 | public void sampleRouteTest() throws InterruptedException { 23 | 24 | String expected="Hello"; 25 | 26 | MockEndpoint mock = getMockEndpoint("mock:output"); 27 | mock.expectedBodiesReceived(expected); 28 | 29 | /** 30 | * Producer Template. 31 | */ 32 | template.sendBody("direct:sampleInput","Hello" ); 33 | 34 | assertMockEndpointsSatisfied(); 35 | 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /learncamel-simple-file/src/test/java/com/learncamel/file/CopyFilesCamelTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.file; 2 | 3 | import org.apache.camel.RoutesBuilder; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | import java.time.LocalDateTime; 10 | 11 | /** 12 | * Created by Dilip on 6/8/17. 13 | */ 14 | public class CopyFilesCamelTest extends CamelTestSupport { 15 | 16 | @Override 17 | public RoutesBuilder createRouteBuilder() throws Exception { 18 | return new CopyFilesRoute(); 19 | } 20 | 21 | @Test 22 | public void checkFileExistsInOutputDirectory() throws InterruptedException { 23 | 24 | 25 | Thread.sleep(5000); 26 | 27 | File file = new File("data/output"); 28 | 29 | assertTrue(file.isDirectory()); 30 | System.out.println("Total no of files in the output directory : " + file.listFiles().length); 31 | assertEquals(2, file.listFiles().length); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | *.log 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ 26 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/input/file1.txt: -------------------------------------------------------------------------------- 1 | id,firstname,lastname 2 | 01,Dilip,Sundarraj 3 | 02,Kevin,Hart -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/input/file2.txt: -------------------------------------------------------------------------------- 1 | id;firstname;lastname 2 | 01;Dilip;Sundarraj 3 | 02;Kevin;Hart -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/input/file3.txt: -------------------------------------------------------------------------------- 1 | id|firstname|lastname 2 | 01|Dilip|Sundarraj 3 | 02|Kevin|Hart -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/input/file4.txt: -------------------------------------------------------------------------------- 1 | id*firstname*lastname 2 | 01*Dilip*Sundarraj 3 | 02*Kevin*Hart -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/input/fileWithAddress.txt: -------------------------------------------------------------------------------- 1 | id,firstname,lastname,addressline,city,state,country 2 | 01,Dilip,Sundarraj,1234 abc street,AppleValley,MN,12345,USA -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/output/output.txt: -------------------------------------------------------------------------------- 1 | id*firstName*lastName 2 | 123*Dilip*Sundar 3 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/csv/output/outputWithAddress.txt: -------------------------------------------------------------------------------- 1 | 123,Dilip,Sundar,12345 ABC lane,APple Valley,MN,12345,USA 2 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/fixedposition/input/FixedPositionFile-Date.txt: -------------------------------------------------------------------------------- 1 | 123dilip Engineer12Jan2017 2 | 123kevin Engineer12Jan2017 -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/fixedposition/input/FixedPositionFile-Delimiter-salary.txt: -------------------------------------------------------------------------------- 1 | 123dilip Engineer12Jan201730^100000.00 2 | 123kevin Engineer12Jan201730^100000.00 -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/fixedposition/input/FixedPositionFile-Delimiter.txt: -------------------------------------------------------------------------------- 1 | 123dilip Engineer12Jan201730^ 2 | 123kevin Engineer12Jan201730^ -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/fixedposition/input/FixedPositionFile.txt: -------------------------------------------------------------------------------- 1 | 123dilip Engineer 2 | 123kevin Engineer -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/fixedposition/output/FixedPositionFile.txt: -------------------------------------------------------------------------------- 1 | 1 AdamEngineer24Dec201730^ 2 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/headerandfooter/input/samplefile: -------------------------------------------------------------------------------- 1 | (MH7000) 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | DUM2402l 19NOV14 05:00 2.0 10 | 11 | DUM2402h 19NOV14 05:00 6.0 12 | 13 | DUM2401w 19NOV14 05:00 586.0 14 | 15 | DUM2401u 19NOV14 05:00 586.0 16 | 17 | DUM2401u 19NOV14 05:00 586.0 18 | 19 | 20 | 21 | (RRRR) 22 | 23 | 24 | 25 | (MH7000) 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | XICE002l 30jul15 23 34 | 35 | XICE002h 30jul15 87 36 | 37 | 38 | 39 | (RRRR) 40 | 41 | (MH7000) 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | AAIBH00l 21DEC15 03:00 1311.5 50 | 51 | AAIBH00c 21DEC15 03:00 1312 52 | 53 | AAIBH00h 21DEC15 03:00 1312.5 54 | 55 | AAIBN00l 21DEC15 03:00 1311.5 56 | 57 | 58 | 59 | (RRRR) -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/keyValue/input/key-value-file1.txt: -------------------------------------------------------------------------------- 1 | 1=1 2=dilip 3=12 2 | 1=2 2=kevin 3=11 -------------------------------------------------------------------------------- /learncamel-transform-bindy/data/keyValue/output/key-value-file-output.txt: -------------------------------------------------------------------------------- 1 | 1=1 2=Dilip 3=12 2 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/domain/Employee.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.domain; 2 | 3 | import org.apache.camel.dataformat.bindy.annotation.CsvRecord; 4 | import org.apache.camel.dataformat.bindy.annotation.DataField; 5 | 6 | /** 7 | * Created by Dilip on 12/6/17. 8 | */ 9 | //@CsvRecord( separator = ",",skipFirstLine=true ) 10 | //@CsvRecord( separator = ";",skipFirstLine=true ) 11 | //@CsvRecord( separator = "\\|",skipFirstLine=true ) 12 | @CsvRecord( separator = "\\*",skipFirstLine=true ,generateHeaderColumns = true) 13 | //@CsvRecord( separator = ",",skipFirstLine=true ,generateHeaderColumns = true) 14 | public class Employee { 15 | 16 | public String getFirstName() { 17 | return firstName; 18 | } 19 | 20 | public void setFirstName(String firstName) { 21 | this.firstName = firstName; 22 | } 23 | 24 | public String getLastName() { 25 | return lastName; 26 | } 27 | 28 | public void setLastName(String lastName) { 29 | this.lastName = lastName; 30 | } 31 | 32 | public String getId() { 33 | 34 | return id; 35 | } 36 | 37 | public void setId(String id) { 38 | this.id = id; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Employee{" + 44 | "id='" + id + '\'' + 45 | ", firstName='" + firstName + '\'' + 46 | ", lastName='" + lastName + '\'' + 47 | '}'; 48 | 49 | } 50 | 51 | //"10","Dilip","Sundarraj" 52 | @DataField(pos = 1) 53 | private String id; 54 | 55 | @DataField(pos = 2) 56 | private String firstName; 57 | 58 | @DataField(pos = 3) 59 | private String lastName; 60 | } 61 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/domain/EmployeeWithAddress.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.domain; 2 | 3 | import org.apache.camel.dataformat.bindy.annotation.CsvRecord; 4 | import org.apache.camel.dataformat.bindy.annotation.DataField; 5 | import org.apache.camel.dataformat.bindy.annotation.Link; 6 | 7 | /** 8 | * Created by Dilip on 12/6/17. 9 | */ 10 | @CsvRecord( separator = ",",skipFirstLine=true) 11 | public class EmployeeWithAddress { 12 | 13 | //"10","Dilip","Sundarraj" 14 | @DataField(pos = 1,position = 10) 15 | private String id; 16 | 17 | @DataField(pos = 2,position = 11) 18 | private String firstName; 19 | 20 | @DataField(pos = 3,position = 12) 21 | private String lastName; 22 | 23 | @Link 24 | private Address address; 25 | 26 | public Address getAddress() { 27 | return address; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "EmployeeWithAddress{" + 33 | "id='" + id + '\'' + 34 | ", firstName='" + firstName + '\'' + 35 | ", lastName='" + lastName + '\'' + 36 | ", address=" + address + 37 | '}'; 38 | } 39 | 40 | public void setAddress(Address address) { 41 | this.address = address; 42 | } 43 | 44 | public String getFirstName() { 45 | return firstName; 46 | } 47 | 48 | public void setFirstName(String firstName) { 49 | this.firstName = firstName; 50 | } 51 | 52 | public String getLastName() { 53 | return lastName; 54 | } 55 | 56 | public void setLastName(String lastName) { 57 | this.lastName = lastName; 58 | } 59 | 60 | public String getId() { 61 | 62 | return id; 63 | } 64 | 65 | public void setId(String id) { 66 | this.id = id; 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/domain/Student.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.domain; 2 | 3 | import org.apache.camel.dataformat.bindy.annotation.KeyValuePairField; 4 | import org.apache.camel.dataformat.bindy.annotation.Message; 5 | 6 | /** 7 | * Created by Dilip on 12/26/17. 8 | */ 9 | @Message(keyValuePairSeparator = "=", pairSeparator = " ") 10 | public class Student { 11 | 12 | @KeyValuePairField(tag = 1) 13 | private String id; 14 | @KeyValuePairField(tag = 2) 15 | private String name; 16 | @KeyValuePairField(tag = 3) 17 | private String grade; 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | public void setId(String id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getGrade() { 36 | return grade; 37 | } 38 | 39 | public void setGrade(String grade) { 40 | this.grade = grade; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Student{" + 46 | "id='" + id + '\'' + 47 | ", name='" + name + '\'' + 48 | ", grade='" + grade + '\'' + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/processor/EmployeeProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 12/6/17. 7 | */ 8 | public class EmployeeProcessor implements org.apache.camel.Processor { 9 | public void process(Exchange exchange) throws Exception { 10 | System.out.println(" Body : "+exchange.getIn().getBody()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/csv/CSVMarshalRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.Employee; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; 7 | import org.apache.camel.spi.DataFormat; 8 | 9 | /** 10 | * Created by Dilip on 12/17/17. 11 | */ 12 | public class CSVMarshalRoute extends RouteBuilder { 13 | 14 | 15 | public void configure() throws Exception { 16 | 17 | DataFormat bindy = new BindyCsvDataFormat(Employee.class); 18 | 19 | from("direct:objInput") 20 | .marshal(bindy) 21 | .log("Marshaled Input : ${body} and headers are ${headers}") 22 | .to("file:data/csv/output?fileName=output.txt"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/csv/CSVMarshalWithLinkRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.EmployeeWithAddress; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/19/17. 10 | */ 11 | public class CSVMarshalWithLinkRoute extends RouteBuilder { 12 | public void configure() throws Exception { 13 | DataFormat bindy = new BindyCsvDataFormat(EmployeeWithAddress.class); 14 | 15 | from("direct:objInput") 16 | .marshal(bindy) 17 | .log("Marshaled Input : ${body} and headers are ${headers}") 18 | .to("file:data/csv/output?fileName=outputWithAddress.txt"); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/csv/CSVUnMarshalRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | 4 | import com.learncamel.domain.Employee; 5 | import com.learncamel.processor.EmployeeProcessor; 6 | import org.apache.camel.builder.RouteBuilder; 7 | import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; 8 | import org.apache.camel.spi.DataFormat; 9 | 10 | /** 11 | * Created by Dilip on 12/6/17. 12 | */ 13 | public class CSVUnMarshalRoute extends RouteBuilder { 14 | 15 | 16 | public void configure() throws Exception { 17 | 18 | DataFormat bindy = new BindyCsvDataFormat(Employee.class); 19 | //from("file:data/csv/input?fileName=file1.txt&noop=true") 20 | /*from("file:data/csv/input?fileName=file2.txt&noop=true")*/ 21 | /*from("file:data/csv/input?fileName=file3.txt&noop=true")*/ 22 | from("file:data/csv/input?fileName=file4.txt&noop=true") 23 | .unmarshal(bindy) 24 | .to("log:?level=INFO&showBody=true&showHeaders=true") 25 | .process(new EmployeeProcessor()) 26 | .to("direct:output"); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/csv/CSVUnMarshalWithLinkRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.Employee; 4 | import com.learncamel.domain.EmployeeWithAddress; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; 7 | import org.apache.camel.spi.DataFormat; 8 | 9 | /** 10 | * Created by Dilip on 12/18/17. 11 | */ 12 | public class CSVUnMarshalWithLinkRoute extends RouteBuilder{ 13 | 14 | public void configure() throws Exception { 15 | DataFormat bindy = new BindyCsvDataFormat(EmployeeWithAddress.class); 16 | 17 | from("file:data/csv/input?fileName=fileWithAddress.txt&noop=true") 18 | .unmarshal(bindy) 19 | .log("Marshaled Input : ${body} and headers are ${headers}") 20 | .to("direct:output"); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/fixedlength/FixedPositionMarshalRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/24/17. 10 | */ 11 | public class FixedPositionMarshalRoute extends RouteBuilder { 12 | 13 | public void configure() throws Exception { 14 | DataFormat bindy = new BindyFixedLengthDataFormat(EmployeeWithFixedLength.class); 15 | 16 | from("direct:input") 17 | .marshal(bindy) 18 | .log("Marshaled output is : ${body}") 19 | .to("file:data/fixedposition/output?fileName=FixedPositionFile.txt&noop=true"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/23/17. 10 | */ 11 | public class FixedPositionUnMarshalRoute extends RouteBuilder { 12 | public void configure() throws Exception { 13 | 14 | DataFormat bindy = new BindyFixedLengthDataFormat(EmployeeWithFixedLength.class); 15 | 16 | from("file:data/fixedposition/input?fileName=FixedPositionFile.txt&noop=true") 17 | .unmarshal(bindy) 18 | .to("direct:output"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteDate.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/24/17. 10 | */ 11 | public class FixedPositionUnMarshalRouteDate extends RouteBuilder { 12 | public void configure() throws Exception { 13 | 14 | DataFormat bindy = new BindyFixedLengthDataFormat(EmployeeWithFixedLength.class); 15 | 16 | from("file:data/input/fixedposition?fileName=FixedPositionFile-Date.txt&noop=true") 17 | .unmarshal(bindy) 18 | .to("direct:output"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteDelimiter.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/24/17. 10 | */ 11 | public class FixedPositionUnMarshalRouteDelimiter extends RouteBuilder { 12 | public void configure() throws Exception { 13 | DataFormat bindy = new BindyFixedLengthDataFormat(EmployeeWithFixedLength.class); 14 | 15 | from("file:data/input/fixedposition?fileName=FixedPositionFile-Delimiter.txt&noop=true") 16 | .unmarshal(bindy) 17 | .to("direct:output"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteDelimiterSalary.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/24/17. 10 | */ 11 | public class FixedPositionUnMarshalRouteDelimiterSalary extends RouteBuilder { 12 | public void configure() throws Exception { 13 | DataFormat bindy = new BindyFixedLengthDataFormat(EmployeeWithFixedLength.class); 14 | 15 | from("file:data/fixedposition/input?fileName=FixedPositionFile-Delimiter-salary.txt&noop=true") 16 | .unmarshal(bindy) 17 | .log("Unmarshaled Body is : ${body}") 18 | .to("direct:output"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/headerandfooter/HeaderAndFooterRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.headerandfooter; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.apache.camel.Processor; 5 | import org.apache.camel.builder.RouteBuilder; 6 | 7 | public class HeaderAndFooterRoute extends RouteBuilder { 8 | 9 | 10 | private final String HEADER = "(MH7000)"; 11 | private final String FOOTER = "(RRRR)"; 12 | 13 | public void configure() throws Exception { 14 | 15 | from("file:data/headerandfooter/input?fileName=samplefile&noop=true") 16 | .split((body().tokenize("(MH7000)"))) 17 | .streaming() 18 | .process(new Processor() { 19 | public void process(Exchange exchange) throws Exception { 20 | String body = (String) exchange.getIn().getBody(); 21 | if(((String) exchange.getIn().getBody()).contains("(") || ((String) exchange.getIn().getBody()).contains(")")){ 22 | body = body.replace("(",""); 23 | body = body.replace(")",""); 24 | if(!body.equals("")) 25 | body = HEADER.concat(body); 26 | body = body.replace("RRRR",FOOTER); 27 | 28 | }; 29 | exchange.getIn().setBody(body); 30 | } 31 | }) 32 | .log("Tokenized output is : ${body}") 33 | .choice() 34 | .when(body().isNotEqualTo("")) 35 | .to("file:data/headerandfooter/output?fileName=${file:name}-${date:now:yyyyMMddHHmmssSSS}"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/keyvaluepair/KeyValueMarshalRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.keyvaluepair; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/26/17. 10 | */ 11 | public class KeyValueMarshalRoute extends RouteBuilder { 12 | public void configure() throws Exception { 13 | 14 | DataFormat bindyKeyValuePairDataFormat = new BindyKeyValuePairDataFormat(Student.class); 15 | 16 | from("direct:keyValueRoute") 17 | .marshal(bindyKeyValuePairDataFormat) 18 | .log("Marshaled Message is : ${body}") 19 | .to("file:data/keyValue/output?fileName=key-value-file-output.txt"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/java/com/learncamel/routes/keyvaluepair/KeyValueUnMarshalRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.keyvaluepair; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat; 6 | import org.apache.camel.spi.DataFormat; 7 | 8 | /** 9 | * Created by Dilip on 12/26/17. 10 | */ 11 | public class KeyValueUnMarshalRoute extends RouteBuilder { 12 | 13 | public void configure() throws Exception { 14 | 15 | DataFormat bindyKeyValuePairDataFormat = new BindyKeyValuePairDataFormat(Student.class); 16 | 17 | from("file:data/keyValue/input?fileName=key-value-file1.txt&noop=true") 18 | .unmarshal(bindyKeyValuePairDataFormat) 19 | .log("UnMarshaled message is ${body}") 20 | .to("direct:output"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n 17 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/csv/CSVMarshalRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.Employee; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Dilip on 12/17/17. 12 | */ 13 | public class CSVMarshalRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RoutesBuilder createRouteBuilder(){ 17 | 18 | return new CSVMarshalRoute(); 19 | } 20 | 21 | @Test 22 | public void marhsalRouteTest(){ 23 | 24 | Employee employee = new Employee(); 25 | employee.setId("123"); 26 | employee.setFirstName("Dilip"); 27 | employee.setLastName("Sundar"); 28 | 29 | 30 | template.sendBody("direct:objInput", employee); 31 | 32 | File file = new File("data/csv/output"); 33 | assertTrue(file.isDirectory()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/csv/CSVMarshalWithLinkRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.Address; 4 | import com.learncamel.domain.Employee; 5 | import com.learncamel.domain.EmployeeWithAddress; 6 | import org.apache.camel.RoutesBuilder; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | import java.io.File; 11 | 12 | /** 13 | * Created by Dilip on 12/19/17. 14 | */ 15 | public class CSVMarshalWithLinkRouteTest extends CamelTestSupport { 16 | 17 | @Override 18 | public RoutesBuilder createRouteBuilder(){ 19 | 20 | return new CSVMarshalWithLinkRoute(); 21 | } 22 | 23 | @Test 24 | public void marshalWithLinkTest() throws InterruptedException { 25 | 26 | EmployeeWithAddress employee = new EmployeeWithAddress(); 27 | employee.setId("123"); 28 | employee.setFirstName("Dilip"); 29 | employee.setLastName("Sundar"); 30 | Address address = new Address(); 31 | address.setAddressLine("12345 ABC lane"); 32 | address.setCity("APple Valley"); 33 | address.setCountry("USA"); 34 | address.setState("MN"); 35 | address.setZip("12345"); 36 | employee.setAddress(address); 37 | 38 | 39 | 40 | template.sendBody("direct:objInput", employee); 41 | 42 | Thread.sleep(3000); 43 | File file = new File("data/csv/output/outputWithAddress.txt"); 44 | assertTrue(file.exists()); 45 | } 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/csv/CSVUnMarshalRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.Employee; 4 | import com.learncamel.routes.csv.CSVUnMarshalRoute; 5 | import org.apache.camel.Exchange; 6 | import org.apache.camel.RoutesBuilder; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Dilip on 12/6/17. 14 | */ 15 | public class CSVUnMarshalRouteTest extends CamelTestSupport{ 16 | 17 | @Override 18 | public RoutesBuilder createRouteBuilder() throws Exception { 19 | return new CSVUnMarshalRoute(); 20 | } 21 | 22 | @Test 23 | public void cvsUnmarshalRouteTest() throws InterruptedException { 24 | 25 | Exchange exchange = consumer.receive("direct:output"); 26 | 27 | Thread.sleep(5000); 28 | 29 | List employeeList = (List) exchange.getIn().getBody(); 30 | for(Employee employee1 : employeeList ){ 31 | System.out.println("Employee in test case : " + employee1); 32 | } 33 | 34 | assertEquals("01", employeeList.get(0).getId()); 35 | assertEquals("Kevin", employeeList.get(1).getFirstName()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/csv/CSVUnMarshalWithLinkRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.csv; 2 | 3 | import com.learncamel.domain.EmployeeWithAddress; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.RoutesBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Created by Dilip on 12/18/17. 11 | */ 12 | public class CSVUnMarshalWithLinkRouteTest extends CamelTestSupport { 13 | 14 | @Override 15 | public RoutesBuilder createRouteBuilder(){ 16 | 17 | return new CSVUnMarshalWithLinkRoute(); 18 | } 19 | 20 | @Test 21 | public void csvWithLinkRouteTest(){ 22 | Exchange exchange = consumer.receive("direct:output"); 23 | 24 | 25 | EmployeeWithAddress employeeWithAddress = (EmployeeWithAddress) exchange.getIn().getBody(); 26 | System.out.println(employeeWithAddress); 27 | 28 | assertEquals("USA", employeeWithAddress.getAddress().getCountry()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/fixedlength/FixedPositionMarshalRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.Employee; 4 | import com.learncamel.domain.EmployeeWithFixedLength; 5 | import org.apache.camel.Exchange; 6 | import org.apache.camel.RoutesBuilder; 7 | import org.apache.camel.test.junit4.CamelTestSupport; 8 | import org.junit.Test; 9 | 10 | import java.io.File; 11 | import java.time.LocalDate; 12 | 13 | /** 14 | * Created by Dilip on 12/24/17. 15 | */ 16 | public class FixedPositionMarshalRouteTest extends CamelTestSupport { 17 | 18 | @Override 19 | public RoutesBuilder createRouteBuilder(){ 20 | 21 | return new FixedPositionMarshalRoute(); 22 | } 23 | 24 | @Test 25 | public void positionMarshalTest() throws InterruptedException { 26 | 27 | EmployeeWithFixedLength employeeWithFixedLength = new EmployeeWithFixedLength(); 28 | employeeWithFixedLength.setId(1); 29 | employeeWithFixedLength.setName("Adam"); 30 | employeeWithFixedLength.setAge(30); 31 | employeeWithFixedLength.setJoinDate(LocalDate.now()); 32 | employeeWithFixedLength.setRole("Engineer"); 33 | 34 | template.sendBody("direct:input",employeeWithFixedLength); 35 | 36 | Thread.sleep(5000); 37 | 38 | File file = new File("data/fixedposition/output"); 39 | assertTrue(file.isDirectory()); 40 | 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteDateTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.RoutesBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.time.LocalDate; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Dilip on 12/24/17. 14 | */ 15 | public class FixedPositionUnMarshalRouteDateTest extends CamelTestSupport { 16 | 17 | @Override 18 | public RoutesBuilder createRouteBuilder(){ 19 | 20 | return new FixedPositionUnMarshalRouteDate(); 21 | } 22 | 23 | @Test 24 | public void unMarshalFixedPositionDate() throws InterruptedException { 25 | Exchange exchange = consumer.receive("direct:output"); 26 | 27 | Thread.sleep(5000); 28 | 29 | List employeeList = (List) exchange.getIn().getBody(); 30 | assertNotNull(employeeList); 31 | System.out.println(employeeList); 32 | assertEquals("dilip",employeeList.get(0).getName().trim()); 33 | LocalDate expeectedDate = LocalDate.of(2017,01,12); 34 | assertEquals(expeectedDate.getYear(),employeeList.get(0).getJoinDate().getYear()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteDelimiterSalaryTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.math.BigDecimal; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by Dilip on 12/24/17. 14 | */ 15 | public class FixedPositionUnMarshalRouteDelimiterSalaryTest extends CamelTestSupport { 16 | 17 | @Override 18 | public RouteBuilder createRouteBuilder(){ 19 | return new FixedPositionUnMarshalRouteDelimiterSalary(); 20 | } 21 | 22 | @Test 23 | public void salaryTest() throws InterruptedException { 24 | Exchange exchange = consumer.receive("direct:output"); 25 | 26 | Thread.sleep(5000); 27 | 28 | List employeeList = (List) exchange.getIn().getBody(); 29 | assertNotNull(employeeList); 30 | System.out.println(employeeList); 31 | assertEquals("dilip",employeeList.get(0).getName()); 32 | 33 | BigDecimal expectedSalary = new BigDecimal("100000.00"); 34 | assertEquals(expectedSalary, employeeList.get(0).getSalary()); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteDelimiterTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.EmployeeWithFixedLength; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.RoutesBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Dilip on 12/24/17. 13 | */ 14 | public class FixedPositionUnMarshalRouteDelimiterTest extends CamelTestSupport { 15 | 16 | @Override 17 | public RoutesBuilder createRouteBuilder(){ 18 | 19 | return new FixedPositionUnMarshalRouteDelimiter(); 20 | } 21 | 22 | @Test 23 | public void unMarshalFixedPositionDelimiter() throws InterruptedException { 24 | 25 | Exchange exchange = consumer.receive("direct:output"); 26 | 27 | Thread.sleep(5000); 28 | 29 | List employeeList = (List) exchange.getIn().getBody(); 30 | assertNotNull(employeeList); 31 | System.out.println(employeeList); 32 | assertEquals("dilip",employeeList.get(0).getName().trim()); 33 | //assertEquals(30,employeeList.get(0).getAge()); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/fixedlength/FixedPositionUnMarshalRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.fixedlength; 2 | 3 | import com.learncamel.domain.Employee; 4 | import com.learncamel.domain.EmployeeWithFixedLength; 5 | import com.learncamel.routes.csv.CSVMarshalRoute; 6 | import org.apache.camel.Exchange; 7 | import org.apache.camel.RoutesBuilder; 8 | import org.apache.camel.builder.RouteBuilder; 9 | import org.apache.camel.test.junit4.CamelTestSupport; 10 | import org.junit.Test; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by Dilip on 12/23/17. 16 | */ 17 | public class FixedPositionUnMarshalRouteTest extends CamelTestSupport{ 18 | @Override 19 | public RoutesBuilder createRouteBuilder(){ 20 | 21 | return new FixedPositionUnMarshalRoute(); 22 | } 23 | 24 | @Test 25 | public void unMarshalFixedPositionTest() throws InterruptedException { 26 | 27 | Exchange exchange = consumer.receive("direct:output"); 28 | 29 | Thread.sleep(5000); 30 | 31 | List employeeList = (List) exchange.getIn().getBody(); 32 | assertNotNull(employeeList); 33 | System.out.println(employeeList); 34 | assertEquals("dilip",employeeList.get(0).getName().trim()); 35 | //assertEquals(Local); 36 | 37 | 38 | } 39 | 40 | @Test 41 | public void unMarshalFixedPositionTest_ignoreTrailingChars() throws InterruptedException { 42 | 43 | Exchange exchange = consumer.receive("direct:output"); 44 | 45 | Thread.sleep(5000); 46 | 47 | List employeeList = (List) exchange.getIn().getBody(); 48 | assertNotNull(employeeList); 49 | System.out.println(employeeList); 50 | assertEquals("dilip",employeeList.get(0).getName()); 51 | 52 | 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/headerandfooter/HeaderAndFooterRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.headerandfooter; 2 | 3 | import com.learncamel.routes.fixedlength.FixedPositionUnMarshalRouteDate; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | public class HeaderAndFooterRouteTest extends CamelTestSupport { 11 | 12 | 13 | private String destinationDirectory = "data/headerandfooter/output"; 14 | @Override 15 | public void doPreSetup(){ 16 | 17 | File file = new File(destinationDirectory); 18 | 19 | if(file.exists()){ 20 | for(File file1 : file.listFiles()){ 21 | file1.delete(); 22 | } 23 | 24 | file.delete(); 25 | 26 | System.out.println("Directory and files are deleted."); 27 | } 28 | 29 | 30 | 31 | } 32 | 33 | @Override 34 | public RoutesBuilder createRouteBuilder(){ 35 | 36 | return new HeaderAndFooterRoute(); 37 | } 38 | 39 | @Test 40 | public void splittingFiles() throws InterruptedException { 41 | Thread.sleep(5000); 42 | 43 | File file = new File("data/headerandfooter/output"); 44 | assertTrue(file.isDirectory()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/keyvaluepair/KeyValueMarshalRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.keyvaluepair; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Created by Dilip on 12/26/17. 12 | */ 13 | public class KeyValueMarshalRouteTest extends CamelTestSupport { 14 | 15 | @Override 16 | public RoutesBuilder createRouteBuilder(){ 17 | 18 | return new KeyValueMarshalRoute(); 19 | } 20 | 21 | @Test 22 | public void marshalKeyValueTest() throws InterruptedException { 23 | 24 | Student student = new Student(); 25 | student.setGrade("12"); 26 | student.setId("1"); 27 | student.setName("Dilip"); 28 | 29 | template.sendBody("direct:keyValueRoute",student); 30 | 31 | Thread.sleep(3000); 32 | File file = new File("data/keyValue/output/key-value-file-output.txt"); 33 | assertTrue(file.isFile()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /learncamel-transform-bindy/src/test/java/com/learncamel/routes/keyvaluepair/KeyValueUnMarshalRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.routes.keyvaluepair; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.RoutesBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Dilip on 12/26/17. 13 | */ 14 | public class KeyValueUnMarshalRouteTest extends CamelTestSupport { 15 | 16 | @Override 17 | public RoutesBuilder createRouteBuilder(){ 18 | 19 | return new KeyValueUnMarshalRoute(); 20 | } 21 | 22 | @Test 23 | public void unMarshalKeyValuePair() throws InterruptedException { 24 | 25 | Exchange exchange = consumer.receive("direct:output"); 26 | 27 | Thread.sleep(5000); 28 | 29 | List students = (List) exchange.getIn().getBody(); 30 | 31 | System.out.println(students); 32 | 33 | assertEquals("dilip", students.get(0).getName()); 34 | assertEquals("kevin", students.get(1).getName()); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /learncamel-transform/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | *.log 18 | 19 | ### NetBeans ### 20 | nbproject/private/ 21 | build/ 22 | nbbuild/ 23 | dist/ 24 | nbdist/ 25 | .nb-gradle/ -------------------------------------------------------------------------------- /learncamel-transform/data/input/input.txt: -------------------------------------------------------------------------------- 1 | 123,dilip,12JAN2017 2 | 456,adam,12JAN2017 -------------------------------------------------------------------------------- /learncamel-transform/data/output/output.txt: -------------------------------------------------------------------------------- 1 | 123:dilip:12JAN2017 2 | 456:adam:12JAN2017 3 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/bean/CamelBean.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.bean; 2 | 3 | /** 4 | * Created by Dilip on 6/14/17. 5 | */ 6 | public class CamelBean { 7 | 8 | public String map(String input){ 9 | 10 | String newBody = input.replace(",", "*"); 11 | 12 | return newBody; 13 | 14 | } 15 | 16 | public String map2(String input){ 17 | 18 | String newBody = input.replace(",", "~"); 19 | 20 | return newBody; 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/domain/Employee.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.domain; 2 | 3 | import javax.xml.bind.annotation.XmlRootElement; 4 | 5 | /** 6 | * Created by Dilip on 6/17/17. 7 | */ 8 | public class Employee { 9 | 10 | private String name; 11 | 12 | @Override 13 | public String toString() { 14 | return "Employee{" + 15 | "name='" + name + '\'' + 16 | ", id='" + id + '\'' + 17 | ", joinDate='" + joinDate + '\'' + 18 | '}'; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public void setId(String id) { 34 | this.id = id; 35 | } 36 | 37 | public String getJoinDate() { 38 | return joinDate; 39 | } 40 | 41 | public void setJoinDate(String joinDate) { 42 | this.joinDate = joinDate; 43 | } 44 | 45 | private String id; 46 | private String joinDate; 47 | } 48 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/domain/Student.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.domain; 2 | 3 | /** 4 | * Created by Dilip on 12/19/17. 5 | */ 6 | public class Student { 7 | 8 | 9 | private int id; 10 | private String name; 11 | private String phonenumber; 12 | 13 | public int getId() { 14 | return id; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return "Student{" + 20 | "id=" + id + 21 | ", name='" + name + '\'' + 22 | ", phonenumber='" + phonenumber + '\'' + 23 | '}'; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getPhonenumber() { 39 | return phonenumber; 40 | } 41 | 42 | public void setPhonenumber(String phonenumber) { 43 | this.phonenumber = phonenumber; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/processor/CamelDirectExampleProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import org.apache.camel.Exchange; 4 | 5 | /** 6 | * Created by Dilip on 6/10/17. 7 | */ 8 | public class CamelDirectExampleProcessor implements org.apache.camel.Processor { 9 | 10 | 11 | public void process(Exchange exchange) throws Exception { 12 | 13 | try{ 14 | String oldValue = (String) exchange.getIn().getBody(); 15 | 16 | System.out.println("Old Value is : " + oldValue); 17 | 18 | String newValue = oldValue.replace(",", ":"); 19 | 20 | System.out.println("New Value is : " + newValue); 21 | 22 | exchange.getIn().setBody(newValue); 23 | 24 | }catch (Exception e){ 25 | System.out.println("Exception in processor is : " + e); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/processor/CamelFileExampleProcessor.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import org.apache.camel.Exchange; 4 | import org.apache.camel.component.file.GenericFile; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.File; 8 | import java.io.FileReader; 9 | 10 | /** 11 | * Created by Dilip on 6/12/17. 12 | */ 13 | public class CamelFileExampleProcessor implements org.apache.camel.Processor { 14 | 15 | String newValue=""; 16 | private String readLine; 17 | 18 | public void process(Exchange exchange) throws Exception { 19 | 20 | GenericFile file = (GenericFile) exchange.getIn().getBody(); 21 | String readLine=null; 22 | 23 | if(file!=null){ 24 | 25 | FileReader file1 = new FileReader(file.getFile()); 26 | BufferedReader reader = new BufferedReader(file1); 27 | 28 | while((readLine =reader.readLine()) !=null){ 29 | System.out.println("Read line is : " + readLine); 30 | 31 | String oldValue = readLine; 32 | 33 | System.out.println("Old Value is : " + oldValue); 34 | 35 | newValue = newValue.concat(oldValue.replace(",", ":")).concat("\n"); 36 | 37 | System.out.println("New Value is : " + newValue); 38 | 39 | exchange.getIn().setBody(newValue); 40 | } 41 | 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/processor/CustomProcessorXStream.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.processor; 2 | 3 | import com.learncamel.domain.Employee; 4 | import org.apache.camel.Exchange; 5 | 6 | import java.util.StringTokenizer; 7 | 8 | /** 9 | * Created by Dilip on 6/17/17. 10 | */ 11 | public class CustomProcessorXStream implements org.apache.camel.Processor { 12 | 13 | public void process(Exchange exchange) throws Exception { 14 | String newBody = exchange.getIn().getBody(String.class); 15 | StringTokenizer tokenizer = new StringTokenizer(newBody, ","); 16 | Employee employee = new Employee(); 17 | while (tokenizer.hasMoreElements()){ 18 | employee.setName((String) tokenizer.nextElement()); 19 | employee.setId((String) tokenizer.nextElement()); 20 | employee.setJoinDate((String) tokenizer.nextElement()); 21 | } 22 | 23 | exchange.getIn().setBody(employee); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/bean/CamelModifyBeanRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.bean; 2 | 3 | import com.learncamel.bean.CamelBean; 4 | import org.apache.camel.builder.RouteBuilder; 5 | 6 | /** 7 | * Created by Dilip on 6/14/17. 8 | */ 9 | public class CamelModifyBeanRoute extends RouteBuilder { 10 | 11 | public void configure() throws Exception { 12 | 13 | from("process:beanInput") 14 | .bean(new CamelBean()) 15 | //.bean(new CamelBean(), "map") 16 | .log("Received Message is ${body} and Headers are ${headers}") 17 | .to("mock:output"); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/gson/MarshalUsingGson.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.gson; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.component.gson.GsonDataFormat; 6 | 7 | /** 8 | * Created by Dilip on 12/20/17. 9 | */ 10 | public class MarshalUsingGson extends RouteBuilder { 11 | public void configure() throws Exception { 12 | GsonDataFormat format = new GsonDataFormat(Student.class); 13 | 14 | from("direct:marshalGSON") 15 | .log("Received Message is ${body} and Headers are ${headers}") 16 | .marshal(format) 17 | .log("Received Message is ${body} and Headers are ${headers}");// 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/gson/UnMarshalUsingGson.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.gson; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.component.gson.GsonDataFormat; 6 | 7 | /** 8 | * Created by Dilip on 12/19/17. 9 | */ 10 | public class UnMarshalUsingGson extends RouteBuilder { 11 | public void configure() throws Exception { 12 | GsonDataFormat format = new GsonDataFormat(Student.class); 13 | from("direct:unMarshalGSON") 14 | .log("Received Message is ${body} and Headers are ${headers}") 15 | .unmarshal(format) 16 | .log("Converted Message is ${body} and Headers are ${headers}"); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/process/CamelModifyDirectProcessorRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.process; 2 | 3 | import com.learncamel.processor.CamelDirectExampleProcessor; 4 | import org.apache.camel.builder.RouteBuilder; 5 | 6 | /** 7 | * Created by Dilip on 6/10/17. 8 | */ 9 | public class CamelModifyDirectProcessorRoute extends RouteBuilder { 10 | 11 | 12 | public void configure() throws Exception { 13 | 14 | from("process:processorInput") 15 | .process(new CamelDirectExampleProcessor()) 16 | .log("Received Message is ${body} and Headers are ${headers}") 17 | //.to("file:data/output?fileName=output.txt"); 18 | .to("mock:output"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/process/CamelModifyFileProcessorRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.process; 2 | 3 | import com.learncamel.processor.CamelFileExampleProcessor; 4 | import org.apache.camel.builder.RouteBuilder; 5 | 6 | /** 7 | * Created by Dilip on 6/12/17. 8 | */ 9 | public class CamelModifyFileProcessorRoute extends RouteBuilder { 10 | public void configure() throws Exception { 11 | from("file:data/input?noop=true") 12 | .process(new CamelFileExampleProcessor()) 13 | .log("Received Message is ${body} and Headers are ${headers}") 14 | .to("file:data/output?fileName=output.txt") 15 | .to("mock:output"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/transform/CamelModifyTransformRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.transform; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | 5 | /** 6 | * Created by Dilip on 6/13/17. 7 | */ 8 | public class CamelModifyTransformRoute extends RouteBuilder { 9 | 10 | public void configure() throws Exception { 11 | 12 | from("process:transformInput") 13 | .transform(body().regexReplaceAll(",","*")) 14 | .to("mock:output"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/xml2json/XML2JSONRoute.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.xml2json; 2 | 3 | import org.apache.camel.Route; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; 6 | 7 | /** 8 | * Created by Dilip on 6/17/17. 9 | */ 10 | public class XML2JSONRoute extends RouteBuilder { 11 | 12 | public void configure() throws Exception { 13 | 14 | from("direct:marshalEmployeexml2json") 15 | .to("log:?level=INFO&showBody=true") 16 | .marshal().xmljson() 17 | .to("log:?level=INFO&showBody=true"); 18 | 19 | 20 | final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat(); 21 | xmlJsonFormat.setRootName("Employee"); 22 | 23 | from("direct:unMarshalEmployeejson2xml") 24 | //.unmarshal().xmljson() 25 | .unmarshal(xmlJsonFormat) 26 | .to("log:?level=INFO&showBody=true"); 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/xmlxstream/MarshalUsingXStream.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.xmlxstream; 2 | 3 | import com.learncamel.domain.Employee; 4 | import com.learncamel.processor.CustomProcessorXStream; 5 | import org.apache.camel.builder.RouteBuilder; 6 | import org.apache.camel.dataformat.xstream.XStreamDataFormat; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * Created by Dilip on 6/17/17. 13 | */ 14 | public class MarshalUsingXStream extends RouteBuilder { 15 | 16 | 17 | 18 | public void configure() throws Exception { 19 | 20 | from("direct:csvinput") 21 | .process(new CustomProcessorXStream()) 22 | // .marshal().xstream() 23 | .marshal(populateStreamDef()) 24 | .to("log:?level=INFO&showBody=true") 25 | .to("mock:output"); 26 | } 27 | 28 | private XStreamDataFormat populateStreamDef() { 29 | 30 | XStreamDataFormat xstreamDefinition = new XStreamDataFormat(); 31 | 32 | Map aliases = new HashMap(); 33 | 34 | aliases.put("employee", Employee.class.getName()); 35 | 36 | xstreamDefinition.setAliases(aliases); 37 | 38 | return xstreamDefinition; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/java/com/learncamel/route/xmlxstream/UnMarshalUsingXStream.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.xmlxstream; 2 | 3 | import com.learncamel.domain.Employee; 4 | import org.apache.camel.builder.RouteBuilder; 5 | import org.apache.camel.dataformat.xstream.XStreamDataFormat; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * Created by Dilip on 6/17/17. 12 | */ 13 | public class UnMarshalUsingXStream extends RouteBuilder { 14 | 15 | public void configure() throws Exception { 16 | 17 | Map reference = new HashMap(); 18 | reference.put("employee", Employee.class.getName()); 19 | 20 | XStreamDataFormat xstreamDataFormat = new XStreamDataFormat(); 21 | xstreamDataFormat.setAliases(reference); 22 | xstreamDataFormat.setPermissions(Employee.class.getName()); //Need permission on this class otherwise 23 | // it will through the com.thoughtworks.xstream.security.ForbiddenClassException: com.learncamel.transformXML.xstream.Employee 24 | 25 | 26 | from("direct:xmlinput") 27 | .unmarshal(xstreamDataFormat) 28 | .to("log:?level=INFO&showBody=true") 29 | .to("mock:output"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /learncamel-transform/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Root logger option 2 | log4j.rootLogger=INFO, file, console 3 | 4 | log4j.logger.com.javarticles=INFO, file 5 | 6 | # Direct log messages to a log file 7 | log4j.appender.file=org.apache.log4j.FileAppender 8 | log4j.appender.file.File=camel-transofrm.log 9 | log4j.appender.file.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.file.layout.ConversionPattern=%d | %p | %F %L | %m%n 11 | 12 | # Direct log messages to stdout 13 | log4j.appender.console=org.apache.log4j.ConsoleAppender 14 | log4j.appender.console.Target=System.out 15 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 16 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm}| %p | %F %L | %m%n -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/CamelModifyDirectProcessorRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.route.process.CamelModifyDirectProcessorRoute; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Created by Dilip on 6/11/17. 11 | */ 12 | public class CamelModifyDirectProcessorRouteTest extends CamelTestSupport { 13 | 14 | @Override 15 | public RoutesBuilder createRouteBuilder() throws Exception { 16 | return new CamelModifyDirectProcessorRoute(); 17 | } 18 | 19 | /** 20 | * This test case will check the content using requestBody() method. 21 | */ 22 | @Test 23 | public void processorTest() { 24 | 25 | String expected = "123:dilip:12JAN2017"; 26 | 27 | String output = (String) template.requestBody("process:processorInput","123,dilip,12JAN2017" ); 28 | 29 | System.out.println("output : " + output); 30 | assertEquals(expected , output); 31 | 32 | } 33 | 34 | /** 35 | * This test case will check the content using Mock() method. 36 | */ 37 | @Test 38 | public void processorTestUsingMock() throws InterruptedException { 39 | 40 | String expected = "123:dilip:12JAN2017"; 41 | MockEndpoint mock = getMockEndpoint("mock:output"); 42 | mock.expectedBodiesReceived(expected); 43 | 44 | 45 | String output = (String) template.requestBody("process:processorInput","123,dilip,12JAN2017" ); 46 | 47 | System.out.println("output : " + output); 48 | assertMockEndpointsSatisfied(); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/CamelModifyFileProcessorRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route; 2 | 3 | import com.learncamel.route.process.CamelModifyFileProcessorRoute; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * Created by Dilip on 6/12/17. 13 | */ 14 | public class CamelModifyFileProcessorRouteTest extends CamelTestSupport{ 15 | 16 | @Override 17 | public RoutesBuilder createRouteBuilder() throws Exception { 18 | return new CamelModifyFileProcessorRoute(); 19 | } 20 | 21 | @Test 22 | public void processorTest() throws InterruptedException { 23 | 24 | String expected="123:dilip:12JAN2017\n" + 25 | "456:adam:12JAN2017\n"; 26 | MockEndpoint mock = getMockEndpoint("mock:output"); 27 | mock.expectedBodiesReceived(expected); 28 | 29 | Thread.sleep(5000); 30 | 31 | File file = new File("data/output"); 32 | 33 | assertTrue(file.isDirectory()); 34 | 35 | assertEquals(1,file.listFiles().length); 36 | 37 | assertMockEndpointsSatisfied(); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/bean/CamelModifyBeanRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.bean; 2 | 3 | import com.learncamel.route.transform.CamelModifyTransformRoute; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by Dilip on 6/14/17. 10 | */ 11 | public class CamelModifyBeanRouteTest extends CamelTestSupport { 12 | 13 | @Override 14 | public RoutesBuilder createRouteBuilder() throws Exception { 15 | return new CamelModifyBeanRoute(); 16 | } 17 | 18 | @Test 19 | public void beanTest(){ 20 | String expected = "123*dilip*12JAN2017"; 21 | String output = (String) template.requestBody("process:beanInput","123,dilip,12JAN2017" ); 22 | System.out.println("output : "+ output); 23 | 24 | assertEquals(expected,output); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/gson/MarshalGsonTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.gson; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.Exchange; 5 | import org.apache.camel.RoutesBuilder; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Created by Dilip on 12/20/17. 11 | */ 12 | public class MarshalGsonTest extends CamelTestSupport { 13 | 14 | @Override 15 | public RoutesBuilder createRouteBuilder() throws Exception { 16 | return new MarshalUsingGson(); 17 | } 18 | 19 | @Test 20 | public void marshalUsingGson(){ 21 | Student student=new Student(); 22 | student.setId(1); 23 | student.setName("Dilip"); 24 | student.setPhonenumber("2183984979"); 25 | String expected = "{\"id\":1,\"name\":\"Dilip\",\"phonenumber\":\"2183984979\"}"; 26 | 27 | String studentJson = (String) template.requestBody("direct:marshalGSON", student,String.class); 28 | System.out.println("studentJson : " + studentJson); 29 | assertEquals(expected,studentJson); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/gson/UnMarshalUsingGsonTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.gson; 2 | 3 | import com.learncamel.domain.Student; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by Dilip on 12/19/17. 10 | */ 11 | public class UnMarshalUsingGsonTest extends CamelTestSupport { 12 | 13 | @Override 14 | public RoutesBuilder createRouteBuilder() throws Exception { 15 | return new UnMarshalUsingGson(); 16 | } 17 | 18 | @Test 19 | public void UnmarshalGsonTest(){ 20 | String jsonInput = "{ \"id\":\"1\" ,\"name\":\"sudheer\",\"phonenumber\" :\"123456789\"}"; 21 | 22 | Student student = (Student) template.requestBody("direct:unMarshalGSON", jsonInput); 23 | 24 | assertEquals(1,student.getId()); 25 | 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/transform/CamelModifyTransformRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.transform; 2 | 3 | import org.apache.camel.RoutesBuilder; 4 | import org.apache.camel.component.mock.MockEndpoint; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by Dilip on 6/13/17. 10 | */ 11 | public class CamelModifyTransformRouteTest extends CamelTestSupport { 12 | 13 | @Override 14 | public RoutesBuilder createRouteBuilder() throws Exception { 15 | return new CamelModifyTransformRoute(); 16 | } 17 | 18 | @Test 19 | public void transformTest(){ 20 | 21 | 22 | String expected = "123*dilip*12JAN2017"; 23 | String output = (String) template.requestBody("process:transformInput","123,dilip,12JAN2017" ); 24 | System.out.println("output : "+ output); 25 | 26 | assertEquals(expected,output); 27 | } 28 | 29 | @Test 30 | public void transformTest_Uisng_Mock() throws InterruptedException { 31 | 32 | String expected = "123*dilip*12JAN2017"; 33 | MockEndpoint mock = getMockEndpoint("mock:output"); 34 | mock.expectedBodiesReceived(expected); 35 | 36 | 37 | 38 | template.sendBody("process:transformInput","123,dilip,12JAN2017" ); 39 | 40 | assertMockEndpointsSatisfied(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/xml2json/XML2JSONRouteTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.xml2json; 2 | 3 | import org.apache.camel.builder.RouteBuilder; 4 | import org.apache.camel.test.junit4.CamelTestSupport; 5 | import org.junit.Test; 6 | 7 | /** 8 | * Created by Dilip on 6/17/17. 9 | */ 10 | public class XML2JSONRouteTest extends CamelTestSupport { 11 | 12 | @Override 13 | protected RouteBuilder createRouteBuilder() throws Exception { 14 | return new XML2JSONRoute(); 15 | } 16 | 17 | @Test 18 | public void marshalEmployeeJSON2XML(){ 19 | 20 | String expected = "{\"id\":\"123 \",\"name\":\"ABC\",\"type\":\"senior\"}"; 21 | String request = "\r\n" + 22 | "123 ABCsenior\r\n"; 23 | 24 | final String response = template.requestBody("direct:marshalEmployeexml2json", request, String.class); 25 | System.out.println("response is : " + response); 26 | 27 | assertEquals(expected, response); 28 | 29 | } 30 | 31 | @Test 32 | public void unMarshalEmployeeJSON2XML(){ 33 | 34 | final String request = "{\"name\":\"ABC\",\"id\":\"123 \",\"type\":\"senior\"}"; 35 | 36 | final String response = template.requestBody("direct:unMarshalEmployeejson2xml", request, String.class); 37 | System.out.println("response is : " + response); 38 | String expected = "\r\n" + 39 | "123 ABCsenior\r\n"; 40 | assertEquals(expected, response); 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/xmlxstream/MarshalUsingXStreamTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.xmlxstream; 2 | 3 | import org.apache.camel.RoutesBuilder; 4 | import org.apache.camel.component.mock.MockEndpoint; 5 | import org.apache.camel.test.junit4.CamelTestSupport; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Created by Dilip on 6/17/17. 10 | */ 11 | public class MarshalUsingXStreamTest extends CamelTestSupport { 12 | 13 | @Override 14 | public RoutesBuilder createRouteBuilder() throws Exception { 15 | return new MarshalUsingXStream(); 16 | } 17 | 18 | @Test 19 | public void marshalXstreamTest() throws InterruptedException { 20 | 21 | String expected = "dilip12301APR2017"; 22 | MockEndpoint mock = getMockEndpoint("mock:output"); 23 | mock.expectedBodiesReceived(expected); 24 | 25 | template.sendBody("direct:csvinput", "dilip,123,01APR2017"); 26 | 27 | assertMockEndpointsSatisfied(); 28 | 29 | } 30 | 31 | @Test 32 | public void marshalXstreamCustomXmLlTest() throws InterruptedException { 33 | 34 | String expected = "dilip12301APR2017"; 35 | MockEndpoint mock = getMockEndpoint("mock:output"); 36 | mock.expectedBodiesReceived(expected); 37 | 38 | template.sendBody("direct:csvinput", "dilip,123,01APR2017"); 39 | 40 | assertMockEndpointsSatisfied(); 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /learncamel-transform/src/test/java/com/learncamel/route/xmlxstream/UnMarshalUsingXStreamTest.java: -------------------------------------------------------------------------------- 1 | package com.learncamel.route.xmlxstream; 2 | 3 | import com.learncamel.domain.Employee; 4 | import org.apache.camel.RoutesBuilder; 5 | import org.apache.camel.component.mock.MockEndpoint; 6 | import org.apache.camel.test.junit4.CamelTestSupport; 7 | import org.junit.Test; 8 | 9 | /** 10 | * Created by Dilip on 6/17/17. 11 | */ 12 | public class UnMarshalUsingXStreamTest extends CamelTestSupport { 13 | 14 | @Override 15 | public RoutesBuilder createRouteBuilder() throws Exception { 16 | return new UnMarshalUsingXStream(); 17 | } 18 | 19 | @Test 20 | public void unMarshalTest() throws InterruptedException { 21 | 22 | Employee employee = new Employee(); 23 | employee.setName("Daniel"); 24 | employee.setId("123"); 25 | employee.setJoinDate("01APR2017"); 26 | MockEndpoint mock = getMockEndpoint("mock:output"); 27 | mock.expectedBodiesReceived(employee.toString()); 28 | template.sendBody("direct:xmlinput", " Daniel12301APR2017"); 29 | 30 | assertMockEndpointsSatisfied(); 31 | 32 | } 33 | 34 | } 35 | --------------------------------------------------------------------------------