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/[email protected]/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()).toByteArray()));
}
}
}
> -----Ursprüngliche Nachricht-----
> Von: Sergey Beryozkin [mailto:[email protected]]
> Gesendet: Dienstag, 22. Mai 2012 16:38
> An: [email protected]
> Betreff: Re: AW: Correct phase for XSLT In-Interceptor
>
> Hi Anne
> On 22/05/12 14:48, Diefenbach, Anne wrote:
> > Hi Freeman,
> >
> > thanks for the answer. Unfortunately, I've already written the
> stylesheet, so I'm pretty sure it's going to take me less time to write
> the interceptor than to familiarize myself with the transformation
> feature.
> >
> The transformation feature will perform much faster than the XSLT
> transformation and it is actually easy to setup.
>
> However it has at least a couple of limitations that may require a
> custom transformation, specifically, no conditional transformations are
> supported (say, add an element only if a given text value is set to 'a',
> etc) and it is not possible to change only an individual sibling,
> example, given <a><b/><b/></a>, it is not possible to remove a second
> <b/> only.
>
> FYI, the transformation in interceptor runs at POST-STREAM phase which
> can also be changed, not sure though what stage you'd have to run the
> XSLT transformation
>
> HTH, Sergey
>
> > Anne
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Freeman Fang [mailto:[email protected]]
> >> Gesendet: Dienstag, 22. Mai 2012 15:06
> >> An: [email protected]
> >> Betreff: Re: Correct phase for XSLT In-Interceptor
> >>
> >> Hi,
> >>
> >> You probably needn't write that interceptor yourself, take a look at
> >> transformation feature[1] CXF already have, to see if it can meet your
> >> requirement.
> >> [1]http://cxf.apache.org/docs/transformationfeature.html
> >>
> >> Freeman
> >> On 2012-5-22, at 下午6:30, Diefenbach, Anne wrote:
> >>
> >>> Hi,
> >>>
> >>> I'm trying to determine the correct phase for an interceptor
> >>> performing XSL transformations on incoming messages. I can't figure
> >>> out if it's POST_STREAM, READ or one of the PROTOCOL phases. I'm
> >>> extending AbstractSoapInterceptor (and if that's not the correct
> >>> choice, I would be thankful if you could tell me that, too).
> >>>
> >>> Thanks for any tips,
> >>> Anne
> >>>
> >>
> >> ---------------------------------------------
> >> Freeman Fang
> >>
> >> FuseSource
> >> Email:[email protected]
> >> Web: fusesource.com
> >> Twitter: freemanfang
> >> Blog: http://freemanfang.blogspot.com
> >> http://blog.sina.com.cn/u/1473905042
> >> weibo: http://weibo.com/u/1473905042
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com