use of org.apache.camel.core.osgi.OsgiLanguageResolver in project karaf by apache.
the class CamelComponent method activate.
@Activate
public void activate(ComponentContext componentContext) throws Exception {
BundleContext bundleContext = componentContext.getBundleContext();
OsgiDefaultCamelContext osgiDefaultCamelContext = new OsgiDefaultCamelContext(bundleContext);
osgiDefaultCamelContext.setClassResolver(new OsgiClassResolver(camelContext, bundleContext));
osgiDefaultCamelContext.setDataFormatResolver(new OsgiDataFormatResolver(bundleContext));
osgiDefaultCamelContext.setLanguageResolver(new OsgiLanguageResolver(bundleContext));
osgiDefaultCamelContext.setName("context-example");
camelContext = osgiDefaultCamelContext;
serviceRegistration = bundleContext.registerService(CamelContext.class, camelContext, null);
camelContext.start();
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://0.0.0.0:9090/example").id("example-http-inbound").convertBodyTo(String.class).log("[EXAMPLE INBOUND] Received: ${body}").choice().when().simple("${headers.CamelHttpMethod} == 'POST'").setHeader("type").jsonpath("$.notification.type").choice().when().simple("${header.type} == 'email'").log("[EXAMPLE INBOUND] Received email notification").to("direct:email").setHeader("Exchange.HTTP_RESPONSE_CODE", constant(200)).when().simple("${header.type} == 'http'").log("[EXAMPLE INBOUND] Received http notification").to("direct:http").setHeader("Exchange.HTTP_RESPONSE_CODE", constant(200)).otherwise().log("[EXAMPLE INBOUND] Unknown notification").setBody(constant("{ \"status\": \"reject\", \"type\": \"unknown\" }")).setHeader("Exchange.HTTP_RESPONSE_CODE", constant(400)).otherwise().log("[EXAMPLE INBOUND] only POST is accepted (${headers.CamelHttpMethod})").setBody(constant("{ \"error\": \"only POST is accepted\" }")).setHeader("Exchange.HTTP_RESPONSE_CODE", constant(500));
from("direct:email").id("example-email").log("[EXAMPLE EMAIL] Sending notification email").setHeader("to").jsonpath("$.notification.to").setHeader("subject", constant("Notification")).setHeader("payload").jsonpath("$.notification.message").setBody(simple("{ \"status\": \"email sent\", \"to\": \"${header.to}\", \"subject\": \"${header.subject}\" }"));
from("direct:http").id("example-http").log("[EXAMPLE HTTP] Sending http notification").setHeader("service").jsonpath("$.notification.service").setBody(simple("{ \"status\": \"http requested\", \"service\": \"${header.service}\" }"));
}
});
}
Aggregations