From d1529ddaacb34686f0940d28a745728f89f76d73 Mon Sep 17 00:00:00 2001 From: Khaled Janania Date: Thu, 4 Oct 2018 13:34:10 -0400 Subject: [PATCH 1/3] Adding some files for testing and cleanup --- .../features/pom.xml | 73 ---- .../src/main/filtered-resources/features.xml | 10 - .../parent/pom.xml | 400 ++++++++---------- .../routing/pom.xml | 41 ++ .../src/main/java/org/acme/Application.java | 13 + .../config/CustomerDbRouteProperties.java | 10 + .../config/CustomerLoadRouteProperties.java | 46 ++ .../CustomerTransformRouteProperties.java | 27 ++ .../CustomerRestClientRouteProperties.java | 28 ++ .../CustomerRestServerRouteProperties.java | 28 ++ .../ws/CustomerWsClientRouteProperties.java | 28 ++ .../ws/CustomerWsServerRouteProperties.java | 28 ++ .../java/org/acme/routes/CustomerDbRoute.java | 28 ++ .../org/acme/routes/CustomerLoadRoute.java | 36 ++ .../acme/routes/CustomerTransformRoute.java | 74 ++++ .../routes/rest/CustomerRestClientRoute.java | 43 ++ .../routes/rest/CustomerRestServerRoute.java | 39 ++ .../acme/routes/ws/CustomerWsClientRoute.java | 28 ++ .../acme/routes/ws/CustomerWsServerRoute.java | 28 ++ .../org/fuse/usecase/AccountAggregator.java | 9 + .../fuse/usecase/service/CustomerRest.java | 5 +- .../usecase/service/CustomerRestImpl.java | 3 +- .../META-INF/spring/camel-context.xml | 20 +- .../main/resources/META-INF/spring/test.xml | 16 + .../java/org/fuse/usecase/CxfRestClient.java | 7 +- 25 files changed, 748 insertions(+), 320 deletions(-) delete mode 100644 code/01_file-split-and-transform-sb/features/pom.xml delete mode 100644 code/01_file-split-and-transform-sb/features/src/main/filtered-resources/features.xml create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/Application.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerTransformRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestClientRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestServerRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsClientRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsServerRouteProperties.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerTransformRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java create mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml diff --git a/code/01_file-split-and-transform-sb/features/pom.xml b/code/01_file-split-and-transform-sb/features/pom.xml deleted file mode 100644 index f985428..0000000 --- a/code/01_file-split-and-transform-sb/features/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - 4.0.0 - - - org.fuse.usecase1 - parent - 1.0 - ../parent/pom.xml - - - features - Fuse :: Use Case 1 :: Features - - pom - - - - - - ${pom.basedir}/src/main/filtered-resources - true - - **/* - - - - - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin.version} - - - filter - generate-resources - - resources - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - ${build-helper-maven-plugin.version} - - - attach-artifacts - package - - attach-artifact - - - - - target/classes/features.xml - xml - features - - - - - - - - - - \ No newline at end of file diff --git a/code/01_file-split-and-transform-sb/features/src/main/filtered-resources/features.xml b/code/01_file-split-and-transform-sb/features/src/main/filtered-resources/features.xml deleted file mode 100644 index eb8ca65..0000000 --- a/code/01_file-split-and-transform-sb/features/src/main/filtered-resources/features.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - camel - camel-bindy - camel-jackson - camel-dozer - mvn:org.fuse.usecase1/routing/${project.version} - - \ No newline at end of file diff --git a/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml b/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml index d9652b8..6aa206a 100644 --- a/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml +++ b/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml @@ -1,220 +1,180 @@ - - - 4.0.0 - - project - org.fuse.usecase2 - 1.0 - - - parent - 1.0 - Fuse :: Use Case 2 :: Parent - pom - - - - 6.2.1.redhat-084 - - - 2.15.1.redhat-621084 - 2.15.1.redhat-621084 - - - 1.9.1 - 2.3.2 - 2.5 - 2.19.1 - 2.3.1 - 2.3.7 - 1.2.0.redhat-621084 - - - * - - - - - - - - - org.jboss.fuse.bom - jboss-fuse-parent - ${jboss.fuse.bom.version} - pom - import - - - org.apache.camel - camel-parent - ${camel.version} - pom - import - - - - - - - - org.apache.camel - camel-core - - - org.apache.camel - camel-spring - - - org.apache.camel - camel-cxf - - - org.apache.camel - camel-dozer - - - org.apache.camel - camel-jackson - - - org.apache.camel - camel-sql - - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - log4j - log4j - - - - - - install - - - - - org.apache.camel - camel-maven-plugin - ${camel.version} - - - org.apache.felix - maven-bundle-plugin - ${felix-maven-plugin.version} - - - io.fabric8 - fabric8-maven-plugin - ${fabric8-plugin.version} - - - org.codehaus.mojo - build-helper-maven-plugin - ${build-helper-maven-plugin.version} - - - org.apache.maven.plugins - maven-resources-plugin - ${maven-resources-plugin.version} - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire.version} - - - - - - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.7 - 1.7 - - - - org.apache.felix - maven-bundle-plugin - ${felix-maven-plugin.version} - true - - - ${project.artifactId} - ${osgi-import-package} - ${osgi-private-package} - ${osgi-export-package} - ${osgi-dynamic-package} - - - - - - - - - fusesource-public-repository - FuseSource Release Repository - http://repository.jboss.org/nexus/content/repositories/fs-public/ - - - jboss-public-repository - JBoss.org Public Maven Repository Group - http://repository.jboss.org/nexus/content/groups/public-jboss/ - - - jboss-fuse-ea - http://repository.jboss.org/nexus/content/groups/ea - - - jboss-releases - JBoss.org Fuse Releases - http://repository.jboss.org/nexus/content/repositories/fs-releases/ - - - Maven Central - http://repo1.maven.org/maven2/ - - - Tech Preview - http://maven.repository.redhat.com/techpreview/all - - - - - fusesource-public-repository - FuseSource Release Repository - http://repository.jboss.org/nexus/content/repositories/fs-public/ - - - jboss-public-repository-group - JBoss.org Public Maven Repository Group - http://repository.jboss.org/nexus/content/groups/public-jboss/ - - - jboss-fuse-releases - JBoss.org Fuse Releases - http://repository.jboss.org/nexus/content/repositories/fs-releases - - - jboss-fuse-ea - http://repository.jboss.org/nexus/content/groups/ea - - - Tech Preview - http://maven.repository.redhat.com/techpreview/all - - - + + + 4.0.0 + + project + org.fuse.usecase2 + 1.0 + + + parent + 1.0 + Fuse :: Use Case 2 :: Parent + pom + + + + 7.1.0.fuse-710019-redhat-00002 + + 3.0.0 + 3.8.0 + 3.1.0 + 2.19.1 + 2.3.1 + 2.8.11.redhat-1 + 1.4.197 + + + + + + org.jboss.redhat-fuse + fuse-springboot-bom + ${fuse.version} + pom + import + + + org.springframework.boot + spring-boot-starter-test + 1.5.13.RELEASE + + + com.h2database + h2 + ${h2-driver.version} + + + + + + + + + + + + + + org.jboss.redhat-fuse + spring-boot-maven-plugin + ${fuse.version} + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire.version} + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + + + + + org.apache.camel + camel-core + + + org.apache.camel + camel-spring + + + org.apache.camel + camel-cxf + + + org.apache.camel + camel-dozer + + + org.apache.camel + camel-jackson + + + org.apache.camel + camel-sql + + + + org.slf4j + slf4j-api + + + log4j + log4j + + + + + + + + fusesource-public-repository + FuseSource Release Repository + http://repository.jboss.org/nexus/content/repositories/fs-public/ + + + jboss-public-repository + JBoss.org Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public-jboss/ + + + jboss-fuse-ea + http://repository.jboss.org/nexus/content/groups/ea + + + jboss-releases + JBoss.org Fuse Releases + http://repository.jboss.org/nexus/content/repositories/fs-releases/ + + + Maven Central + http://repo1.maven.org/maven2/ + + + Tech Preview + http://maven.repository.redhat.com/techpreview/all + + + + + fusesource-public-repository + FuseSource Release Repository + http://repository.jboss.org/nexus/content/repositories/fs-public/ + + + jboss-public-repository-group + JBoss.org Public Maven Repository Group + http://repository.jboss.org/nexus/content/groups/public-jboss/ + + + jboss-fuse-releases + JBoss.org Fuse Releases + http://repository.jboss.org/nexus/content/repositories/fs-releases + + + jboss-fuse-ea + http://repository.jboss.org/nexus/content/groups/ea + + + Tech Preview + http://maven.repository.redhat.com/techpreview/all + + + diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml b/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml index e1d39d9..d43abff 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml +++ b/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml @@ -19,6 +19,34 @@ org.apache.camel camel-spring-boot-starter + + org.apache.cxf + cxf-rt-transports-http-jetty + + + + + + + + + + + + + + + + + + + + + + + org.apache.camel + camel-cxf + org.apache.camel camel-bindy @@ -31,6 +59,19 @@ com.fasterxml.jackson.core jackson-databind + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + + + + + + + + com.h2database + h2 + diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/Application.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/Application.java new file mode 100644 index 0000000..dacb9e3 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/Application.java @@ -0,0 +1,13 @@ +package org.acme; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; + +@SpringBootApplication +@ImportResource("classpath:META-INF/spring/camel-context.xml") +public class Application { + public static void main(String... args) { + SpringApplication.run(org.acme.Application.class, args); + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java new file mode 100644 index 0000000..0547c9d --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java @@ -0,0 +1,10 @@ +package org.acme.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.db") +public class CustomerDbRouteProperties { + +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java new file mode 100644 index 0000000..c689557 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java @@ -0,0 +1,46 @@ +package org.acme.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.load") +public class CustomerLoadRouteProperties { + private String input = "file://src/data/outbox?noop=true"; + private String restEndpoint = "direct:callRestEndpoint"; + private String wsEndpoint = "direct:callWsEndpoint"; + private String output = "direct:insertDb"; + + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getRestEndpoint() { + return restEndpoint; + } + + public void setRestEndpoint(String restEndpoint) { + this.restEndpoint = restEndpoint; + } + + public String getWsEndpoint() { + return wsEndpoint; + } + + public void setWsEndpoint(String wsEndpoint) { + this.wsEndpoint = wsEndpoint; + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerTransformRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerTransformRouteProperties.java new file mode 100644 index 0000000..9b30240 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerTransformRouteProperties.java @@ -0,0 +1,27 @@ +package org.acme.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.transform") +public class CustomerTransformRouteProperties { + private String input = "file://src/data/inbox?fileName=customers.csv&noop=true"; + private String output = "file://src/data/outbox?fileName=account-${property.CamelSplitIndex}.json"; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestClientRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestClientRouteProperties.java new file mode 100644 index 0000000..061bf95 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestClientRouteProperties.java @@ -0,0 +1,28 @@ +package org.acme.config.rest; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.rest") +public class CustomerRestClientRouteProperties { + private String input = "direct:callRestEndpoint"; + + private String output = "cxfrs:bean:customerRestServiceClient"; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestServerRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestServerRouteProperties.java new file mode 100644 index 0000000..2d05aca --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/rest/CustomerRestServerRouteProperties.java @@ -0,0 +1,28 @@ +package org.acme.config.rest; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.rest") +public class CustomerRestServerRouteProperties { + private String input = "cxfrs:bean:customerRestService"; + + private String output = "cxfrs:bean:customerRestServiceClient"; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsClientRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsClientRouteProperties.java new file mode 100644 index 0000000..c026a4e --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsClientRouteProperties.java @@ -0,0 +1,28 @@ +package org.acme.config.ws; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.ws") +public class CustomerWsClientRouteProperties { + private String input = "direct:callWsEndpoint"; + + private String output = "cxf:bean:customerWebService"; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsServerRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsServerRouteProperties.java new file mode 100644 index 0000000..3edebcd --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/ws/CustomerWsServerRouteProperties.java @@ -0,0 +1,28 @@ +package org.acme.config.ws; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "org.acme.customer.ws") +public class CustomerWsServerRouteProperties { + private String input = "cxf:bean:customerWebService"; + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } + + private String output = "direct:insertDb"; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java new file mode 100644 index 0000000..e00295b --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java @@ -0,0 +1,28 @@ +package org.acme.routes; + +import org.acme.config.CustomerDbRouteProperties; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CustomerDbRoute extends RouteBuilder { + @Autowired + private CustomerDbRouteProperties customerDbRouteProperties; + + @Override + public void configure() { + onException(Exception.class) + .to("log:onException") + .handled(true) + .transform(constant("Exception thrown. Stop route")); + + from("direct:insertDb").routeId("customer-insert-db") + .to("log:picked-up-db") + .to("sql:INSERT INTO USECASE.T_ACCOUNT(CLIENT_ID,SALES_CONTACT,COMPANY_NAME,COMPANY_GEO,COMPANY_ACTIVE,CONTACT_FIRST_NAME,CONTACT_LAST_NAME,CONTACT_ADDRESS," + + "CONTACT_CITY,CONTACT_STATE,CONTACT_ZIP,CONTACT_PHONE,CREATION_DATE,CREATION_USER) " + + "VALUES " + + "(:#CLIENT_ID,:#SALES_CONTACT,:#COMPANY_NAME,:#COMPANY_GEO,:#COMPANY_ACTIVE,:#CONTACT_FIRST_NAME,:#CONTACT_LAST_NAME,:#CONTACT_ADDRESS,:#CONTACT_CITY," + + ":#CONTACT_STATE,:#CONTACT_ZIP,:#CONTACT_PHONE,:#CREATION_DATE,:#CREATION_USER);"); + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java new file mode 100644 index 0000000..5943c7b --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java @@ -0,0 +1,36 @@ +package org.acme.routes; + +import org.acme.config.CustomerLoadRouteProperties; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; +import org.fuse.usecase.AccountAggregator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CustomerLoadRoute extends RouteBuilder { + + @Autowired + private CustomerLoadRouteProperties customerLoadRouteProperties; + + @Override + public void configure () throws Exception { + onException(Exception.class) + .to("log:onException") + .handled(true) + .transform(constant("Exception thrown. Stop route")); + + JacksonDataFormat format = new JacksonDataFormat(org.globex.Account.class); + + from(customerLoadRouteProperties.getInput()).routeId("customer-load") + .to("log:loaded") + .unmarshal(format) + .to("log:unmarshalled") + .multicast(new AccountAggregator()) + .to(customerLoadRouteProperties.getRestEndpoint(), customerLoadRouteProperties.getWsEndpoint()).end() + .to(customerLoadRouteProperties.getOutput()) + .to("log:enriched"); +// .to(customerLoadRouteProperties.getOutput()) +// .to("log:end-enrich"); + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerTransformRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerTransformRoute.java new file mode 100644 index 0000000..e5ac215 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerTransformRoute.java @@ -0,0 +1,74 @@ +package org.acme.routes; + +import org.acme.Customer; +import org.acme.config.CustomerTransformRouteProperties; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat; +import org.apache.camel.model.dataformat.JsonLibrary; +import org.globex.Account; +import org.globex.Company; +import org.globex.Contact; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CustomerTransformRoute extends RouteBuilder { + + @Autowired + private CustomerTransformRouteProperties customerTransformRouteProperties; + + @Override + public void configure () throws Exception { + onException(IllegalArgumentException.class) + .to("log:fail") + .to("file://src/data/error?fileName=csv-record-${date:now:yyyyMMdd}.txt") + .handled(true) + .stop(); + + BindyCsvDataFormat format = new BindyCsvDataFormat(org.acme.Customer.class); + format.setLocale("default"); + + from(customerTransformRouteProperties.getInput()).routeId("customer2account-transform") + .split() + .tokenize("\n") + .to("log:tokenized") + .unmarshal(format) + .to("log:unmarshalled") + .to("dozer:customerToAccount?mappingFile=transformation.xml&sourceModel=org.acme.Customer&targetModel=org.globex.Account") + /* + If you want to use a processor, uncomment the line below and comment the dozer line above + .process(new CustomerProcessor()) + */ + .to("log:transformed") + .marshal().json(JsonLibrary.Jackson) + .to(customerTransformRouteProperties.getOutput()); + } + + class CustomerProcessor implements Processor { + public void process(Exchange exchange) throws Exception { + Customer customer = exchange.getIn().getBody(Customer.class); + Account theAccount = new Account(); + Company theCompany = new Company(); + Contact theContact = new Contact(); + + theContact.setCity(customer.getCity()); + theContact.setFirstName(customer.getFirstName()); + theContact.setLastName(customer.getLastName()); + theContact.setPhone(customer.getPhone()); + theContact.setState(customer.getState()); + theContact.setStreetAddr(customer.getStreetAddr()); + theContact.setZip(customer.getZip()); + + theCompany.setActive(customer.isActive()); + theCompany.setGeo(customer.getRegion()); + theCompany.setName(customer.getCompanyName()); + + theAccount.setCompany(theCompany); + theAccount.setContact(theContact); + + exchange.getIn().setBody(theAccount, Account.class); + } + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java new file mode 100644 index 0000000..95aeffe --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java @@ -0,0 +1,43 @@ +package org.acme.routes.rest; + +import org.acme.config.rest.CustomerRestClientRouteProperties; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CustomerRestClientRoute extends RouteBuilder { + + @Autowired + private CustomerRestClientRouteProperties customerRestClientRouteProperties; + + @Override + public void configure () throws Exception { + onException(Exception.class) + .to("log:onException") + .handled(true) + .transform(constant("Exception thrown. Stop route")); + + from(customerRestClientRouteProperties.getInput()).routeId("customer-rest") + .to("log:rest-picked-up") + .process(new AccountHeaderProcessor()) + .inOut(customerRestClientRouteProperties.getOutput()) + .to("log:sent-to-rest"); +// .to("direct:insertDb"); + } + + class AccountHeaderProcessor implements Processor { + public void process(Exchange exchange) { + Message message = exchange.getIn(); + message.setHeader("Content-type", "application/json"); + message.setHeader("Accept", "application/json"); + message.setHeader("CamelHTTPMethod", "POST"); + message.setHeader("CamelHttpPath", "/customerservice/enrich"); + message.setHeader("CamelCxfRsUsingHttpAPI", "True"); + } + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java new file mode 100644 index 0000000..4d0ab4d --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java @@ -0,0 +1,39 @@ +package org.acme.routes.rest; + +import org.acme.config.rest.CustomerRestClientRouteProperties; +import org.acme.config.rest.CustomerRestServerRouteProperties; +import org.apache.camel.Exchange; +import org.apache.camel.ExchangePattern; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CustomerRestServerRoute extends RouteBuilder { + + @Autowired + private CustomerRestServerRouteProperties customerRestServerRouteProperties; + + @Override + public void configure () throws Exception { + onException(Exception.class) + .to("log:onException") + .handled(true) + .transform(constant("Exception thrown. Stop route")); + + from(customerRestServerRouteProperties.getInput()).to("log:found-rest-message"); + } + + class AccountHeaderProcessor implements Processor { + public void process(Exchange exchange) { + Message message = exchange.getIn(); + message.setHeader("Content-type", "application/json"); + message.setHeader("Accept", "application/json"); + message.setHeader("CamelHTTPMethod", "POST"); + message.setHeader("CamelHttpPath", "/customerservice/enrich"); + message.setHeader("CamelCxfRsUsingHttpAPI", "True"); + } + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java new file mode 100644 index 0000000..86b1b9f --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java @@ -0,0 +1,28 @@ +package org.acme.routes.ws; + +import org.acme.config.ws.CustomerWsClientRouteProperties; +import org.apache.camel.ExchangePattern; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CustomerWsClientRoute extends RouteBuilder { + + @Autowired + private CustomerWsClientRouteProperties customerWsClientRouteProperties; + + @Override + public void configure () throws Exception { + onException(Exception.class) + .to("log:onException") + .handled(true) + .transform(constant("Exception thrown. Stop route")); + + from(customerWsClientRouteProperties.getInput()).routeId("customer-ws-client") + .to("log:ws-picked-up") + .to(customerWsClientRouteProperties.getOutput()) + .to("log:sent-to-ws"); + } + +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java new file mode 100644 index 0000000..0da9513 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java @@ -0,0 +1,28 @@ +package org.acme.routes.ws; + +import org.acme.config.ws.CustomerWsClientRouteProperties; +import org.acme.config.ws.CustomerWsServerRouteProperties; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +@Component +public class CustomerWsServerRoute extends RouteBuilder { + + @Autowired + private CustomerWsServerRouteProperties customerWsServerRouteProperties; + + @Override + public void configure () throws Exception { + onException(Exception.class) + .to("log:onException") + .handled(true) + .transform(constant("Exception thrown. Stop route")); + + from(customerWsServerRouteProperties.getInput()).routeId("customer-ws-server") + .beanRef("customerWSImplBean", "updateAccount") + .to("log:ws-server-sent"); +// .to("direct:insertDb"); + } +} diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java index dfa5c65..e9bb1c7 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java @@ -18,6 +18,15 @@ public class AccountAggregator implements AggregationStrategy { @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + if(oldExchange == null) + return newExchange; + + Account account = oldExchange.getIn().getBody(Account.class); + CorporateAccount corporateAccount = oldExchange.getIn().getBody(CorporateAccount.class); + account.setClientId(corporateAccount.getId()); + account.setSalesRepresentative(corporateAccount.getSalesContact()); + + oldExchange.getIn().setBody(account, Account.class); return oldExchange; } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRest.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRest.java index 3a569cf..d1b138a 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRest.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRest.java @@ -4,11 +4,14 @@ import org.globex.Account; import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; @Path("/customerservice/") public interface CustomerRest { - @POST @Path("/enrich") @Consumes("application/json") + @POST @Path("/enrich") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) Account enrich(Account customer); } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRestImpl.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRestImpl.java index 9181021..488f37f 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRestImpl.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/service/CustomerRestImpl.java @@ -13,7 +13,8 @@ public class CustomerRestImpl implements CustomerRest { private static final String WE_REGION = "WEST_AMERICA"; private static final String EAST_REGION = "EAST_AMERICA"; - @Override public Account enrich(Account account) { + @Override + public Account enrich(Account account) { Company company = account.getCompany(); String region = company.getGeo(); switch (region) { diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/camel-context.xml b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/camel-context.xml index 6f95558..5efcd71 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/camel-context.xml +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/camel-context.xml @@ -1,17 +1,12 @@ + http://camel.apache.org/schema/cxf/camel-cxf-spring.xsd"> @@ -32,14 +27,14 @@ + loggingFeatureEnabled="true"> + loggingFeatureEnabled="true" serviceClass="org.fuse.usecase.service.CustomerRest"> @@ -49,15 +44,16 @@ + - + + + - - - + diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml new file mode 100644 index 0000000..fce0693 --- /dev/null +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/test/java/org/fuse/usecase/CxfRestClient.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/test/java/org/fuse/usecase/CxfRestClient.java index 617ccac..20a821e 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/test/java/org/fuse/usecase/CxfRestClient.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/test/java/org/fuse/usecase/CxfRestClient.java @@ -1,14 +1,15 @@ package org.fuse.usecase; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; -//import org.codehaus.jackson.jaxrs.JacksonJsonProvider; import org.globex.Account; import org.globex.Company; import org.globex.Contact; -import javax.ws.rs.client.*; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import static org.junit.Assert.assertEquals; From 6080b8df92e7b693d3a362a35f4a8b121cf67bde Mon Sep 17 00:00:00 2001 From: Khaled Janania Date: Fri, 5 Oct 2018 12:00:59 -0400 Subject: [PATCH 2/3] Cleaning up tests and poms --- .../parent/pom.xml | 27 -------- .../routing/pom.xml | 4 -- .../java/org/acme/routes/CustomerRoute.java | 1 - .../usecase/ValidateTransformationTest.java | 61 ++----------------- .../test/resources/config/application.yaml | 2 +- 5 files changed, 6 insertions(+), 89 deletions(-) diff --git a/code/01_file-split-and-transform-sb/parent/pom.xml b/code/01_file-split-and-transform-sb/parent/pom.xml index 968989e..705977e 100644 --- a/code/01_file-split-and-transform-sb/parent/pom.xml +++ b/code/01_file-split-and-transform-sb/parent/pom.xml @@ -34,11 +34,6 @@ pom import - - org.springframework.boot - spring-boot-starter-test - 1.5.13.RELEASE - @@ -63,28 +58,6 @@ - - - - org.apache.camel - camel-core - - - org.apache.camel - camel-spring - - - - org.slf4j - slf4j-api - - - log4j - log4j - - - - diff --git a/code/01_file-split-and-transform-sb/routing/pom.xml b/code/01_file-split-and-transform-sb/routing/pom.xml index 0438dcb..91a00d9 100644 --- a/code/01_file-split-and-transform-sb/routing/pom.xml +++ b/code/01_file-split-and-transform-sb/routing/pom.xml @@ -62,10 +62,6 @@ camel-test-spring test - - org.apache.camel - camel-spring-javaconfig - diff --git a/code/01_file-split-and-transform-sb/routing/src/main/java/org/acme/routes/CustomerRoute.java b/code/01_file-split-and-transform-sb/routing/src/main/java/org/acme/routes/CustomerRoute.java index f62f5c5..cf83656 100644 --- a/code/01_file-split-and-transform-sb/routing/src/main/java/org/acme/routes/CustomerRoute.java +++ b/code/01_file-split-and-transform-sb/routing/src/main/java/org/acme/routes/CustomerRoute.java @@ -8,7 +8,6 @@ import org.apache.camel.model.dataformat.JsonLibrary; import org.apache.camel.model.language.ExpressionDefinition; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.globex.Account; import org.globex.Company; diff --git a/code/01_file-split-and-transform-sb/routing/src/test/java/org/fuse/usecase/ValidateTransformationTest.java b/code/01_file-split-and-transform-sb/routing/src/test/java/org/fuse/usecase/ValidateTransformationTest.java index a507a04..77bb25e 100644 --- a/code/01_file-split-and-transform-sb/routing/src/test/java/org/fuse/usecase/ValidateTransformationTest.java +++ b/code/01_file-split-and-transform-sb/routing/src/test/java/org/fuse/usecase/ValidateTransformationTest.java @@ -1,74 +1,23 @@ package org.fuse.usecase; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import org.acme.Application; -import org.apache.camel.CamelContext; import org.apache.camel.EndpointInject; -import org.apache.camel.Produce; -import org.apache.camel.ProducerTemplate; -import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.spring.CamelSpringDelegatingTestContextLoader; -import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner; +import org.apache.camel.test.spring.CamelSpringRunner; import org.junit.Test; -import org.acme.routes.CustomerRoute; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.logging.Logger; -@RunWith(CamelSpringJUnit4ClassRunner.class) -//@ContextConfiguration(classes = {ValidateTransformationTest.ContextConfig.class}, loader = CamelSpringDelegatingTestContextLoader.class) +@RunWith(CamelSpringRunner.class) @SpringBootTest(classes = Application.class) -public class ValidateTransformationTest extends AbstractJUnit4SpringContextTests { +public class ValidateTransformationTest { - @Autowired - private CamelContext camelContext; - - @EndpointInject(uri = "mock:csv2json-test-output") private MockEndpoint resultEndpoint; - - @Produce(uri = "direct:csv2json-test-input") private ProducerTemplate startEndpoint; - -// private RouteBuilder createRouteBuilder() throws Exception { -// return new CustomerRoute(); -// } + @EndpointInject(uri = "mock:csv2json-test-output") + private MockEndpoint resultEndpoint; @Test public void testMessageOutputCount() throws Exception { resultEndpoint.expectedMessageCount(1); resultEndpoint.assertIsSatisfied(); } - -// @Test -// public void test() { -// resultEndpoint. -// } - -// private String readFile(String filePath) throws Exception { -// String content; -// FileInputStream fis = new FileInputStream(filePath); -// try { -// content = new CamelContext().getTypeConverter().convertTo(String.class, fis); -// } finally { -// fis.close(); -// } -// return content; -// } - - private String jsonUnprettyPrint(String jsonString) throws JsonProcessingException, IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true); - JsonNode node = mapper.readTree(jsonString); - return node.toString(); - } } diff --git a/code/01_file-split-and-transform-sb/routing/src/test/resources/config/application.yaml b/code/01_file-split-and-transform-sb/routing/src/test/resources/config/application.yaml index 497a08e..c6953d7 100644 --- a/code/01_file-split-and-transform-sb/routing/src/test/resources/config/application.yaml +++ b/code/01_file-split-and-transform-sb/routing/src/test/resources/config/application.yaml @@ -1,5 +1,5 @@ org: acme: customer: - input: file://src/test/data/inbox?fileName=customers.csv&noop=true + input: file://src/test/data/inbox?fileName=customer.csv&noop=true output: mock:csv2json-test-output \ No newline at end of file From f5010c5c43632ce168ca8e9c01d5deb9a1e53c6f Mon Sep 17 00:00:00 2001 From: Khaled Janania Date: Fri, 5 Oct 2018 16:52:13 -0400 Subject: [PATCH 3/3] Cleaning up properties and poms --- .../parent/pom.xml | 10 ----- .../routing/pom.xml | 30 +-------------- .../config/CustomerDbRouteProperties.java | 23 +++++++++++ .../config/CustomerLoadRouteProperties.java | 2 +- .../java/org/acme/routes/CustomerDbRoute.java | 16 +++----- .../org/acme/routes/CustomerLoadRoute.java | 11 +----- .../routes/rest/CustomerRestClientRoute.java | 8 +++- .../routes/rest/CustomerRestServerRoute.java | 21 ---------- .../acme/routes/ws/CustomerWsClientRoute.java | 8 +--- .../acme/routes/ws/CustomerWsServerRoute.java | 9 +---- .../org/fuse/usecase/AccountAggregator.java | 38 +++++++++++++------ .../java/org/fuse/usecase/ProcessorBean.java | 3 -- .../main/resources/META-INF/spring/test.xml | 16 -------- .../main/resources/fabric8/route.properties | 3 -- 14 files changed, 67 insertions(+), 131 deletions(-) delete mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml delete mode 100644 code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/fabric8/route.properties diff --git a/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml b/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml index 6aa206a..61133b2 100644 --- a/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml +++ b/code/02_enrich-content-REST-and-WS-sb/parent/pom.xml @@ -35,21 +35,11 @@ pom import - - org.springframework.boot - spring-boot-starter-test - 1.5.13.RELEASE - com.h2database h2 ${h2-driver.version} - - - - - diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml b/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml index d43abff..590957b 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml +++ b/code/02_enrich-content-REST-and-WS-sb/routing/pom.xml @@ -22,27 +22,7 @@ org.apache.cxf cxf-rt-transports-http-jetty - - - - - - - - - - - - - - - - - - - - org.apache.camel camel-cxf @@ -63,11 +43,8 @@ com.fasterxml.jackson.jaxrs jackson-jaxrs-json-provider - - - - + com.h2database h2 @@ -92,16 +69,13 @@ org.springframework.boot spring-boot-starter-test + test org.apache.camel camel-test-spring test - - org.apache.camel - camel-spring-javaconfig - diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java index 0547c9d..a468695 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerDbRouteProperties.java @@ -6,5 +6,28 @@ @Component @ConfigurationProperties(prefix = "org.acme.customer.db") public class CustomerDbRouteProperties { + private String input = "direct:insertDb"; + + private String output = "sql:INSERT INTO USECASE.T_ACCOUNT(CLIENT_ID,SALES_CONTACT,COMPANY_NAME,COMPANY_GEO,COMPANY_ACTIVE,CONTACT_FIRST_NAME,CONTACT_LAST_NAME,CONTACT_ADDRESS," + + "CONTACT_CITY,CONTACT_STATE,CONTACT_ZIP,CONTACT_PHONE,CREATION_DATE,CREATION_USER) " + + "VALUES " + + "(:#CLIENT_ID,:#SALES_CONTACT,:#COMPANY_NAME,:#COMPANY_GEO,:#COMPANY_ACTIVE,:#CONTACT_FIRST_NAME,:#CONTACT_LAST_NAME,:#CONTACT_ADDRESS,:#CONTACT_CITY," + + ":#CONTACT_STATE,:#CONTACT_ZIP,:#CONTACT_PHONE,:#CREATION_DATE,:#CREATION_USER)"; + + public String getInput() { + return input; + } + + public void setInput(String input) { + this.input = input; + } + + public String getOutput() { + return output; + } + + public void setOutput(String output) { + this.output = output; + } } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java index c689557..413b4ee 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/config/CustomerLoadRouteProperties.java @@ -6,7 +6,7 @@ @Component @ConfigurationProperties(prefix = "org.acme.customer.load") public class CustomerLoadRouteProperties { - private String input = "file://src/data/outbox?noop=true"; + private String input = "file://src/data/outbox?noop=true&idempotent=true"; private String restEndpoint = "direct:callRestEndpoint"; private String wsEndpoint = "direct:callWsEndpoint"; private String output = "direct:insertDb"; diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java index e00295b..563f2c1 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerDbRoute.java @@ -2,6 +2,7 @@ import org.acme.config.CustomerDbRouteProperties; import org.apache.camel.builder.RouteBuilder; +import org.fuse.usecase.ProcessorBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -12,17 +13,10 @@ public class CustomerDbRoute extends RouteBuilder { @Override public void configure() { - onException(Exception.class) - .to("log:onException") - .handled(true) - .transform(constant("Exception thrown. Stop route")); - - from("direct:insertDb").routeId("customer-insert-db") + from(customerDbRouteProperties.getInput()).routeId("customer-insert-db") .to("log:picked-up-db") - .to("sql:INSERT INTO USECASE.T_ACCOUNT(CLIENT_ID,SALES_CONTACT,COMPANY_NAME,COMPANY_GEO,COMPANY_ACTIVE,CONTACT_FIRST_NAME,CONTACT_LAST_NAME,CONTACT_ADDRESS," + - "CONTACT_CITY,CONTACT_STATE,CONTACT_ZIP,CONTACT_PHONE,CREATION_DATE,CREATION_USER) " + - "VALUES " + - "(:#CLIENT_ID,:#SALES_CONTACT,:#COMPANY_NAME,:#COMPANY_GEO,:#COMPANY_ACTIVE,:#CONTACT_FIRST_NAME,:#CONTACT_LAST_NAME,:#CONTACT_ADDRESS,:#CONTACT_CITY," + - ":#CONTACT_STATE,:#CONTACT_ZIP,:#CONTACT_PHONE,:#CREATION_DATE,:#CREATION_USER);"); + .transform().method(ProcessorBean.class, "defineNamedParameters") + .to(customerDbRouteProperties.getOutput()) + .to("log:inserted-db"); } } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java index 5943c7b..432ccc5 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/CustomerLoadRoute.java @@ -15,11 +15,6 @@ public class CustomerLoadRoute extends RouteBuilder { @Override public void configure () throws Exception { - onException(Exception.class) - .to("log:onException") - .handled(true) - .transform(constant("Exception thrown. Stop route")); - JacksonDataFormat format = new JacksonDataFormat(org.globex.Account.class); from(customerLoadRouteProperties.getInput()).routeId("customer-load") @@ -28,9 +23,7 @@ public void configure () throws Exception { .to("log:unmarshalled") .multicast(new AccountAggregator()) .to(customerLoadRouteProperties.getRestEndpoint(), customerLoadRouteProperties.getWsEndpoint()).end() - .to(customerLoadRouteProperties.getOutput()) - .to("log:enriched"); -// .to(customerLoadRouteProperties.getOutput()) -// .to("log:end-enrich"); + .to("log:enriched") + .to(customerLoadRouteProperties.getOutput()); } } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java index 95aeffe..056f3a8 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestClientRoute.java @@ -2,10 +2,12 @@ import org.acme.config.rest.CustomerRestClientRouteProperties; import org.apache.camel.Exchange; -import org.apache.camel.ExchangePattern; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; +import org.apache.camel.component.jackson.ListJacksonDataFormat; +import org.globex.Account; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,12 +24,14 @@ public void configure () throws Exception { .handled(true) .transform(constant("Exception thrown. Stop route")); + JacksonDataFormat dataFormat = new ListJacksonDataFormat(Account.class); + from(customerRestClientRouteProperties.getInput()).routeId("customer-rest") .to("log:rest-picked-up") .process(new AccountHeaderProcessor()) .inOut(customerRestClientRouteProperties.getOutput()) + .unmarshal(dataFormat) .to("log:sent-to-rest"); -// .to("direct:insertDb"); } class AccountHeaderProcessor implements Processor { diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java index 4d0ab4d..86d2b4c 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/rest/CustomerRestServerRoute.java @@ -1,11 +1,6 @@ package org.acme.routes.rest; -import org.acme.config.rest.CustomerRestClientRouteProperties; import org.acme.config.rest.CustomerRestServerRouteProperties; -import org.apache.camel.Exchange; -import org.apache.camel.ExchangePattern; -import org.apache.camel.Message; -import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -18,22 +13,6 @@ public class CustomerRestServerRoute extends RouteBuilder { @Override public void configure () throws Exception { - onException(Exception.class) - .to("log:onException") - .handled(true) - .transform(constant("Exception thrown. Stop route")); - from(customerRestServerRouteProperties.getInput()).to("log:found-rest-message"); } - - class AccountHeaderProcessor implements Processor { - public void process(Exchange exchange) { - Message message = exchange.getIn(); - message.setHeader("Content-type", "application/json"); - message.setHeader("Accept", "application/json"); - message.setHeader("CamelHTTPMethod", "POST"); - message.setHeader("CamelHttpPath", "/customerservice/enrich"); - message.setHeader("CamelCxfRsUsingHttpAPI", "True"); - } - } } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java index 86b1b9f..2788ae5 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsClientRoute.java @@ -1,7 +1,6 @@ package org.acme.routes.ws; import org.acme.config.ws.CustomerWsClientRouteProperties; -import org.apache.camel.ExchangePattern; import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -14,15 +13,10 @@ public class CustomerWsClientRoute extends RouteBuilder { @Override public void configure () throws Exception { - onException(Exception.class) - .to("log:onException") - .handled(true) - .transform(constant("Exception thrown. Stop route")); - from(customerWsClientRouteProperties.getInput()).routeId("customer-ws-client") .to("log:ws-picked-up") .to(customerWsClientRouteProperties.getOutput()) - .to("log:sent-to-ws"); + .to("log:ws-response-received"); } } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java index 0da9513..a7799d1 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/acme/routes/ws/CustomerWsServerRoute.java @@ -1,6 +1,5 @@ package org.acme.routes.ws; -import org.acme.config.ws.CustomerWsClientRouteProperties; import org.acme.config.ws.CustomerWsServerRouteProperties; import org.apache.camel.builder.RouteBuilder; import org.springframework.beans.factory.annotation.Autowired; @@ -15,14 +14,8 @@ public class CustomerWsServerRoute extends RouteBuilder { @Override public void configure () throws Exception { - onException(Exception.class) - .to("log:onException") - .handled(true) - .transform(constant("Exception thrown. Stop route")); - from(customerWsServerRouteProperties.getInput()).routeId("customer-ws-server") .beanRef("customerWSImplBean", "updateAccount") - .to("log:ws-server-sent"); -// .to("direct:insertDb"); + .to("log:ws-server-responded"); } } diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java index e9bb1c7..95431d6 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/AccountAggregator.java @@ -2,33 +2,47 @@ import org.apache.camel.Exchange; import org.apache.camel.processor.aggregate.AggregationStrategy; -import org.apache.cxf.message.MessageContentsList; import org.globex.Account; -import org.globex.Company; import org.globex.CorporateAccount; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.ArrayList; /** * Aggregator implementation which extract the id and salescontact * from CorporateAccount and update the Account */ public class AccountAggregator implements AggregationStrategy { + final Logger logger = LoggerFactory.getLogger(AccountAggregator.class); @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { - if(oldExchange == null) + if(oldExchange == null) { + logger.info("oldExchange is empty, just returning newExchange."); return newExchange; + } - Account account = oldExchange.getIn().getBody(Account.class); - CorporateAccount corporateAccount = oldExchange.getIn().getBody(CorporateAccount.class); - account.setClientId(corporateAccount.getId()); - account.setSalesRepresentative(corporateAccount.getSalesContact()); + try { + logger.info("oldExchange body: " + oldExchange.getIn().getBody().getClass()); + logger.info("newExchange body: " + newExchange.getIn().getBody().getClass()); + Account account = (Account) oldExchange.getIn().getBody(ArrayList.class).get(0); + logger.info("Retrieved Account from oldExchange: " + account); + CorporateAccount corporateAccount = newExchange.getIn().getBody(CorporateAccount.class); + logger.info("Retrieved CorporateAccount from newExchange: " + corporateAccount); + logger.info("CorporateAccount ID: " + corporateAccount.getId()); + account.setClientId(corporateAccount.getId()); + logger.info("CorporateAccount Sales Contact: " + corporateAccount.getSalesContact()); + account.setSalesRepresentative(corporateAccount.getSalesContact()); - oldExchange.getIn().setBody(account, Account.class); + oldExchange.getIn().setBody(account, Account.class); - return oldExchange; + logger.info("Successfully merged enriched accounts."); + return oldExchange; + } + catch(Exception e) { + logger.error("Exception: ", e); + } + return newExchange; } } \ No newline at end of file diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/ProcessorBean.java b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/ProcessorBean.java index f1eaeca..5f6678b 100644 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/ProcessorBean.java +++ b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/java/org/fuse/usecase/ProcessorBean.java @@ -4,13 +4,10 @@ import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.cxf.jaxrs.impl.ResponseImpl; -import org.apache.cxf.message.MessageContentsList; import org.globex.Account; -import org.globex.CorporateAccount; import java.io.IOException; import java.io.InputStream; -import java.io.SequenceInputStream; import java.sql.Timestamp; import java.util.Calendar; import java.util.HashMap; diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml deleted file mode 100644 index fce0693..0000000 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/META-INF/spring/test.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/fabric8/route.properties b/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/fabric8/route.properties deleted file mode 100644 index bbfd0e6..0000000 --- a/code/02_enrich-content-REST-and-WS-sb/routing/src/main/resources/fabric8/route.properties +++ /dev/null @@ -1,3 +0,0 @@ -fileInput=src/data/inbox -fileOutput=src/data/outbox -fileError=src/data/error \ No newline at end of file