I fixed JAXRSOutInterceptor to handle CachedXmlStreamWriters in all the cases
(at the moment it's handled only if JAXBElementProvider has been explicitly
configured to buffer its output)...

cheers, Sergey



Sergey Beryozkin wrote:
> 
> Hi
> 
> this method
> 
> protected void marshalToWriter(Marshaller ms, Object obj,
>             XMLStreamWriter writer, MediaType mt) throws Exception {
> }
> 
> assumes that the writer has already been created so this method is not
> called at the moment. Custom providers can also extend this method and
> wrap the writer with yet another writer as you do, but in your specific
> case you need to register a writer using a response filter, here's an
> example :
> 
> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/XmlStreamWriterProvider.java
> 
> you can register this filter the same way as the custom JAXB provider.
> 
> Given that you've actually extended the JAXBProvider, it seems like an
> extra step to go and also create a filter. So I've updated the JAXB
> provider (locally only) with 
> 
> protected XMLStreamWriter getStreamWriter(Object obj, OutputStream os,
> MediaType mt) {}
> 
> (and a similar method for XMLStreamReader)
> 
> so, starting with 2.2.3 you'll be able to avoid registering a filter just
> for the sake of providing a writer to the JAXB provider :
> 
> public class MyCustomJAXBElementProvider extends JAXBElementProvider {
> 
>     @Override
>     protected XMLStreamWriter getStreamWriter(Object obj, OutputStream os,
> MediaType mt) {
>         XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os);        
>         //return new CachingXmlEventWriterWrapper(writer);
>     }
> }
> 
> Note explicitly registered CachingXmlEventWriters are not supported yet
> (assuming they just cache the XMLEvents), unless you enable a buffering
> mode. I'll fix it too, but in meantime  you might want to use a delegating
> writer instead similar to
> 
> http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomXmlStreamWriter.java
> 
> hope it helps, Sergey
>  
> 
> 
> Juan José Vázquez Delgado wrote:
>> 
>> Hi,
>> 
>> I have a JAX-RS web service which uses JAXB for binding. Everything is
>> ok, but currently I have a Flash client which is not ready to
>> understand neither namespaces nor prefixes at all. I have to clean the
>> output XML of namespaces and prefixes, included xmlns attributes, but
>> I would´nt like having to modify my xml schemas so I´m looking for a
>> solution on binding time.
>> 
>> My approach has been to extend JAXBElementProvider in order to wrap
>> the default XMLStreamWriter, CachingXmlEventWriter in this case. So I
>> have something like this:
>> 
>> public class MyCustomJAXBElementProvider extends JAXBElementProvider {
>> 
>>     @Override
>>     protected void marshalToWriter(Marshaller ms, Object obj,
>>             XMLStreamWriter writer, MediaType mt) throws Exception {
>>         CachingXmlEventWriterWrapper wrappedWriter = new
>> CachingXmlEventWriterWrapper(writer);
>>         super.marshalToWriter(ms, obj, wrappedWriter, mt);
>>     }
>> 
>> }
>> 
>> class CachingXmlEventWriterWrapper implements XMLStreamWriter {
>> 
>>      private XMLStreamWriter wrappedStreamWriter;
>> 
>>      public CachingXmlEventWriterWrapper(XMLStreamWriter
>> wrappedStreamWriter) {
>>             this.wrappedStreamWriter = wrappedStreamWriter;
>> 
>>      }
>> 
>>     ............
>> 
>> }
>> 
>> The wrapper implementation tries to generate a "clean" XML
>> overwritting "setPrefix", "writeEmptyElement" and others methods  but
>> I didn´t get to remove the "xmlns" attributes. Any ideas?.
>> 
>> Thanks in advance.
>> 
>> Regards,
>> 
>> Juanjo.
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Removing-XML-namespaces-and-prefixes-tp24457677p24458944.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to