View Javadoc

1   package org.srinivas.siteworks.fecamelworks;
2   
3   import org.apache.camel.Exchange;
4   import org.apache.camel.builder.RouteBuilder;
5   
6   /**
7    * The Class FECamelWorksRoute.
8    */
9   public class FECamelWorksRoute extends RouteBuilder {
10  
11  	public static final String CAMEL_ENDPOINT_DIRECT_ERROR = "direct:error";
12  	public static final String FEUPDATEFIREWORK = "FEupdatefirework";
13  	public static final String FEFIREWORKSCOLLECTION = "FEfireworkscollection";
14  	public static final String FE_ROUTE_STATUS = "FERouteStatus";
15  
16  	/* (non-Javadoc)
17  	 * @see org.apache.camel.builder.RouteBuilder#configure()
18  	 */
19  	@Override
20  	public void configure() throws Exception {
21  
22  		onException(Exception.class).onWhen(header(FE_ROUTE_STATUS).contains(FEFIREWORKSCOLLECTION)).to(CAMEL_ENDPOINT_DIRECT_ERROR).handled(true).end();
23  		onException(Exception.class).onWhen(header(FE_ROUTE_STATUS).contains(FEUPDATEFIREWORK)).to(CAMEL_ENDPOINT_DIRECT_ERROR).handled(true).end();
24  		onException(Exception.class).handled(true).transform().constant("Sorry FECameWorks Could Not Process Due to Errors").end();
25  
26  		from("direct:process")
27  				.split(bodyAs(String.class).tokenize("&&"), new StringAggregationStrategy())
28  				.choice()
29  				.when(body().contains("getAll"))
30  				.setHeader(FE_ROUTE_STATUS, constant(FEFIREWORKSCOLLECTION))
31  				.setHeader(Exchange.HTTP_METHOD,
32  						constant(org.apache.camel.component.http4.HttpMethods.GET))
33  				.to("http4://localhost:8080/RLRestServer/fireworks/getAll")
34  				.when(body().contains("Update:"))
35  				.setHeader(FE_ROUTE_STATUS, constant(FEUPDATEFIREWORK))
36  				.log("Message ${body}")
37  				.setHeader(Exchange.HTTP_METHOD,
38  						constant(org.apache.camel.component.http4.HttpMethods.POST))
39  				.to("http4://localhost:8080/RLRestServer/fireworks/updatefirework")
40  				.convertBodyTo(String.class).otherwise()
41  				.transform(simple("${body}: does not have a corresponding Service")).end()
42  				.convertBodyTo(String.class).log("Message ${body}").end().to("mock:result");
43  
44  		from(CAMEL_ENDPOINT_DIRECT_ERROR).process(new FECamelWorksErrorHandlerProcessor())
45  				.log("Message ${body}");
46  	}
47  
48  }