2008/9/16 James Strachan <[EMAIL PROTECTED]>:
> 2008/9/16 raulvk.soa <[EMAIL PROTECTED]>:
>>
>> Hi Claus,
>>
>> My requirement is a bit different... I need to print human-readable messages
>> such as "Validating against XML Schema...", "Validation OK", "Validation
>> ERROR", etc... Therefore, I need to be able to specify the message that
>> should be printed out when I am building the route.
>>
>> Don't know if I have expressed myself clearly...
>>
>> Is there any functionality in Camel that will allow me to do send custom log
>> messages to the Log component?
>
> You could use a templating engine to transform the message into a
> human readable format first, before routing it to the log component.
>
> See...
> http://activemq.apache.org/camel/templating.html
>
> for example
>
> from("...").
> to("velocity:scripts/Validating.vm").
> to("log:Validating");
>
> then your Validating.vm script could generate text extracting some
> headers or payload from the message etc.
>
> Maybe if the logging information is simpler; we could just use normal
> expressions?
>
> e.g. using the EL as a kinda templating engine
>
> from("...").
> setBody().el("Validating ${in.header.foo} blah").
> to("log:Validating");
>
> Templating engines come into their own when you are composing a large
> page of text such as an email with embedded values; if its a single
> line of text for a log message or SMS or something then using EL or
> XPath or something might be simpler as you can inline the expression
> inside your route.
One thought though; imagine if you want to log at each step of a
route; its currently a bit icky if you transform the message at each
step. e.g.
from("...").
multicast().
block().
setBody().el("About to invoke bean with ${body}").to("log:Foo").
end().
bean(Foo.class).
multicast().
block().
setBody().el("About to invoke bean with ${body}").to("log:Bar").
end().
bean(Bar.class)
i.e. having to use some kinda multicast/block syntax to avoid the
transformed log message from being used in the actual pipeline.
I wonder if we can come up with some kinda neater syntax, that allows
us to spawn off a oneway 'transform and send' type step within a route
easier?
We could add logging to the DSL for this specific use case - though it
does feel a bit like we should make it easier to support
transform-and-send-but-continue-with-previous-message more easily in
the DSL. Any thoughts?
For logging maybe we could do something like
from("....").
log("SomeCategory").el("My message ${in.header.foo}").
bean(Foo.class).
log("Bar").el("About to invoke bean with ${body}").
bean(Bar.class);
Or maybe we come up with an alternative to the "to()" method which
takes an expression? Something like...
from("....").
transformTo("log:SomeCategory").el("My message ${in.header.foo}").
bean(Foo.class).
transformTo("log:Bar").el("About to invoke bean with ${body}").
bean(Bar.class);
So that transformTo() does a transform first, using the given
expression (in the above example using EL) then sends it to the given
endpoint - but then returns the previous message exchange? Then this
way its not logging specific. So we could use it to fire off emails
during the route or fire off SMS texts or whatever
from("....").
transformTo("smtp:[EMAIL PROTECTED]").el("My message ${in.header.foo}").
bean(Foo.class).
transformTo("sms:1234567").el("About to invoke bean with ${body}").
bean(Bar.class);
Am not sure about the name; transformTo() - maybe forwardTo()? Or
forwardTransform()? Maybe it should start with "to..." as its kinda
like to(endpoint) but just that it also takes an expression; so maybe
"toWithTransform()" maybe?
Thoughts?
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://open.iona.com