cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: AW: AW: Correct phase for XSLT In-Interceptor
Date Tue, 22 May 2012 16:10:01 GMT

That should work fine, providing the resulting message isn't very large.  
The ByteArrayOutputStream obviously involves pulling in the whole message 
into memory.   You could use the CXF CachedOutputStream to allow spilling to 
disk if a threshold is reached.

Another option could be to use a DOMResult to transform to DOM.   Take the 
resulting DOM, create an XMLStreamReader from it 
(StaxUtils.createXMLStreamReader) and set that into the content of the 
message.   Would help performance slightly as it won't need to reparse the 
byte[].

Anyway, what you have should work fine, just offering some optimizations.  
:-)


Dan


On Tuesday, May 22, 2012 03:37:05 PM Diefenbach, Anne wrote:
> From the quick glance I gave the transform feature before I started in on
> the interceptor, I do think it wouldn't be able to do all the
> transformations I need. And I think I got my interceptor - if someone
> could give it a glance to see if they think it should work I would be
> thankful; I've never written one before and worked off an example for an
> outbound XSLT interceptor
> (http://www.mail-archive.com/cxf-user@incubator.apache.org/msg04344.html)
> .
 
> Thanks a lot,
> Anne
> 
> public class XSLTInInterceptor extends AbstractSoapInterceptor {
> 	private InputStream originalIS;
> 
>     public XSLTInInterceptor() {
>         super(Phase.POST_STREAM);
>     }
> 
>     public void handleMessage(SoapMessage message) throws Fault {
> 		// TODO Auto-generated method stub
>     	if (message == message.getExchange().getInMessage()) {
>     		originalIS = message.getContent(InputStream.class);
>     		StreamSource src = new StreamSource(originalIS);
>     		StreamSource stylesheet = new
> StreamSource(XSLTInInterceptor.class.getResourceAsStream("./Data.xsl"));
> StreamResult result = new StreamResult(new ByteArrayOutputStream()); 
>             TransformerFactory factory =
> TransformerFactory.newInstance();
 try {
>                 Transformer t = factory.newTransformer(stylesheet);
>                 t.transform(src, result);
>             } catch (TransformerConfigurationException e) {
>                 e.printStackTrace();
>             } catch (TransformerException e) {
>                 e.printStackTrace();
>             }
> 
>             message.setContent(InputStream.class,new
> ByteArrayInputStream(((ByteArrayOutputStream)result.getOutputStream()).to
> ByteArray()));
 }
>     }
> }
> 
> 

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


Mime
View raw message