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" <[email protected]>
To: <[email protected]>
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 <[email protected]>

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:[email protected]]
Sent: 01 April 2009 18:39
To: [email protected]
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


Reply via email to