You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Chris Marshall <ch...@campsbayterrace.com> on 2009/04/01 19:38:43 UTC

How to add Stylesheet to XML returned from server?

Forgive me if this is the wrong forum or off topic or plain stupid!I want to
add an xml-stylesheet reference to the document created by CXF-2.2 JAX-RS
via JAXB.
The JAXB documentation indicates something like this code to add the
xml-stylesheet to the header:

Marshaller marshaller = myContext.getJAXBContext().createMarshaller();
marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml-stylesheet
type='text/xsl' href='foobar.xsl' ?>");

I don't know if this is correct, or where to do it.
Do I need to write an Interceptor to do this or are there better/easier
ways?
Thanks Chris Marshall

Re: How to add Stylesheet to XML returned from server?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Chris

I just sent you the other email...
May be what you find unnatural about this code is that is's not XML-centric, something similar to using regular 
expressions for transforming XML :-).

cheers, Sergey

----- Original Message ----- 
From: "Chris Marshall" <ch...@campsbayterrace.com>
To: <us...@cxf.apache.org>
Sent: Tuesday, April 07, 2009 12:15 PM
Subject: Re: How to add Stylesheet to XML returned from server?


> Hi SergeyTo clarify my earlier post I can achieve the result I want via an
> interceptor with the following code:
> 
> public void handleMessage(Message message) {
> try {
> OutputStream os = message.getContent(OutputStream.class);
> byte[] b = "<?xml-stylesheet type='text/xsl'
> href='foobar.xsl'?>".getBytes();
> os.write(b);
> message.setContent(OutputStream.class, os);
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
> }
> 
> but this rather seems to be missing the point.
> 
> Regards Chris
> 
> 
> 2009/4/7 Chris Marshall <ch...@campsbayterrace.com>
> 
>> Thanks - using JAXRSOutInterceptor was part of my experimentation ;-)I am
>> still battling to find out how to set marshaller properties
>> programmatically.
>> My ultimate goal is to set the xsl stylesheet depending on runtime data.
>> Thanks for your patience.
>> Regards Chris
>>
>> 2009/4/6 Sergey Beryozkin <sb...@progress.com>
>>
>>> Hi,
>>>
>>> JAXRSOutInterceptor is not really memant to be subclassed but then I
>>> should've added 'final' to it :-)
>>> Can you explain please why do you need to modify XML given that the
>>> example works ? If you don't use Spring then marshaller properties can be
>>> set programmatically too - may be it is what you're really after ?
>>>
>>> cheers, Sergey
>>>
>>>
>>>
>>> ----- Original Message ----- From: "Chris Marshall" <
>>> chris@campsbayterrace.com>
>>> To: <us...@cxf.apache.org>
>>> Sent: Monday, April 06, 2009 5:13 PM
>>> Subject: Re: How to add Stylesheet to XML returned from server?
>>>
>>>
>

Re: How to add Stylesheet to XML returned from server?

Posted by Chris Marshall <ch...@campsbayterrace.com>.
Hi SergeyTo clarify my earlier post I can achieve the result I want via an
interceptor with the following code:

public void handleMessage(Message message) {
try {
OutputStream os = message.getContent(OutputStream.class);
byte[] b = "<?xml-stylesheet type='text/xsl'
href='foobar.xsl'?>".getBytes();
os.write(b);
message.setContent(OutputStream.class, os);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

but this rather seems to be missing the point.

Regards Chris


2009/4/7 Chris Marshall <ch...@campsbayterrace.com>

> Thanks - using JAXRSOutInterceptor was part of my experimentation ;-)I am
> still battling to find out how to set marshaller properties
> programmatically.
> My ultimate goal is to set the xsl stylesheet depending on runtime data.
> Thanks for your patience.
> Regards Chris
>
> 2009/4/6 Sergey Beryozkin <sb...@progress.com>
>
>> Hi,
>>
>> JAXRSOutInterceptor is not really memant to be subclassed but then I
>> should've added 'final' to it :-)
>> Can you explain please why do you need to modify XML given that the
>> example works ? If you don't use Spring then marshaller properties can be
>> set programmatically too - may be it is what you're really after ?
>>
>> cheers, Sergey
>>
>>
>>
>> ----- Original Message ----- From: "Chris Marshall" <
>> chris@campsbayterrace.com>
>> To: <us...@cxf.apache.org>
>> Sent: Monday, April 06, 2009 5:13 PM
>> Subject: Re: How to add Stylesheet to XML returned from server?
>>
>>

Re: How to add Stylesheet to XML returned from server?

Posted by sridhar veerappan <sr...@gmail.com>.
Hi,

I am new To CXF, Can you anyone help me how to build the application with
minimal setup with Jboss or Tomcat,Java,eclipse,Ant/Maven,Web service with a
sample application to test.

Thanks in Advance
Sridhar

On Wed, Apr 8, 2009 at 1:26 PM, Chris Marshall <ch...@campsbayterrace.com>wrote:

> That would be a great help Sergey!
> Thanks Chris
>
>
> On 07/04/2009, Sergey Beryozkin <sb...@progress.com> wrote:
> >
> > Hi Chris
> >
> > it's great :-)
> > that code though may get a bit brittle if other XML-aware providers are
> > registered/found.
> > I do like the idea of updating teh JAXBElementProvider to check the
> > injected context for well-known marshaller properties
> > such that the only thing you do is to
> >
> > message.put(XML_HEADERS, "<?xml-stylesheet type='text/xsl'>
> > href=foobar.xsl'?>");
> >
> > cheers, Sergey
> >
>

Re: How to add Stylesheet to XML returned from server?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi,

Just update JAXBElementProvider to check well-known Marshaller properties which might've been set earlier on in CXF 
interceptors/JAX-RS response filters on a current message - snapshots should have it starting from tomorrow

cheers, Sergey
----- Original Message ----- 
From: "Chris Marshall" <ch...@campsbayterrace.com>
To: <us...@cxf.apache.org>
Sent: Wednesday, April 08, 2009 8:56 AM
Subject: Re: How to add Stylesheet to XML returned from server?


> That would be a great help Sergey!
> Thanks Chris
>
>
> On 07/04/2009, Sergey Beryozkin <sb...@progress.com> wrote:
>>
>> Hi Chris
>>
>> it's great :-)
>> that code though may get a bit brittle if other XML-aware providers are
>> registered/found.
>> I do like the idea of updating teh JAXBElementProvider to check the
>> injected context for well-known marshaller properties
>> such that the only thing you do is to
>>
>> message.put(XML_HEADERS, "<?xml-stylesheet type='text/xsl'>
>> href=foobar.xsl'?>");
>>
>> cheers, Sergey
>>
> 


Re: How to add Stylesheet to XML returned from server?

Posted by Chris Marshall <ch...@campsbayterrace.com>.
That would be a great help Sergey!
Thanks Chris


On 07/04/2009, Sergey Beryozkin <sb...@progress.com> wrote:
>
> Hi Chris
>
> it's great :-)
> that code though may get a bit brittle if other XML-aware providers are
> registered/found.
> I do like the idea of updating teh JAXBElementProvider to check the
> injected context for well-known marshaller properties
> such that the only thing you do is to
>
> message.put(XML_HEADERS, "<?xml-stylesheet type='text/xsl'>
> href=foobar.xsl'?>");
>
> cheers, Sergey
>

Re: How to add Stylesheet to XML returned from server?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Chris

it's great :-)
that code though may get a bit brittle if other XML-aware providers are registered/found.
I do like the idea of updating teh JAXBElementProvider to check the injected context for well-known marshaller properties
such that the only thing you do is to

message.put(XML_HEADERS, "<?xml-stylesheet type='text/xsl'> href=foobar.xsl'?>");

cheers, Sergey


----- Original Message ----- 
From: "Chris Marshall" <ch...@campsbayterrace.com>
To: <us...@cxf.apache.org>
Sent: Tuesday, April 07, 2009 3:55 PM
Subject: Re: How to add Stylesheet to XML returned from server?


> Many thanks Sergey, that helped hugely!
> 
> Attached is my (skeletal) code which may help other beginners like myself.
> Please point out obvious errors.
> 
> import java.util.HashMap;
> import java.util.Map;
> 
> import javax.ws.rs.core.MediaType;
> 
> import org.apache.cxf.jaxrs.model.OperationResourceInfo;
> import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
> import org.apache.cxf.jaxrs.provider.ProviderFactory;
> import org.apache.cxf.message.Message;
> import org.apache.cxf.phase.AbstractPhaseInterceptor;
> import org.apache.cxf.phase.Phase;
> 
> public class StylesheetInterceptor extends AbstractPhaseInterceptor<Message>
> {
> 
>    private static final String XML_HEADERS = "com.sun.xml.bind.xmlHeaders";
> 
>    public StylesheetInterceptor() {
>        super(Phase.SETUP);
>    }
> 
>    public void handleMessage(Message message) {
> 
>            OperationResourceInfo ori =
> message.getExchange().get(OperationResourceInfo.class);
> 
>            JAXBElementProvider provider = (JAXBElementProvider)
> ProviderFactory
>            .getInstance(message)
>            .createMessageBodyWriter(
>                    ori.getMethodToInvoke().getReturnType(),
>                    ori.getMethodToInvoke().getGenericReturnType(),
>                    ori.getMethodToInvoke().getAnnotations(),
>                    MediaType.APPLICATION_XML_TYPE,
>                    message);
> 
>            Map<String, Object>properties = new HashMap<String, Object>();
>            properties.put(XML_HEADERS, "<?xml-stylesheet type='text/xsl'
> href=foobar.xsl'?>");
>            provider.setMarshallerProperties(properties);
>    }
> 
>    public void handleFault(Message message) {
>        System.out.println("Stylesheet Error");
>    }
> }
> 
> On 07/04/2009, Sergey Beryozkin <sb...@progress.com> wrote:
> 
>> Hi,
>>
>> You can set up a JAXRS endpoint like this :
>>
>> JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
>> factory.setResourceClasses(myService.class);
>> JAXBElementProvider provider = new JAXBElementProvider();
>> p.setMarshallerProperties(properties);
>> factory.setProviders(provider);
>> factory.create();
>>
>> Actually, another way to do it would be to do something like this in a
>> custom ResponseHandler filter (or indeed
>> from your custom CXF out interceptor) :
>>
>> ProviderFactory.getInstance(message).createMessageBodyWriter(responseClass,
>> genericType, annotations,
>>   MediaType.APPLICATION_XML_TYPE, message);
>>
>> You can get the first 3 parameters for this invocation by doing
>>
>> message.getExhange().get(OperationResourceInfo.class).getMethodToInvoke()
>> amd picking them up from a Method instance.
>>
>> So then you can cast the returned instance to a JAXBElementProvider and set
>> required properties on it...
>>
>> Actually, may be we can also enhance the JAXBElementProvider to check the
>> injected message context for marshaller properties which might've been setup
>> by cxf interceptors, so the only thing you'd need to do then would be to
>> just set a marshaller property on a message itself..
>>
>> Does it really help ?
>>
>> Cheers, Sergey
>>>
>>>
>>
>>
>

Re: How to add Stylesheet to XML returned from server?

Posted by Chris Marshall <ch...@campsbayterrace.com>.
Many thanks Sergey, that helped hugely!

Attached is my (skeletal) code which may help other beginners like myself.
Please point out obvious errors.

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class StylesheetInterceptor extends AbstractPhaseInterceptor<Message>
{

    private static final String XML_HEADERS = "com.sun.xml.bind.xmlHeaders";

    public StylesheetInterceptor() {
        super(Phase.SETUP);
    }

    public void handleMessage(Message message) {

            OperationResourceInfo ori =
message.getExchange().get(OperationResourceInfo.class);

            JAXBElementProvider provider = (JAXBElementProvider)
ProviderFactory
            .getInstance(message)
            .createMessageBodyWriter(
                    ori.getMethodToInvoke().getReturnType(),
                    ori.getMethodToInvoke().getGenericReturnType(),
                    ori.getMethodToInvoke().getAnnotations(),
                    MediaType.APPLICATION_XML_TYPE,
                    message);

            Map<String, Object>properties = new HashMap<String, Object>();
            properties.put(XML_HEADERS, "<?xml-stylesheet type='text/xsl'
href=foobar.xsl'?>");
            provider.setMarshallerProperties(properties);
    }

    public void handleFault(Message message) {
        System.out.println("Stylesheet Error");
    }
}

On 07/04/2009, Sergey Beryozkin <sb...@progress.com> wrote:

> Hi,
>
> You can set up a JAXRS endpoint like this :
>
> JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
> factory.setResourceClasses(myService.class);
> JAXBElementProvider provider = new JAXBElementProvider();
> p.setMarshallerProperties(properties);
> factory.setProviders(provider);
> factory.create();
>
> Actually, another way to do it would be to do something like this in a
> custom ResponseHandler filter (or indeed
> from your custom CXF out interceptor) :
>
> ProviderFactory.getInstance(message).createMessageBodyWriter(responseClass,
> genericType, annotations,
>   MediaType.APPLICATION_XML_TYPE, message);
>
> You can get the first 3 parameters for this invocation by doing
>
> message.getExhange().get(OperationResourceInfo.class).getMethodToInvoke()
> amd picking them up from a Method instance.
>
> So then you can cast the returned instance to a JAXBElementProvider and set
> required properties on it...
>
> Actually, may be we can also enhance the JAXBElementProvider to check the
> injected message context for marshaller properties which might've been setup
> by cxf interceptors, so the only thing you'd need to do then would be to
> just set a marshaller property on a message itself..
>
> Does it really help ?
>
> Cheers, Sergey
>>
>>
>
>

Re: How to add Stylesheet to XML returned from server?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi,

You can set up a JAXRS endpoint like this :

JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setResourceClasses(myService.class);
JAXBElementProvider provider = new JAXBElementProvider();
p.setMarshallerProperties(properties);
factory.setProviders(provider);
factory.create();

Actually, another way to do it would be to do something like this in a custom ResponseHandler filter (or indeed
from your custom CXF out interceptor) :

ProviderFactory.getInstance(message).createMessageBodyWriter(responseClass, genericType, annotations,
    MediaType.APPLICATION_XML_TYPE, message);

You can get the first 3 parameters for this invocation by doing

message.getExhange().get(OperationResourceInfo.class).getMethodToInvoke() amd picking them up from a Method instance.

So then you can cast the returned instance to a JAXBElementProvider and set required properties on it...

Actually, may be we can also enhance the JAXBElementProvider to check the injected message context for marshaller properties which 
might've been setup by cxf interceptors, so the only thing you'd need to do then would be to just set a marshaller property on a 
message itself..

Does it really help ?

Cheers, Sergey

> Thanks - using JAXRSOutInterceptor was part of my experimentation ;-)I am
> still battling to find out how to set marshaller properties
> programmatically.
> My ultimate goal is to set the xsl stylesheet depending on runtime data.
> Thanks for your patience.
> Regards Chris
>
> 2009/4/6 Sergey Beryozkin <sb...@progress.com>
>
>> Hi,
>>
>> JAXRSOutInterceptor is not really memant to be subclassed but then I
>> should've added 'final' to it :-)
>> Can you explain please why do you need to modify XML given that the example
>> works ? If you don't use Spring then marshaller properties can be set
>> programmatically too - may be it is what you're really after ?
>>
>> cheers, Sergey
>>
>>
>>
>> ----- Original Message ----- From: "Chris Marshall" <
>> chris@campsbayterrace.com>
>> To: <us...@cxf.apache.org>
>> Sent: Monday, April 06, 2009 5:13 PM
>> Subject: Re: How to add Stylesheet to XML returned from server?
>>
>>
> 


Re: How to add Stylesheet to XML returned from server?

Posted by Chris Marshall <ch...@campsbayterrace.com>.
Thanks - using JAXRSOutInterceptor was part of my experimentation ;-)I am
still battling to find out how to set marshaller properties
programmatically.
My ultimate goal is to set the xsl stylesheet depending on runtime data.
Thanks for your patience.
Regards Chris

2009/4/6 Sergey Beryozkin <sb...@progress.com>

> Hi,
>
> JAXRSOutInterceptor is not really memant to be subclassed but then I
> should've added 'final' to it :-)
> Can you explain please why do you need to modify XML given that the example
> works ? If you don't use Spring then marshaller properties can be set
> programmatically too - may be it is what you're really after ?
>
> cheers, Sergey
>
>
>
> ----- Original Message ----- From: "Chris Marshall" <
> chris@campsbayterrace.com>
> To: <us...@cxf.apache.org>
> Sent: Monday, April 06, 2009 5:13 PM
> Subject: Re: How to add Stylesheet to XML returned from server?
>
>

Re: How to add Stylesheet to XML returned from server?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi,

JAXRSOutInterceptor is not really memant to be subclassed but then I should've added 'final' to it :-)
Can you explain please why do you need to modify XML given that the example works ? 
If you don't use Spring then marshaller properties can be set programmatically too - may be it is what you're really after ?

cheers, Sergey



----- Original Message ----- 
From: "Chris Marshall" <ch...@campsbayterrace.com>
To: <us...@cxf.apache.org>
Sent: Monday, April 06, 2009 5:13 PM
Subject: Re: How to add Stylesheet to XML returned from server?


> Thanks Sergey - delayed my reply to try and fully understand what is going
> on here.
> The JAXB provider example works fine via Spring, but I am stuck on how to
> create the
> xml-stylesheet reference using an Interceptor, mainly because I can't work
> out how to manipulate the (XML) message in handleMessage(Message message)
> of my StylesheetInterceptor subclass of JAXRSOutInterceptor.
> 
> I have studied the CXF Interceptors and Phases document and several code
> examples but cannot find any which shows how to add to the header of an
> outgoing XML message.
> 
> The interceptor instance is added programmatically via
> sf.getOutInterceptors().add(stylesheetInterceptor) and is invoked when
> expected.
> 
> Do you have any references which may help?
> 
> Regards Chris
> 
> 
> 2009/4/1 Sergey Beryozkin <sb...@progress.com>
> 
>> Hi
>>
>> It's a very good question, have a look here please :
>>
>> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/resources/ja
>> xrs/WEB-INF/beans.xml
>>
>> This is somewhat unrelated example, but it shows how you can register a
>> JAXB provider, and it shows how to define utils:map, so you can do
>> something like this
>>
>> <util:map id="marshallerProperties">
>> <entry key="com.sun.xml.bind.xmlHeaders" value="<?xml-stylesheet
>> type='text/xsl' href='foobar.xsl' ?>"/>
>> </util:map>
>>
>> <bean id="jaxbProvider"
>> class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
>> <property name="marshallerProperties" ref="marshallerProperties"/>
>> </bean>
>>
>> This should do it.
>> Other options are to create a CXF out interceptor or CXF JAXRS
>> ResponseFilter and add a needed header there...
>>
>> Cheers, Sergey
>>
>> -----Original Message-----
>> From: Chris Marshall [mailto:chris@campsbayterrace.com]
>> Sent: 01 April 2009 18:39
>> To: users@cxf.apache.org
>> Subject: How to add Stylesheet to XML returned from server?
>>
>> Forgive me if this is the wrong forum or off topic or plain stupid!I
>> want to
>> add an xml-stylesheet reference to the document created by CXF-2.2
>> JAX-RS
>> via JAXB.
>> The JAXB documentation indicates something like this code to add the
>> xml-stylesheet to the header:
>>
>> Marshaller marshaller = myContext.getJAXBContext().createMarshaller();
>> marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml-stylesheet
>> type='text/xsl' href='foobar.xsl' ?>");
>>
>> I don't know if this is correct, or where to do it.
>> Do I need to write an Interceptor to do this or are there better/easier
>> ways?
>> Thanks Chris Marshall
>>
>

Re: How to add Stylesheet to XML returned from server?

Posted by Chris Marshall <ch...@campsbayterrace.com>.
Thanks Sergey - delayed my reply to try and fully understand what is going
on here.
The JAXB provider example works fine via Spring, but I am stuck on how to
create the
xml-stylesheet reference using an Interceptor, mainly because I can't work
out how to manipulate the (XML) message in handleMessage(Message message)
of my StylesheetInterceptor subclass of JAXRSOutInterceptor.

I have studied the CXF Interceptors and Phases document and several code
examples but cannot find any which shows how to add to the header of an
outgoing XML message.

The interceptor instance is added programmatically via
sf.getOutInterceptors().add(stylesheetInterceptor) and is invoked when
expected.

Do you have any references which may help?

Regards Chris


2009/4/1 Sergey Beryozkin <sb...@progress.com>

> Hi
>
> It's a very good question, have a look here please :
>
> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/resources/ja
> xrs/WEB-INF/beans.xml
>
> This is somewhat unrelated example, but it shows how you can register a
> JAXB provider, and it shows how to define utils:map, so you can do
> something like this
>
> <util:map id="marshallerProperties">
> <entry key="com.sun.xml.bind.xmlHeaders" value="<?xml-stylesheet
> type='text/xsl' href='foobar.xsl' ?>"/>
> </util:map>
>
> <bean id="jaxbProvider"
> class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
> <property name="marshallerProperties" ref="marshallerProperties"/>
> </bean>
>
> This should do it.
> Other options are to create a CXF out interceptor or CXF JAXRS
> ResponseFilter and add a needed header there...
>
> Cheers, Sergey
>
> -----Original Message-----
> From: Chris Marshall [mailto:chris@campsbayterrace.com]
> Sent: 01 April 2009 18:39
> To: users@cxf.apache.org
> Subject: How to add Stylesheet to XML returned from server?
>
> Forgive me if this is the wrong forum or off topic or plain stupid!I
> want to
> add an xml-stylesheet reference to the document created by CXF-2.2
> JAX-RS
> via JAXB.
> The JAXB documentation indicates something like this code to add the
> xml-stylesheet to the header:
>
> Marshaller marshaller = myContext.getJAXBContext().createMarshaller();
> marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml-stylesheet
> type='text/xsl' href='foobar.xsl' ?>");
>
> I don't know if this is correct, or where to do it.
> Do I need to write an Interceptor to do this or are there better/easier
> ways?
> Thanks Chris Marshall
>

RE: How to add Stylesheet to XML returned from server?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

It's a very good question, have a look here please :

http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/resources/ja
xrs/WEB-INF/beans.xml

This is somewhat unrelated example, but it shows how you can register a
JAXB provider, and it shows how to define utils:map, so you can do
something like this 

<util:map id="marshallerProperties">
<entry key="com.sun.xml.bind.xmlHeaders" value="<?xml-stylesheet
type='text/xsl' href='foobar.xsl' ?>"/>
</util:map>

<bean id="jaxbProvider"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="marshallerProperties" ref="marshallerProperties"/>
</bean>

This should do it.
Other options are to create a CXF out interceptor or CXF JAXRS
ResponseFilter and add a needed header there...

Cheers, Sergey  

-----Original Message-----
From: Chris Marshall [mailto:chris@campsbayterrace.com] 
Sent: 01 April 2009 18:39
To: users@cxf.apache.org
Subject: How to add Stylesheet to XML returned from server?

Forgive me if this is the wrong forum or off topic or plain stupid!I
want to
add an xml-stylesheet reference to the document created by CXF-2.2
JAX-RS
via JAXB.
The JAXB documentation indicates something like this code to add the
xml-stylesheet to the header:

Marshaller marshaller = myContext.getJAXBContext().createMarshaller();
marshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml-stylesheet
type='text/xsl' href='foobar.xsl' ?>");

I don't know if this is correct, or where to do it.
Do I need to write an Interceptor to do this or are there better/easier
ways?
Thanks Chris Marshall