Here you go. It looks like below (roughly):
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.phase.Phase;
public class XSLTOutInterceptor extends AbstractSoapInterceptor {
private OutputStream originalOs;
public XSLTOutInterceptor() {
super(Phase.PRE_PROTOCOL);
}
public void handleMessage(SoapMessage message) throws Fault {
boolean isOutbound = false;
isOutbound = message == message.getExchange().getOutMessage()
|| message == message.getExchange().getOutFaultMessage();
if (isOutbound) {
//replace the original output stream with our own outputstream,
//so that the output can be cached for xslt transformation,
otherwise
//the output might be flushed to socket before xslt.
originalOs = message.getContent(OutputStream.class);
CachedOutputStream cos = new CachedOutputStream();
message.setContent(OutputStream.class, cos);
// Add an ending interceptor to read the cached output and do xslt
message.getInterceptorChain().add(new XSLTOutEndingInterceptor());
}
}
public class XSLTOutEndingInterceptor extends AbstractSoapInterceptor {
public XSLTOutEndingInterceptor() {
super(Phase.PRE_PROTOCOL_ENDING);
}
public void handleMessage(SoapMessage message) throws Fault {
try {
CachedOutputStream cos =
(CachedOutputStream)message.getContent(OutputStream.class);
//the output is cached in CachedOutputStream, now lets do xslt.
Transformer trans =m ...
// write the transformed result back to the original output
stream
trans.transform(new StreamSource(cos.getInputStream()), new
StreamResult(originalOs));
//set the original output stream back
message.setContent(OutputStream.class, originalOs);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
> -----Original Message-----
> From: mule1 [mailto:[EMAIL PROTECTED]
> Sent: 2007年11月26日 22:29
> To: [email protected]
> Subject: RE: what would be the best place to introduce xslt transformer for
> response message
>
>
> Hello,
>
> I am not clear exactly what you said. I looked at the SAAJOutInterceptor,
> but didn't clearly understand how I can get the message content - either
> bytes or something that I can use to tranform with an xslt transfomer. If
> possible, can you provide me some sample lines of code? Thanks.
> --
> View this message in context:
> http://www.nabble.com/what-would-be-the-best-place-to-introduce-xslt-tr
> ansformer-for-response-message-tf4862565.html#a13950419
> Sent from the cxf-user mailing list archive at Nabble.com.
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland