View Javadoc

1   package org.srinivas.siteworks.dbrestserver;
2   
3   import org.apache.camel.builder.RouteBuilder;
4   import org.apache.camel.model.rest.RestBindingMode;
5   
6   /**
7    * The Class DbServerRoute.
8    */
9   public class DbServerRoute extends RouteBuilder {
10  
11  	public static final String CAMEL_ENDPOINT_DIRECT_DBUPDATEFIREWORK = "direct:dbupdatefirework";
12  	public static final String CAMEL_ENDPOINT_DIRECT_DBFIREWORKSCOLLECTION = "direct:dbfireworkscollection";
13  	public static final int DBRESTSERVER_PORT_NUMBER_8181 = 8181;
14  	public static final String DOMAIN_LOCALHOST = "localhost";
15  	public static final String CAMEL_ENDPOINT_DIRECT_ERROR = "direct:error";
16  	public static final String DBUPDATEFIREWORK = "dbupdatefirework";
17  	public static final String DBFIREWORKSCOLLECTION = "dbfireworkscollection";
18  	public static final String DB_ROUTE_STATUS = "DbRouteStatus";
19  
20  	/* (non-Javadoc)
21  	 * @see org.apache.camel.builder.RouteBuilder#configure()
22  	 */
23  	@Override
24  	public void configure() throws Exception {
25  		onException(Exception.class).onWhen(header(DB_ROUTE_STATUS).contains(DBFIREWORKSCOLLECTION)).to(CAMEL_ENDPOINT_DIRECT_ERROR).handled(true).end();
26  		onException(Exception.class).onWhen(header(DB_ROUTE_STATUS).contains(DBUPDATEFIREWORK)).to(CAMEL_ENDPOINT_DIRECT_ERROR).handled(true).end();
27  		onException(Exception.class).handled(true).transform().constant("Sorry DBRestServer Could Not Process Due to Errors").end();
28  
29  		restConfiguration().component("undertow").host(DOMAIN_LOCALHOST)
30  				.port(DBRESTSERVER_PORT_NUMBER_8181).bindingMode(RestBindingMode.auto)
31  				.componentProperty("matchOnUriPrefix", "true")
32  				.dataFormatProperty("prettyPrint", "true").apiContextPath("/api-doc")
33  				.apiProperty("api.title", "User API").apiProperty("api.version", "1.2.3")
34  				.apiProperty("cors", "true");
35  
36  		rest("/fireworks/getAll").description("Servlet for Get All Fireworks").get()
37  				.description("Get Request of Servlet for Get All Fireworks and It Produces XML")
38  				.outType(String.class).produces("appication/xml").route()
39  				.to(CAMEL_ENDPOINT_DIRECT_DBFIREWORKSCOLLECTION).endRest().post()
40  				.description("POST Request of Servlet for Get All Fireworks and It Produces XML")
41  				.outType(String.class).produces("appication/xml").route()
42  				.to(CAMEL_ENDPOINT_DIRECT_DBFIREWORKSCOLLECTION);
43  		rest("/fireworks/updatefirework").description("Servlet for Update Firework").post()
44  				.description("Get Request of Servlet for Update Firework and It Produces XML")
45  				.outType(String.class).produces("text/plain").route()
46  				.to(CAMEL_ENDPOINT_DIRECT_DBUPDATEFIREWORK);
47  
48  		from(CAMEL_ENDPOINT_DIRECT_DBFIREWORKSCOLLECTION)
49  				.setHeader(DB_ROUTE_STATUS, constant(DBFIREWORKSCOLLECTION))
50  				.process(new FireWorksListProcessor()).log("Message ${body}");
51  		from(CAMEL_ENDPOINT_DIRECT_DBUPDATEFIREWORK)
52  				.setHeader(DB_ROUTE_STATUS, constant(DBUPDATEFIREWORK))
53  				.process(new FireWorksUpdateProcessor()).log("Message ${body}");
54  		from(CAMEL_ENDPOINT_DIRECT_ERROR).process(new DbServerErrorHandlerProcessor()).log(
55  				"Message ${body}");
56  	}
57  
58  }