Before we jump into it, we want to state that this tutorial is about Developers not loosing control. In my humble experience one of the key fears of developers is that they are forced into a tool/framework where they loose control and/or power, and the possible is now impossible. So in this part we stay clear with this vision and our starting point is as follows:
- We have generated the webservice source code using the CXF wsdl2java generator and we have our ReportIncidentEndpointImpl.java file where we as a Developer feels home and have the power.
So the starting point is:
As an end-user you usually use the RouteBuilder as of follows:
- create your own Route class that extends RouteBuilder
- implement your routing DSL in the configure method
So we create a new class ReportIncidentRoutes and implement the first part of the routing:
In the example above we have a very common routing, that can be distilled from pseudo verbs to actual code with:
- from A to B
- From Endpoint A To Endpoint B
from("direct:start") is the consumer that is kick-starting our routing flow. It will wait for messages to arrive on the direct queue and then dispatch the message.
to("velocity:MailBody.vm") is the producer that will receive a message and let Velocity generate the mail body response.
Using a script language to set the filename
We could do as in the previous parts where we send the computed filename as a message header when we "kick-start" the route. But we want to learn new stuff so we look for a different solution using some of Camels many Languages. As OGNL is a favorite language of mine (used by WebWork) so we pick this baby for a Camel ride. For starters we must add it to our pom.xml:
And remember to refresh your editor so you got the new .jars.
In OGNL glory this is done as:
Now we got the expression to dynamic compute the filename on the fly we need to set it on our route so we turn back to our route, where we can add the OGNL expression:
And since we are on Java 1.5 we can use the static import of ognl so we have:
Notice the import static also applies for all the other languages, such as the Bean Language we used previously.
We have just briefly touched the routing in Camel and shown how to implement them using the fluent builder syntax in Java. There is much more to the routing in Camel than shown here, but we are learning step by step. We continue in part 5. See you there.