Apache Camel integration with Spring

Apache Camel can be integrated with Spring using xml configuration file

Here I will provide a tutorial on how you can get started with Apache Camel in xml.If we follow xml based configuration, there is no use of Router class.

Below xml is Camel xml configuration using spring itegration, using this I am trying to achieve copying files one location to other location within time period. Whenever any file reaches to input location, will be copied to output location..
Using transformer content can be transform to other format, process related can be handled by processor and logic can be handled by bean(component)..

Router in Xml Configuration:(applicationContext-camel.xml)
<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>


Processor
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");
		
	}

}


Transformer: Retrieving content and changing to uppercase
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;
	}

}


Maven entries for pom.xml
		<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>


Below is my application execution
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();
    }
}


Apache Camel Application Structure

Apache camel Application Structure

Execute Apache Camel Application:

Execution Spring Aspect Application

Paste a file at input location and check console as well output location.We can observe file transfor input folder to output folder