-
-
Save honghuac/0232f552d6ef4f60aaecae933766a2df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:osgi="http://www.springframework.org/schema/osgi" | |
xmlns:cxf="http://camel.apache.org/schema/cxf" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans.xsd | |
http://www.springframework.org/schema/osgi | |
http://www.springframework.org/schema/osgi/spring-osgi.xsd | |
http://camel.apache.org/schema/cxf | |
http://camel.apache.org/schema/cxf/camel-cxf-spring.xsd | |
http://camel.apache.org/schema/spring | |
http://camel.apache.org/schema/spring/camel-spring.xsd"> | |
<!-- H2 DB --> | |
<bean id="usecaseDB" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> | |
<property name="driverClassName" value="org.h2.Driver"/> | |
<property name="url" value="jdbc:h2:tcp://localhost/~/usecaseDB"/> | |
<property name="username" value="sa"/> | |
<property name="password" value=""/> | |
</bean> | |
<!-- SQL Component & Datasource --> | |
<bean id="sql" class="org.apache.camel.component.sql.SqlComponent"> | |
<property name="dataSource" ref="usecaseDB"/> | |
</bean> | |
<cxf:cxfEndpoint id="customerWebService" address="http://localhost:9090/ws/customerService" | |
serviceClass="org.fuse.usecase.service.CustomerWS" | |
loggingFeatureEnabled="true"> | |
</cxf:cxfEndpoint> | |
<cxf:rsServer id="customerRestService" address="http://localhost:9191/rest" | |
serviceClass="org.fuse.usecase.service.CustomerRest" | |
loggingFeatureEnabled="false"> | |
<cxf:providers> | |
<ref bean="jsonProvider"/> | |
</cxf:providers> | |
</cxf:rsServer> | |
<cxf:rsClient id="customerRestServiceClient" address="http://localhost:9191/rest" | |
loggingFeatureEnabled="false" serviceClass="org.fuse.usecase.service.CustomerRest"> | |
<cxf:providers> | |
<ref bean="jsonProvider"/> | |
</cxf:providers> | |
</cxf:rsClient> | |
<bean id="reconcileData" class="org.fuse.usecase.AccountAggregator"/> | |
<bean id="customerWSImplBean" class="org.fuse.usecase.service.CustomerWSImpl"/> | |
<bean id="customerRestImplBean" class="org.fuse.usecase.service.CustomerRestImpl"/> | |
<bean id="processorBean" class="org.fuse.usecase.ProcessorBean"/> | |
<!-- THIS PROVIDER DOESN'T WORK & RETURN ERROR 415 Unsupported Media Type | |
It can't also handle the Body : No message body reader has been found for | |
class CXF_Test.cxf_test.Book, ContentType: application/json | |
<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"/> | |
--> | |
<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider"/> | |
<camelContext trace="false" xmlns="http://camel.apache.org/schema/spring"> | |
<propertyPlaceholder id="properties" location="fabric8/route.properties"/> | |
<!-- | |
Transformation Endpoint doing csv2java conversion | |
Step 1 : csv record is converted java using camel bindy | |
Step 2 : Dozer transformation of Customer to Account | |
Step 3 : Java to Json conversion using json jackson | |
--> | |
<endpoint | |
uri="dozer:csv2json?sourceModel=org.acme.Customer&targetModel=org.globex.Account&marshalId=json&unmarshalId=csv&mappingFile=transformation.xml" | |
id="csv2json"/> | |
<!-- CSV Input & JSon OutPut DataFormat --> | |
<dataFormats> | |
<bindy id="csv" type="Csv" classType="org.acme.Customer"/> | |
<json id="json" library="Jackson"/> | |
</dataFormats> | |
<!-- Route Definition CSV to JSON --> | |
<route> | |
<!-- Consume files from input directory --> | |
<from uri="file:{{fileInput}}?fileName=customers.csv&noop=true"/> | |
<onException> | |
<exception>java.lang.IllegalArgumentException</exception> | |
<handled> | |
<constant>true</constant> | |
</handled> | |
<to uri="file:{{fileError}}?fileName=csv-record-${date:now:yyyyMMdd}.txt"/> | |
</onException> | |
<split> | |
<tokenize token="\n"/> | |
<to ref="csv2json"/> | |
<to uri="file:{{fileOutput}}?fileName=account-${property.CamelSplitIndex}.json"/> | |
</split> | |
</route> | |
<!-- Multicast the account to the REST & WS to aggregate the result --> | |
<route> | |
<from uri="file:{{fileOutput}}"/> | |
<convertBodyTo type="String"/> | |
<unmarshal> | |
<json library="Jackson" unmarshalTypeName="org.globex.Account"/> | |
</unmarshal> | |
<multicast strategyRef="reconcileData"> | |
<to uri="direct://callRestEndpoint"/> | |
<to uri="direct://callWSEndpoint"/> | |
</multicast> | |
<log loggingLevel="INFO" | |
message=">> Aggregated result: Account : ${body.clientId}, ${body.salesRepresentative}; Company : ${body.company.name}, ${body.company.geo}, ${body.company.active}; Contact : ${body.contact.firstName}, ${body.contact.lastName}, ${body.contact.streetAddr}, ${body.contact.city}, ${body.contact.state}, ${body.contact.zip}, ${body.contact.phone}"/> | |
<to uri="direct:insertDB"/> | |
</route> | |
<!-- REST Service --> | |
<route> | |
<from uri="cxfrs:bean:customerRestService"/> | |
<bean ref="customerRestImplBean" method="enrich"/> | |
</route> | |
<!-- WebService --> | |
<route> | |
<from uri="cxf:bean:customerWebService"/> | |
<bean ref="customerWSImplBean" method="updateAccount"/> | |
</route> | |
<!-- Call WebService Client --> | |
<route> | |
<from uri="direct://callWSEndpoint"/> | |
<to uri="cxf:bean:customerWebService"/> | |
<!-- | |
<log loggingLevel="INFO" | |
message=">> WebService Response : ${body[0].id}, ${body[0].salesContact}, ${body[0].company.geo}, ${body[0].contact.firstName}, ${body[0].contact.lastName} "/> | |
--> | |
</route> | |
<!-- Call REST Client --> | |
<route> | |
<from uri="direct://callRestEndpoint"/> | |
<onException> | |
<exception>java.lang.Exception</exception> | |
<redeliveryPolicy maximumRedeliveries="1"/> | |
<handled> | |
<constant>true</constant> | |
</handled> | |
<log message=">> Error : ${exception.message}, ${exception.stacktrace}"/> | |
</onException> | |
<setHeader headerName="Content-Type"> | |
<constant>application/json</constant> | |
</setHeader> | |
<setHeader headerName="Accept"> | |
<constant>application/json</constant> | |
</setHeader> | |
<setHeader headerName="CamelHttpMethod"> | |
<constant>POST</constant> | |
</setHeader> | |
<setHeader headerName="CamelHttpPath"> | |
<constant>/customerservice/enrich</constant> | |
</setHeader> | |
<setHeader headerName="CamelCxfRsUsingHttpAPI"> | |
<constant>True</constant> | |
</setHeader> | |
<setHeader headerName="originalBody"> | |
<simple>${body}</simple> | |
</setHeader> | |
<inOut uri="cxfrs:bean:customerRestServiceClient"/> | |
<bean beanType="org.fuse.usecase.ProcessorBean" method="convertEntityToString"/> | |
<unmarshal> | |
<json library="Jackson" unmarshalTypeName="org.globex.Account"/> | |
</unmarshal> | |
<!-- Attempt to use HTTP Client | |
<setHeader headerName="CamelHttpUri"> | |
<simple>http://localhost:9191/rest/customerservice/enrich</simple> | |
</setHeader> | |
<to uri="http4://restClient"/> | |
--> | |
<!-- There is no provider to parse the body if we call directly the endpoint and don't use CXF Client | |
<to uri="cxfrs://http://localhost:9191/rest/customerservice/enrich"/> | |
--> | |
<setBody> | |
<simple>${body}</simple> | |
</setBody> | |
</route> | |
<!-- Insert Records --> | |
<route> | |
<from uri="direct:insertDB"/> | |
<bean ref="processorBean" method="defineNamedParameters"/> | |
<to uri="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);"/> | |
<log message=">>> Results : ${body}"/> | |
</route> | |
</camelContext> | |
</beans> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment