You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Lowry <lo...@gmail.com> on 2014/07/23 18:35:39 UTC

cxf transformation feature - could code be ported and used in Camel?

The CXF transformation feature provides a nice way to declaratively specifiy
certain simple transformations, element names, adds elements, changes
namespace, etc. It makes it easy to describe the transformation in a map in
Spring XML. I haven't found anything similar to declare transformation with
Apache Camel. I tried using CXF xformation feature with camel but found to
be tightly tied to the CXF endpoint rather any arbitrary location within a
camel route. So, would it be difficult to write a camel component that
possibly re-uses CXF code "org.apache.cxf.feature.StaxTransformFeature" and
underlying code  ?




--
View this message in context: http://cxf.547215.n5.nabble.com/cxf-transformation-feature-could-code-be-ported-and-used-in-Camel-tp5746812.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: cxf transformation feature - could code be ported and used in Camel?

Posted by Lowry <lo...@gmail.com>.
Excellent, thanks Dan!
I'll give this a try and and report back on how it goes.



--
View this message in context: http://cxf.547215.n5.nabble.com/cxf-transformation-feature-could-code-be-ported-and-used-in-Camel-tp5746812p5746814.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: cxf transformation feature - could code be ported and used in Camel?

Posted by Lowry <lo...@gmail.com>.
Just to follow-up.. I seem to have gotten this to work with the following in
my processing bean:

    public void process(Exchange exchange) throws Exception {
    	log.debug("Entered TransformFeature process() method...");
    	InputStream is = exchange.getIn().getBody(java.io.InputStream.class);
    	// TODO I get a wierd encoding "UTF-8" not supported WARNING in the 
    	// karaf console, could potentially change encoding appropriately here
to workaround?
    	XMLStreamReader reader = StaxUtils.createXMLStreamReader(is);
    	// closing underlying input stream because it wasn't getting closed
    	// when coming from a file component
    	is.close();
    	if ((reader != null) && (inElementsMap != null || inAppendMap != null
|| inDropElements != null)) {
	    	log.debug("Creating InTransformReader...");
	    	reader = new InTransformReader(reader, inElementsMap, inAppendMap,
inDropElements,	null, blockOriginalReader);
		}
		// possilbly could have used Identity transform here to transform the STAX
source to Stream result string
		Document d = StaxUtils.read(reader);
		exchange.getIn().setBody(d,  org.w3c.dom.Document.class);
    }





--
View this message in context: http://cxf.547215.n5.nabble.com/cxf-transformation-feature-could-code-be-ported-and-used-in-Camel-tp5746812p5747047.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: cxf transformation feature - could code be ported and used in Camel?

Posted by Lowry <lo...@gmail.com>.
I added a  custom bean processor (see below) to my camel route where i want
to use the CXF InTransformReader to do some transformation as prescribed.
There seems to be a problem though. No type convertor in camel to convert
the underlying 'ValidatingStreamReader' into type understood by Camel. Does
this mean i'll need to implement my own type convertor to make this work?
The error occurs when my processor returns and the message continues in the
camel route pipeline.


    public void process(Exchange exchange) throws Exception {
         log.debug("Entered TransformFeature process() method...");
         XMLStreamReader reader =
(XMLStreamReader)exchange.getIn().getBody();
         if ((reader != null) && (inElementsMap != null || inAppendMap !=
null || inDropElements != null)) {
                 log.debug("Creating InTransformReader...");
                 reader = new InTransformReader(reader, inElementsMap,
inAppendMap, inDropElements,      null, blockOriginalReader);
                }
                exchange.getIn().setBody(reader, XMLStreamReader.class);
        }
 
 
 
- No type converter available to convert from type:
org.apache.cxf.staxutils.transform.InTransformReader to the required type:
java.io.InputStream with value
com.ctc.wstx.sr.ValidatingStreamReader@d6db5b]
 



--
View this message in context: http://cxf.547215.n5.nabble.com/cxf-transformation-feature-could-code-be-ported-and-used-in-Camel-tp5746812p5747005.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: cxf transformation feature - could code be ported and used in Camel?

Posted by Daniel Kulp <dk...@apache.org>.
On Jul 23, 2014, at 12:35 PM, Lowry <lo...@gmail.com> wrote:

> The CXF transformation feature provides a nice way to declaratively specifiy
> certain simple transformations, element names, adds elements, changes
> namespace, etc. It makes it easy to describe the transformation in a map in
> Spring XML. I haven't found anything similar to declare transformation with
> Apache Camel. I tried using CXF xformation feature with camel but found to
> be tightly tied to the CXF endpoint rather any arbitrary location within a
> camel route. So, would it be difficult to write a camel component that
> possibly re-uses CXF code "org.apache.cxf.feature.StaxTransformFeature" and
> underlying code  ?

It shouldn’t be too hard.  In camel, you should be able to do a convertBodyTo(XMLStreamReader.class) or message.getBody(XMLStreamReader.class) or similar and then call the org.apache.cxf.staxutils.transform.InTransformReader constructor with the appropriate maps.   I don’t think anything in org.apache.cfx.staxutils.transform has any dependency on any of the endpoint settings, annotations, etc… 

Simple thing might be to create a Processor in Camel that would do much the same as the transformationFeature stuff in CXF.   Would take a couple Maps of properties and wrappers the XMLStreamReader/Writers.   You could then easily configure that processor on the route.


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com