<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="processor" class="com.javavillage.camel.processor.LogProcessor"/> <bean id="component" class="com.javavillage.camel.transfermor.CamelTranformer"/> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="file:C:/JavaTraining/camel/input?noop=true" /> <process ref="processor"/> <bean ref="component"/> <to uri="file:C:/JavaTraining/camel/output" /> </route> </camelContext> </beans>
package com.javavillage.camel.processor; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class LogProcessor implements Processor{ public void process(Exchange exchange) throws Exception { String payload = exchange.getIn().getBody(String.class); System.out.println(">>>>>>>>>>>>"+payload); // do something with the payload and/or exchange here exchange.getIn().setBody("By"); } }
package com.javavillage.firstcamelprj; public class Transormer { public String transformContent(String body) { System.out.println("invoking the transformContent method"); String upperCaseContent=body.toUpperCase(); //System.out.println(object); return upperCaseContent; } }
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-core</artifactId> <version>2.13.0</version> </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-spring</artifactId> <version>2.13.0</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.5</version> </dependency>
package com.javavillage.camel.proj; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; /** * Hello world! * */ public class App { public static void main( String[] args ) { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-camel.xml"); ctx.start(); System.out.println("Entered>>>>>"); ctx.stop(); } }