Start with Apache Camel - spring

I’m very new to Apache Camel and will very appreciate if someone could provide me what camel components may be used to solve particular task.
I have a simple REST WS. This service is not accessible to audience.
The idea is to build middle layer between user requests and endpoint service.
So I will have to catch user’s request, make some manipulations with it, send to restricted WS and give a response to user.
I’m just started learning apache camel and the question is what is the best way to implement this logic.
Thx in advance!

Frankly, Camel is not the right framework to implement web controllers. Of course there is the Camel Rest Module, but it is stretching the responsibilities of the framework too far.
I recommend using a more adapt framework for the implementation of the WS, e.g. Spring or Jersey, and call Camel endpoints programmatically from the request handlers. Within Spring, triggering Camel Endpoints is easy since the CamelContext can get autowired into your web controller:
camelContext.createProducerTemplate().sendBodyAndHeader("direct:myEndpoint", null, "id", id);
For your Camel Root this approach means, that it starts of with a Direct endpoint, then forwards to a Camel http endpoint and if necessary forwards the output from the HTTP call to some Spring bean transformation step, before finally passing it back to the web controller handler method:
<route>
<from uri="direct:myEndpoint"/>
<to uri="http:somehost.com"/>
<transform>
<method ref="springBean" method="doSomeTransformation"/>
</transform>
</route>

Well there are several camel components you can use for this task. Think of Camel as a toolbox where you can choose from several tools for the same task.
You can use:
Camel-HTTP4 http://camel.apache.org/http4.html
Camel-Jetty http://camel.apache.org/jetty.html
Camel-Restlet http://camel.apache.org/restlet.html
Camel-CXFRS http://camel.apache.org/cxfrs.html
Example using java dsl:
from("jetty://http://localhost:7070/test").to("jetty://http://localhost:7070/test1");
Example using blueprint
<route>
<from uri="jetty://http://localhost:7070/test"/>
<to uri="jetty://http://localhost:7070/test1"/>
<route>

Related

convert apache camel config to spring java config

we are in the process of converting current spring project into spring boot and at the same time converting all spring beans from xml to java config based.
i am stuck converting camel xml configuration into java based config.
currently we are specified camel config , routes and endpoints , one example as below
<camel:camelContext id="camelClient">
<camel:template id="camelTemplate"/>
</camel:camelContext>
<template id="camelTemplate"/>
here are couple of endpoints
<endpoint id="archiveUserQueue"
uri="swiftmq:${hk.jms.archive.queue.name}?concurrentConsumers=${hk.jms.archive.queue.consumers}"/>
<endpoint id="directSmsNotification" uri="direct:sendSMS"/>
one of the routes defined
<route>
<from ref="directSmsNotification"/>
<to uri="bean:messengerService?method=sendSmsMessage"/>
</route>
in java code we access the end point as below
smsEndpoint = _camelContext.getEndpoint("directSmsNotification");
how can we convert the camel config from xml to java based config.
i have followed instructions specified at http://camel.apache.org/spring-java-config.html but it was too hard to understand as i am not familiar with Camel.
You can mix and match Spring Java config with Apache Camel XML config. I question why you're doing this conversion in the first place.
That said, if you look at the camel docs you'll see there's an example for working with RouteBuilder.
You could also look at the sample spring-boot application. Here's a modified RouteBuilder from that example:
#Component
public class MySpringBootRouter extends RouteBuilder {
#Override
public void configure() {
Context context = getContext();
MyEndpoint ep = context.getEndpoint("someURI", MyEndpoint.class);
from(ep)
.transform().simple("ref:myBean")
.to("log:out");
}
}
Update: I modified the snippet to show getting an Endpoint directly. You can get more info in the Camel docs. I'm not sure how common this approach is. Back when I was using Camel regularly the endpoints were configured declaratively through their URI values. I don't think I ever explicitly defined an endpoint in my Camel XML or Java code. I'm sure there are use cases for it but it might be simpler for you to configure just by URI.

Apply Caching Aspect to Camel Routes using InterceptFrom

I want to apply the caching aspect to Apache Camel Routes using InterceptFrom feature by intercepting
every incoming exchange in a route.
I am able to successfully load the RestDefinitions and RouteDefinitions currently from separate xml files.
In a similar way I want to load the Intercept definition from a seperate XML file.
I currently have tne following content in my xml(Intercept.xml) file which I use to load the InterceptFrom Definitions as below. I only log them as of now. i will be adding the logic to check for cache hit/miss eventually.
<interceptFrom>
<log message="Intercepted Route" />
</interceptFrom>
I am loading them using the below method,
List<InterceptFromDefinition> intDefns=getInterceptDefinitions("Intercept.xml");
I also set them to the routes.
routes.setInterceptFroms(intDefns);
I get the error as below,
2016-10-08 22:13:19.711 ERROR 6004 --- [ main] com.demo.composite.util.CamelUtil : Exception reading configuration files:javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"interceptFrom"). Expected elements are <{http://camel.apache.org/schema/spring}aggregate>,<{http://camel.apache.org/schema/spring}aop>,<{http://camel.apache.org/schema/spring}avro>,<{http://camel.apache.org/schema/spring}barcode>,<{http://camel.apache.org/schema/spring}base64>,<{http://camel.apache.org/schema/spring}batch-config>,<{http://camel.apache.org/schema/spring}bean>,<{http://camel.apache.org/schema/spring}beanio>,<{http://camel.apache.org/schema/spring}bindy>,<{http://camel.apache.org/schema/spring}boon>,<{http://camel.apache.org/schema/spring}castor>,<{http://camel.apache.org/schema/spring}choice>,<{http://camel.apache.org/schema/spring}circuitBreaker>,<{http://camel.apache.org/schema/spring}constant>,<{http://camel.apache.org/schema/spring}contextScan>,<{http://camel.apache.org/schema/spring}convertBodyTo>,<{http://camel.apache.org/schema/spring}crypto>,<{http://camel.apache.org/schema/spring}csv>,<{http://camel.apache.org/schema/spring}customDataFormat>,<{http://camel.apache.org/schema/spring}customLoadBalancer>,<{http://camel.apache.org/schema/spring}dataFormats>,<{http://camel.apache.org/schema/spring}delay>,<{http://camel.apache.org/schema/spring}delete>,<{http://camel.apache.org/schema/spring}description>,<{http://camel.apache.org/schema/spring}doCatch>,<{http://camel.apache.org/schema/spring}doFinally>,<{http://camel.apache.org/schema/spring}doTry>,<{http://camel.apache.org/schema/spring}dynamicRouter>,<{http://camel.apache.org/schema/spring}el>,<{http://camel.apache.org/schema/spring}enrich>,<{http://camel.apache.org/schema/spring}exchangeProperty>,<{http://camel.apache.org/schema/spring}expression>,<{http://camel.apache.org/schema/spring}expressionDefinition>,<{http://camel.apache.org/schema/spring}failover>,<{http://camel.apache.org/schema/spring}filter>,<{http://camel.apache.org/schema/spring}flatpack>,<{http://camel.apache.org/schema/spring}from>,<{http://camel.apache.org/schema/spring}get>,<{http://camel.apache.org/schema/spring}groovy>,<{http://camel.apache.org/schema/spring}gzip>,<{http://camel.apache.org/schema/spring}head>,<{http://camel.apache.org/schema/spring}header>,<{http://camel.apache.org/schema/spring}hessian>,<{http://camel.apache.org/schema/spring}hl7>,<{http://camel.apache.org/schema/spring}ical>,<{http://camel.apache.org/schema/spring}idempotentConsumer>,<{http://camel.apache.org/schema/spring}inOnly>,<{http://camel.apache.org/schema/spring}inOut>,<{http://camel.apache.org/schema/spring}intercept>,<{http://camel.apache.org/schema/spring}interceptFrom>,<{http://camel.apache.org/schema/spring}interceptSendToEndpoint>,<{http://camel.apache.org/schema/spring}jacksonxml>,<{http://camel.apache.org/schema/spring}javaScript>,<{http://camel.apache.org/schema/spring}jaxb>,<{http://camel.apache.org/schema/spring}jibx>,<{http://camel.apache.org/schema/spring}json>,<{http://camel.apache.org/schema/spring}jsonpath>,<{http://camel.apache.org/schema/spring}jxpath>,<{http://camel.apache.org/schema/spring}language>,<{http://camel.apache.org/schema/spring}loadBalance>,<{http://camel.apache.org/schema/spring}log>,<{http://camel.apache.org/schema/spring}loop>,<{http://camel.apache.org/schema/spring}lzf>,<{http://camel.apache.org/schema/spring}marshal>,<{http://camel.apache.org/schema/spring}method>,<{http://camel.apache.org/schema/spring}mime-multipart>,<{http://camel.apache.org/schema/spring}multicast>,<{http://camel.apache.org/schema/spring}mvel>,<{http://camel.apache.org/schema/spring}ognl>,<{http://camel.apache.org/schema/spring}onCompletion>,<{http://camel.apache.org/schema/spring}onException>,<{http://camel.apache.org/schema/spring}optimisticLockRetryPolicy>,<{http://camel.apache.org/schema/spring}options>,<{http://camel.apache.org/schema/spring}otherwise>,<{http://camel.apache.org/schema/spring}packageScan>,<{http://camel.apache.org/schema/spring}param>,<{http://camel.apache.org/schema/spring}patch>,<{http://camel.apache.org/schema/spring}pgp>,<{http://camel.apache.org/schema/spring}php>,<{http://camel.apache.org/schema/spring}pipeline>,<{http://camel.apache.org/schema/spring}policy>,<{http://camel.apache.org/schema/spring}pollEnrich>,<{http://camel.apache.org/schema/spring}post>,<{http://camel.apache.org/schema/spring}process>,<{http://camel.apache.org/schema/spring}properties>,<{http://camel.apache.org/schema/spring}property>,<{http://camel.apache.org/schema/spring}protobuf>,<{http://camel.apache.org/schema/spring}put>,<{http://camel.apache.org/schema/spring}python>,<{http://camel.apache.org/schema/spring}random>,<{http://camel.apache.org/schema/spring}recipientList>,<{http://camel.apache.org/schema/spring}redeliveryPolicy>,<{http://camel.apache.org/schema/spring}ref>,<{http://camel.apache.org/schema/spring}removeHeader>,<{http://camel.apache.org/schema/spring}removeHeaders>,<{http://camel.apache.org/schema/spring}removeProperties>,<{http://camel.apache.org/schema/spring}removeProperty>,<{http://camel.apache.org/schema/spring}resequence>,<{http://camel.apache.org/schema/spring}responseHeader>,<{http://camel.apache.org/schema/spring}responseMessage>,<{http://camel.apache.org/schema/spring}rest>,<{http://camel.apache.org/schema/spring}restBinding>,<{http://camel.apache.org/schema/spring}restConfiguration>,<{http://camel.apache.org/schema/spring}restContextRef>,<{http://camel.apache.org/schema/spring}restProperty>,<{http://camel.apache.org/schema/spring}rests>,<{http://camel.apache.org/schema/spring}rollback>,<{http://camel.apache.org/schema/spring}roundRobin>,<{http://camel.apache.org/schema/spring}route>,<{http://camel.apache.org/schema/spring}routeBuilder>,<{http://camel.apache.org/schema/spring}routeContextRef>,<{http://camel.apache.org/schema/spring}routes>,<{http://camel.apache.org/schema/spring}routingSlip>,<{http://camel.apache.org/schema/spring}rss>,<{http://camel.apache.org/schema/spring}ruby>,<{http://camel.apache.org/schema/spring}sample>,<{http://camel.apache.org/schema/spring}script>,<{http://camel.apache.org/schema/spring}secureXML>,<{http://camel.apache.org/schema/spring}serialization>,<{http://camel.apache.org/schema/spring}setBody>,<{http://camel.apache.org/schema/spring}setExchangePattern>,<{http://camel.apache.org/schema/spring}setFaultBody>,<{http://camel.apache.org/schema/spring}setHeader>,<{http://camel.apache.org/schema/spring}setOutHeader>,<{http://camel.apache.org/schema/spring}setProperty>,<{http://camel.apache.org/schema/spring}simple>,<{http://camel.apache.org/schema/spring}soapjaxb>,<{http://camel.apache.org/schema/spring}sort>,<{http://camel.apache.org/schema/spring}spel>,<{http://camel.apache.org/schema/spring}split>,<{http://camel.apache.org/schema/spring}sql>,<{http://camel.apache.org/schema/spring}sticky>,<{http://camel.apache.org/schema/spring}stop>,<{http://camel.apache.org/schema/spring}stream-config>,<{http://camel.apache.org/schema/spring}string>,<{http://camel.apache.org/schema/spring}syslog>,<{http://camel.apache.org/schema/spring}tarfile>,<{http://camel.apache.org/schema/spring}terser>,<{http://camel.apache.org/schema/spring}threadPoolProfile>,<{http://camel.apache.org/schema/spring}threads>,<{http://camel.apache.org/schema/spring}throttle>,<{http://camel.apache.org/schema/spring}throwException>,<{http://camel.apache.org/schema/spring}tidyMarkup>,<{http://camel.apache.org/schema/spring}to>,<{http://camel.apache.org/schema/spring}toD>,<{http://camel.apache.org/schema/spring}tokenize>,<{http://camel.apache.org/schema/spring}topic>,<{http://camel.apache.org/schema/spring}transacted>,<{http://camel.apache.org/schema/spring}transform>,<{http://camel.apache.org/schema/spring}univocity-csv>,<{http://camel.apache.org/schema/spring}univocity-fixed>,<{http://camel.apache.org/schema/spring}univocity-header>,<{http://camel.apache.org/schema/spring}univocity-tsv>,<{http://camel.apache.org/schema/spring}unmarshal>,<{http://camel.apache.org/schema/spring}validate>,<{http://camel.apache.org/schema/spring}verb>,<{http://camel.apache.org/schema/spring}vtdxml>,<{http://camel.apache.org/schema/spring}weighted>,<{http://camel.apache.org/schema/spring}when>,<{http://camel.apache.org/schema/spring}wireTap>,<{http://camel.apache.org/schema/spring}xmlBeans>,<{http://camel.apache.org/schema/spring}xmljson>,<{http://camel.apache.org/schema/spring}xmlrpc>,<{http://camel.apache.org/schema/spring}xpath>,<{http://camel.apache.org/schema/spring}xquery>,<{http://camel.apache.org/schema/spring}xstream>,<{http://camel.apache.org/schema/spring}xtokenize>,<{http://camel.apache.org/schema/spring}yaml>,<{http://camel.apache.org/schema/spring}zip>,<{http://camel.apache.org/schema/spring}zipFile>
javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"interceptFrom"). Expected elements are <{http://camel.apache.org/schema/spring}aggregate>,<{http://camel.apache.org/schema/spring}aop>,<{http://camel.apache.org/schema/spring}avro>,<{http://camel.apache.org/schema/spring}barcode>,<{http://camel.apache.org/schema/spring}base64>,<{http://camel.apache.org/schema/spring}batch-config>,<{http://camel.apache.org/schema/spring}bean>,<{http://camel.apache.org/schema/spring}beanio>,<{http://camel.apache.org/schema/spring}bindy>,<{http://camel.apache.org/schema/spring}boon>,<{http://camel.apache.org/schema/spring}castor>,<{http://camel.apache.org/schema/spring}choice>,<{http://camel.apache.org/schema/spring}circuitBreaker>,<{http://camel.apache.org/schema/spring}constant>,<{http://camel.apache.org/schema/spring}contextScan>,<{http://camel.apache.org/schema/spring}convertBodyTo>,<{http://camel.apache.org/schema/spring}crypto>,<{http://camel.apache.org/schema/spring}csv>,<{http://camel.apache.org/schema/spring}customDataFormat>,<{http://camel.apache.org/schema/spring}customLoadBalancer>,<{http://camel.apache.org/schema/spring}dataFormats>,<{http://camel.apache.org/schema/spring}delay>,<{http://camel.apache.org/schema/spring}delete>,<{http://camel.apache.org/schema/spring}description>,<{http://camel.apache.org/schema/spring}doCatch>,<{http://camel.apache.org/schema/spring}doFinally>,<{http://camel.apache.org/schema/spring}doTry>,<{http://camel.apache.org/schema/spring}dynamicRouter>,<{http://camel.apache.org/schema/spring}el>,<{http://camel.apache.org/schema/spring}enrich>,<{http://camel.apache.org/schema/spring}exchangeProperty>,<{http://camel.apache.org/schema/spring}expression>,<{http://camel.apache.org/schema/spring}expressionDefinition>,<{http://camel.apache.org/schema/spring}failover>,<{http://camel.apache.org/schema/spring}filter>,<{http://camel.apache.org/schema/spring}flatpack>,<{http://camel.apache.org/schema/spring}from>,<{http://camel.apache.org/schema/spring}get>,<{http://camel.apache.org/schema/spring}groovy>,<{http://camel.apache.org/schema/spring}gzip>,<{http://camel.apache.org/schema/spring}head>,<{http://camel.apache.org/schema/spring}header>,<{http://camel.apache.org/schema/spring}hessian>,<{http://camel.apache.org/schema/spring}hl7>,<{http://camel.apache.org/schema/spring}ical>,<{http://camel.apache.org/schema/spring}idempotentConsumer>,<{http://camel.apache.org/schema/spring}inOnly>,<{http://camel.apache.org/schema/spring}inOut>,<{http://camel.apache.org/schema/spring}intercept>,<{http://camel.apache.org/schema/spring}interceptFrom>,<{http://camel.apache.org/schema/spring}interceptSendToEndpoint>,<{http://camel.apache.org/schema/spring}jacksonxml>,<{http://camel.apache.org/schema/spring}javaScript>,<{http://camel.apache.org/schema/spring}jaxb>,<{http://camel.apache.org/schema/spring}jibx>,<{http://camel.apache.org/schema/spring}json>,<{http://camel.apache.org/schema/spring}jsonpath>,<{http://camel.apache.org/schema/spring}jxpath>,<{http://camel.apache.org/schema/spring}language>,<{http://camel.apache.org/schema/spring}loadBalance>,<{http://camel.apache.org/schema/spring}log>,<{http://camel.apache.org/schema/spring}loop>,<{http://camel.apache.org/schema/spring}lzf>,<{http://camel.apache.org/schema/spring}marshal>,<{http://camel.apache.org/schema/spring}method>,<{http://camel.apache.org/schema/spring}mime-multipart>,<{http://camel.apache.org/schema/spring}multicast>,<{http://camel.apache.org/schema/spring}mvel>,<{http://camel.apache.org/schema/spring}ognl>,<{http://camel.apache.org/schema/spring}onCompletion>,<{http://camel.apache.org/schema/spring}onException>,<{http://camel.apache.org/schema/spring}optimisticLockRetryPolicy>,<{http://camel.apache.org/schema/spring}options>,<{http://camel.apache.org/schema/spring}otherwise>,<{http://camel.apache.org/schema/spring}packageScan>,<{http://camel.apache.org/schema/spring}param>,<{http://camel.apache.org/schema/spring}patch>,<{http://camel.apache.org/schema/spring}pgp>,<{http://camel.apache.org/schema/spring}php>,<{http://camel.apache.org/schema/spring}pipeline>,<{http://camel.apache.org/schema/spring}policy>,<{http://camel.apache.org/schema/spring}pollEnrich>,<{http://camel.apache.org/schema/spring}post>,<{http://camel.apache.org/schema/spring}process>,<{http://camel.apache.org/schema/spring}properties>,<{http://camel.apache.org/schema/spring}property>,<{http://camel.apache.org/schema/spring}protobuf>,<{http://camel.apache.org/schema/spring}put>,<{http://camel.apache.org/schema/spring}python>,<{http://camel.apache.org/schema/spring}random>,<{http://camel.apache.org/schema/spring}recipientList>,<{http://camel.apache.org/schema/spring}redeliveryPolicy>,<{http://camel.apache.org/schema/spring}ref>,<{http://camel.apache.org/schema/spring}removeHeader>,<{http://camel.apache.org/schema/spring}removeHeaders>,<{http://camel.apache.org/schema/spring}removeProperties>,<{http://camel.apache.org/schema/spring}removeProperty>,<{http://camel.apache.org/schema/spring}resequence>,<{http://camel.apache.org/schema/spring}responseHeader>,<{http://camel.apache.org/schema/spring}responseMessage>,<{http://camel.apache.org/schema/spring}rest>,<{http://camel.apache.org/schema/spring}restBinding>,<{http://camel.apache.org/schema/spring}restConfiguration>,<{http://camel.apache.org/schema/spring}restContextRef>,<{http://camel.apache.org/schema/spring}restProperty>,<{http://camel.apache.org/schema/spring}rests>,<{http://camel.apache.org/schema/spring}rollback>,<{http://camel.apache.org/schema/spring}roundRobin>,<{http://camel.apache.org/schema/spring}route>,<{http://camel.apache.org/schema/spring}routeBuilder>,<{http://camel.apache.org/schema/spring}routeContextRef>,<{http://camel.apache.org/schema/spring}routes>,<{http://camel.apache.org/schema/spring}routingSlip>,<{http://camel.apache.org/schema/spring}rss>,<{http://camel.apache.org/schema/spring}ruby>,<{http://camel.apache.org/schema/spring}sample>,<{http://camel.apache.org/schema/spring}script>,<{http://camel.apache.org/schema/spring}secureXML>,<{http://camel.apache.org/schema/spring}serialization>,<{http://camel.apache.org/schema/spring}setBody>,<{http://camel.apache.org/schema/spring}setExchangePattern>,<{http://camel.apache.org/schema/spring}setFaultBody>,<{http://camel.apache.org/schema/spring}setHeader>,<{http://camel.apache.org/schema/spring}setOutHeader>,<{http://camel.apache.org/schema/spring}setProperty>,<{http://camel.apache.org/schema/spring}simple>,<{http://camel.apache.org/schema/spring}soapjaxb>,<{http://camel.apache.org/schema/spring}sort>,<{http://camel.apache.org/schema/spring}spel>,<{http://camel.apache.org/schema/spring}split>,<{http://camel.apache.org/schema/spring}sql>,<{http://camel.apache.org/schema/spring}sticky>,<{http://camel.apache.org/schema/spring}stop>,<{http://camel.apache.org/schema/spring}stream-config>,<{http://camel.apache.org/schema/spring}string>,<{http://camel.apache.org/schema/spring}syslog>,<{http://camel.apache.org/schema/spring}tarfile>,<{http://camel.apache.org/schema/spring}terser>,<{http://camel.apache.org/schema/spring}threadPoolProfile>,<{http://camel.apache.org/schema/spring}threads>,<{http://camel.apache.org/schema/spring}throttle>,<{http://camel.apache.org/schema/spring}throwException>,<{http://camel.apache.org/schema/spring}tidyMarkup>,<{http://camel.apache.org/schema/spring}to>,<{http://camel.apache.org/schema/spring}toD>,<{http://camel.apache.org/schema/spring}tokenize>,<{http://camel.apache.org/schema/spring}topic>,<{http://camel.apache.org/schema/spring}transacted>,<{http://camel.apache.org/schema/spring}transform>,<{http://camel.apache.org/schema/spring}univocity-csv>,<{http://camel.apache.org/schema/spring}univocity-fixed>,<{http://camel.apache.org/schema/spring}univocity-header>,<{http://camel.apache.org/schema/spring}univocity-tsv>,<{http://camel.apache.org/schema/spring}unmarshal>,<{http://camel.apache.org/schema/spring}validate>,<{http://camel.apache.org/schema/spring}verb>,<{http://camel.apache.org/schema/spring}vtdxml>,<{http://camel.apache.org/schema/spring}weighted>,<{http://camel.apache.org/schema/spring}when>,<{http://camel.apache.org/schema/spring}wireTap>,<{http://camel.apache.org/schema/spring}xmlBeans>,<{http://camel.apache.org/schema/spring}xmljson>,<{http://camel.apache.org/schema/spring}xmlrpc>,<{http://camel.apache.org/schema/spring}xpath>,<{http://camel.apache.org/schema/spring}xquery>,<{http://camel.apache.org/schema/spring}xstream>,<{http://camel.apache.org/schema/spring}xtokenize>,<{http://camel.apache.org/schema/spring}yaml>,<{http://camel.apache.org/schema/spring}zip>,<{http://camel.apache.org/schema/spring}zipFile>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:740)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:262)
Probably I need to wrap the interceptFrom using a element similar to the way I wrapped the Rest and RouteDefinitions. But, not sure how.
I am not sure if I am doing it the correct way.
Can somehow help me on this.
Also, I see there is a InterceptStrategy which can be set to the camelcontext.
Is there a way I can use that to do AOP like processsing for my routes by applying the caching concern instead of InterceptFrom.
Also, my Camel Application is based on Spring Boot, so is there any feature in Spring Boot which I can use to intercept the route calls.
I have added the sample project which I had created to load my routes and apiroutes in this repo using XML files. Similarly, I would want to apply the cross cutting concern of caching using interceptors so that they do not mix with route logic. I am looking for a way to use the interceptFrom camel feature so that I can intercept every message to a route and handle them accordingly. I am not sure how to load the interceptors or how to have them linked with the routes.
https://github.com/sri420/compositerepo/tree/master/CompositeApplication
I have currently removed the code which I had added to load the interceptors because of namespace error. Once, I get the correct approach of the solution I will add the same accordingly.
Can you give the full Intercept.xml? Seems your Intercept.xml xml file have the wrong namespace, just like
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- intercept incoming messages and route them to the mock:middle1 endpoint
before we proceed and continue routing from the point of interceptions, that
is mock:end will be the next target -->
<interceptFrom>
<to uri="mock:middle1"/>
</interceptFrom>
<!-- here we have a very simple route -->
<route>
<from uri="direct:start"/>
<to uri="mock:end"/>
</route>
</camelContext>

Camel SOAP CXF Call With Dynamic Addresses

I'm trying to write a SOAP Web Service that:
accepts one request type A
maps request A to another outbound request type B
sends request B to an external SOAP service
maps the response B back to a response A object (and returns it)
I have this working when the endpoint (B) is statically configured.
But I want to be able to hit a variety of services with varying request/response types. These would probably be configured via a properties file.
Is it possible to do this in some generic/dynamic way?
Here's my spring camel XML:
<!— SOAP inbound service —>
<cxf:cxfEndpoint
id="paymentService_A"
serviceClass="#paymentServiceBean"
address="/PaymentService"/>
<!— SOAP outbound service —>
<cxf:cxfEndpoint
id=“paymentService_B"
wsdlURL="http://localhost:9080/externalpayment/ExternalPaymentService?wsdl"
serviceClass="com.yngwietiger.ExternalPayment"
address="http://localhost:9080/externalpayment/ExternalPaymentService"/>
<!— MAP from inbound SOAP request object to external SOAP request object —>
<bean id="mapAToB_RequestProcessor" class="com.yngwietiger.MyProcessor"/>
<!— MAP external SOAP response to a response for the initial/inbound SOAP request —>
<bean id="mapBToA_ResponseProcessor" class="com.yngwietiger.MyPostProcessor"/>
<camel:camelContext id="camelContext">
<camel:route>
<camel:from uri="cxf:bean:paymentService_A"/>
<camel:process ref="mapAToB_RequestProcessor"/>
<camel:to uri="cxf:bean:paymentService_B"/>
<camel:process ref="mapBToA_ResponseProcessor"/>
</camel:route>
</camel:camelContext>
Obviously, I'm using Camel's cxfEndpoint bean. But I don't see any way to set the address, wsdlURL, etc for each request. Is that possible?
Or am I going to have to build a route for each type? If so, how do I build one of these cxfEndpoints dynamically?
Would using Spring's WS Template be more flexible?
Is there a better way that I should be doing this?
Thanks in advance.
Camel Recipient List would better fit into your requirement. This is the link, http://camel.apache.org/recipient-list.html. You have to generate the dynamic endpoint and set into the header somewhere in the route and call the recipient list.
I think you can use HTTP endpoint for your outbound message.
As it is done in the example here

How can I execute a Camel route on shutdown only?

I have a Camel 2.13.1 application which uses an external web service which I access through the CXF component. I use the startupOrder attribute of the Spring XML route element to ensure that a call is made to the Login operation of the web service in a route I've set up to be called once at startup (using the timer component).
When my application is shutting down I want Camel to call the web service and execute the logout operation but I can't see a good way of doing this. I'm using the Spring DSL at the moment and am looking into the org.apache.camel.spi.ShutdownStrategy interface as my only hope but will I be able to execute a route that contains my CXF producer from it? Can't see how at the moment.
Looking for some options and would prefer to use the Spring DSL to specify the route like so:-
<route id="logoutFromWebServiceOnShutdownRoute">
<from uri="direct:logoutFromWebServiceOnShutdown" />
<process ref="prepareWebServiceLogoutProcessor" />
<to uri="cxf:bean:webServiceEndpoint?defaultOperationName=logout" />
<process ref="webServiceLogoutResponseProcessor" />
</route>
Just need to know how to call it on shutdown only! I'm running Camel as a WAR.
I've tried the route policy but can't get it working. I need the route in question to run once only on shutdown and can't see how that can be accomplished using the route policy.
Instead, I've utilised Spring by including a destroy-method attribute on a bean which calls my Logout code.
<bean class="com.chris.MyAuthenticationManager" destroy-method="logout" />
This runs after Camel has shut down and allows me to run the code only once. The down side is that I can't use Camel to logout and my login code is different to my logout code. However, it works and is now stable.

How to send HTTP post request using spring

What configuration do i need to send HTTP post request through spring. I am using java application , it's not a web project. Can i use spring to send HTTP post request? I google it but most almost all examples are using spring MVC. Can i use just spring to send HTTP post request ?
I found this bean on net but I don't know what to do after it. I am using spring3.2 and this post i think is of year 2008...
<bean id="httpClient" class="org.springbyexample.httpclient.HttpClientTemplate">
<property name="defaultUri">
<value><![CDATA[http://localhost:8093/test]]></value>
</property>
</bean>
Any suggestions?
If you are using Spring 3.0+, it will be better to use RestTemplate for sending HTTP requests. Once you wire the RestTemplate (API), you can use different methods in it to send different types of HTTP requests.
You don't need Spring just to issue a HTTP post, see this post: Using java.net.URLConnection to fire and handle HTTP requests
And yes you can use Spring in a non-web application / command line application. Just create an instance of ApplicationContext (eg: ClassPathApplicationContext with path to your beans xml configuration injected)

Resources