cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henk Flipman <hflip...@gmail.com>
Subject Re: How to set Woodstox XMLOutputFactory properties
Date Thu, 25 Feb 2010 16:53:03 GMT
How about an interceptor for inbound traffic? Like:

    class ResponseHandleInterceptor extends AbstractPhaseInterceptor<Message> {
        public ResponseHandleInterceptor() {
            super(Phase.RECEIVE);
        }

        public void handleMessage(Message message) {
            InputStream is = message.getContent(InputStream.class);

            if (is == null) {
                return;
            }

            CachedOutputStream bos = new CachedOutputStream();
            try {
                IOUtils.copy(is, bos);
                is.close();
                bos.flush();

                String response = new String(bos.getBytes());
                bos.close();

                No fix the XML.

                InputStream backup = new ByteArrayInputStream((response).getBytes());
                message.setContent(InputStream.class, backup);
            } catch(Exception e) {
                throw new Exception(e);
            }
        }
    }

And then use that like:

        Client client = ClientProxy.getClient(service);
        client.getInInterceptors().add(new ResponseHandleInterceptor());

I've used that approach before to fix invalid XML from legacy systems.

Hope this helps.

Thanks.

Henk

On Feb 25, 2010, at 8:36 AM, Juan José Vázquez Delgado wrote:

> Hi,
> 
> My team and I are suffering an XML validation problem when our service
> receives a request from a legacy web service client. The trace is:
> 
> org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader.
> INFO   | jvm 1    | 2010/02/23 12:56:26 | 	at
> org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:230)
> ...................................................................................................................................................................
> INFO   | jvm 1    | 2010/02/23 12:56:26 | Caused by:
> com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character
> ((CTRL-CHAR, code 12))
> INFO   | jvm 1    | 2010/02/23 12:56:26 |  at [row,col {unknown-source}]: [1,1]
> INFO   | jvm 1    | 2010/02/23 12:56:26 | 	at
> com.ctc.wstx.sr.StreamScanner.throwInvalidSpace(StreamScanner.java:675)
> 
> Unfortunately we can't modify the legacy code so we are looking for a
> workaround such as one is described in [1]. Our problem now is that we
> don't know how to set properties to the Woodstox XMLOutputFactory. We
> are configuring the CXF Runtime in the Spring way.
> 
> Any ideas?.
> 
> Thanks in advance.
> 
> Regards,
> 
> Juanjo.
> 
> [1] http://www.cowtowncoder.com/blog/archives/2008/12/entry_106.html


Mime
View raw message