camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ronny Aerts <ronny.ae...@intris.be>
Subject RE: can I set a message header or exchange property inside an xslt?
Date Tue, 04 Feb 2014 10:35:20 GMT
Hello,

I figured it out and yes it is possible to set message headers and exchange properties in
camel xslt.

I created a separate java file with content (see the methods that are marked static):
package com.intris.camel.component.xslt;

public class xsltmsg {

public static void setHeader (org.apache.camel.Message message, String name, String value)
{
message.setHeader(name, value);
}

public static void setProperty (org.apache.camel.Exchange exchange, String name, String value)
{
exchange.setProperty(name, value);
}
}

I created a xslt file:
<?xml version='1.0'?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsltmsg="java:com.intris.camel.component.xslt.xsltmsg"
exclude-result-prefixes="xsltmsg" >

<xsl:param name="in"/>
<xsl:param name="out"/>
<xsl:param name="exchange"/>

<xsl:template match="/">
<!-- <test>ronny aerts</test> -->
<!-- setting message headers on the "in" does not seem to work -->
<xsl:value-of select="xsltmsg:setHeader($in, 'bbb-1', 'ronny.aerts.1')"/>
<xsl:value-of select="xsltmsg:setHeader($out, 'bbb-2', 'ronny.aerts.2')"/>
<xsl:value-of select="xsltmsg:setProperty($exchange, 'aaa', 'ronny en gerd')"/>
<!-- <test2>after</test2> -->
</xsl:template>
</xsl:stylesheet>

My route looks like:
<route id="test-xslt">
<from uri="timer://xslt-timer?repeatCount=1" />
<pollEnrich uri="file://example-data?fileName=test.xml&amp;noop=true" timeout="2500"
/>
<convertBodyTo type="java.lang.String" />
<to uri="log://before?showExchangePattern=false&amp;showHeaders=true&amp;showProperties=true&amp;multiline=true"
/>
<to uri="xslt://classpath:test.xsl?saxon=false" />
<to uri="log://after?showExchangePattern=false&amp;showHeaders=true&amp;showProperties=true&amp;multiline=true"
/>
<log message="${routeId} end of route" />
</route>

There is still one problem with the above:
net.sf.saxon.trans.XPathException: Cannot find a matching 3-argument function named {java:com.intris.camel.component.xslt.xsltmsg}setHeader().
Note that direct calls to Java methods are not available under Saxon-HE

It seems that camel uses the saxon home edition and with the home edition it not possible
to call java from xslt.

I added a dependency to my project pom and now it works fine.
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>[8.7,)</version>
</dependency>
A part of the output is:
, Properties: {aaa=ronny en gerd, ...
, Headers: {bbb-2=ronny.aerts.2, ...

The setting of a header on the in does not seem to have an effect.

I would be very handy if there would such a xslt wrapper class for settings message headers,
similar to one I created.
--
Kind regards,
Ronny Aerts - Intris nv - Wapenstilstandlaan 47, 2600 Berchem, Belgium
R&D Integration Architect
Prince II certified
Tel: +32-3-326.50.75


-----Original Message-----
From: Ronny Aerts [mailto:ronny.aerts@intris.be]
Sent: dinsdag 4 februari 2014 9:41
To: users@camel.apache.org
Subject: RE: can I set a message header or exchange property inside an xslt?

Hello Claus,

Thank you for the feedback.

I searched in the xslt test files and found the org.apache.camel.component.xslt.XsltTransformingExceptionTest.java
in combination with org.apache.camel.component.xslt.MyEcho.java and org/apache/camel/component/xslt/transformCallEcho.xsl.

The xsl file declares xmlns:echo="xalan://org.apache.camel.component.xslt.MyEcho" and later
on the <xsl:value-of select="echo:echoString(string(name))"></xsl:value-of> statement
is called to activate the java code.
As far as I known, this approach is only possible with static methods (in the java code) and
therefore it does not seem possible with camel out of the box. I will try to work something.

--
Kind regards,
Ronny Aerts - Intris nv - Wapenstilstandlaan 47, 2600 Berchem, Belgium R&D Integration
Architect Prince II certified
Tel: +32-3-326.50.75


-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
Sent: maandag 3 februari 2014 19:00
To: users@camel.apache.org
Subject: Re: can I set a message header or exchange property inside an xslt?

Hi

You likely can.
Though I can remember how that is possible.

Try look at the unit tests
https://github.com/apache/camel/tree/master/camel-core/src/test/java/org/apache/camel/component/xslt

And we love contributions. People is welcome to add details on the xslt docs how to do this
http://camel.apache.org/contributing

On Mon, Feb 3, 2014 at 3:16 PM, Ronny Aerts <ronny.aerts@intris.be> wrote:
> Hello camel community,
>
> I'm working on a project where it would be very handy to me if I can set a message header
or exchange property inside the execution of an xslt producer. Is this possible?
>
> I know that the "exchange" and "in" are passed as parameter to the transformation.
>
> --
> Kind regards,
> Ronny Aerts<mailto:ronny.aerts@intris.be> - Intris nv -
> Wapenstilstandlaan 47, 2600 Berchem, Belgium R&D Integration Architect
> Prince II certified
> Tel: +32-3-326.50.75
>
>
> Intris nv
> Wapenstilstandlaan 47
> B-2600 Berchem
>         Tel.  +32 3 326 50 75
> Fax  +32 3 326 42 23
> www.intris.be<http://www.intris.be/>
>
> DISCLAIMER
> This is an e-mail from Intris. The information contained in this communication is intended
solely for use by the individual or entity to whom it is addressed.
> Use of this communication by others is prohibited. If the e-mail message was sent to
you by mistake, please notify support@intris.be<mailto:support@intris.be>, destroy it
without reading, using, copying or disclosing its contents to any other person.
> We accept no liability for damage related to data and/or documents which are communicated
by electronic mail.



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen Make your Camel applications look
hawt, try: http://hawt.io Intris nv Wapenstilstandlaan 47
B-2600 Berchem
        Tel.  +32 3 326 50 75
Fax  +32 3 326 42 23
www.intris.be<http://www.intris.be/>

DISCLAIMER
This is an e-mail from Intris. The information contained in this communication is intended
solely for use by the individual or entity to whom it is addressed.
Use of this communication by others is prohibited. If the e-mail message was sent to you by
mistake, please notify support@intris.be<mailto:support@intris.be>, destroy it without
reading, using, copying or disclosing its contents to any other person.
We accept no liability for damage related to data and/or documents which are communicated
by electronic mail.
Intris nv
Wapenstilstandlaan 47
B-2600 Berchem
        Tel.  +32 3 326 50 75
Fax  +32 3 326 42 23
www.intris.be<http://www.intris.be/>

DISCLAIMER
This is an e-mail from Intris. The information contained in this communication is intended
solely for use by the individual or entity to whom it is addressed.
Use of this communication by others is prohibited. If the e-mail message was sent to you by
mistake, please notify support@intris.be<mailto:support@intris.be>, destroy it without
reading, using, copying or disclosing its contents to any other person.
We accept no liability for damage related to data and/or documents which are communicated
by electronic mail.

Mime
View raw message