On Tuesday 09 September 2008 8:13:31 am Selena85 wrote:
> I spent a lot of time looking for solution to this problem. Unfortunately I
> can't filter client outgoing messages. Is there any possibility to filter
> incoming messages on server side.

It would need to be done pre-xml-parsing, thus, at the stream level.   

You could add an interceptor BEFORE the StaxInInterceptor that replaces the 
InputStream with a filtered input stream that would replace all the \0 and 
other wacky characters.  It could wrapper the original InputStream and just 
filter on the "read" calls.

Dan

>
> dkulp wrote:
> > On Friday 29 August 2008 11:51:53 am Martijn Brinkers wrote:
> >> The problem is that Strings can contain those illegal characters as
> >> discussed on Benson's blog. So to make sure that the produced XML is
> >> valid all Strings need to be filtered. Is it possible to do this
> >> filtering by CXF automagically before sending out the final XML?
> >
> > Couple thoughts:
> > 1) JAXB allows you to easily send messages that are not schema compliant.
> > By
> > default, JAXB doesn't validate it's datasets.   For example, you could
> > have a
> > minOccurs="2" maxOccurs="10" element, but only put a single value in the
> > List
> > and JAXB will happily send it.   If you want strict compliance, you need
> > to
> > turn schema validation on (which results in a performance penalty) or
> > make sure the dataset you produce it valid per schema.
> >
> > 2) In this particular case, you COULD write an XMLStreamWriter that
> > wrappers
> > the original writer and overrides the writeCharacters method to do any
> > filtering you need.   I wouldn't make this a default as performance would
> > suffer for the "normal" usecases where this isn't needed.   This is just
> > like
> > schema validation.   It's useful, but is a performance hit so should be
> > turned on by the developer if the developer feels it's needed and/or
> > required.
> >
> > Dan
> >
> >> Martijn
> >>
> >> On Fri, 2008-08-29 at 11:44 -0400, Daniel Kulp wrote:
> >> > Control characters like that are illegal in XML.  You can read
> >> > Benson's blog about it:
> >> > http://dssheep.blogspot.com/2008/01/xml-10-versus-web-services.html
> >> >
> >> > Technically, I would consider this a bug in the JAXB marshaller as
> >> > this should have thrown an exception at write time, not read time.   
> >> > If you turn on schema validation on the send side, it might throw an
> >>
> >> exception,
> >>
> >> > not really sure.
> >> >
> >> > Dan
> >> >
> >> > On Thursday 28 August 2008 6:01:00 pm Martijn Brinkers wrote:
> >> > > Hi,
> >> > >
> >> > > I use CXF as a soap server and CXF as a soap client. In one of my
> >>
> >> soap
> >>
> >> > > calls I return a String but sometimes this results in a
> >> > > WstxUnexpectedCharException.
> >> > >
> >> > > "WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code
> >>
> >> 27))"
> >>
> >> > > I read that a WstxUnexpectedCharException can be caused by a HTML
> >> > > server returning HTML content but that's not the case here. The
> >>
> >> string
> >>
> >> > > that's returned is returned by my CXF soap server. Shouldn't it be
> >> > > escaped or something?
> >> > >
> >> > > Thanks,
> >> > >
> >> > > Martijn Brinkers
> >> > >
> >> > > PS. I use CXF 2.1
> >> > >
> >> > >
> >> > >
> >> > > Partial stacktrace
> >> > >
> >> > > Caused by: org.apache.cxf.interceptor.Fault: Unmarshalling Error:
> >> > > Illegal character ((CTRL-CHAR, code 27))
> >> > > at [row,col {unknown-source}]: [7,1]
> >> > > at
> >>
> >> org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.ja
> >>
> >> > >va:6 42) at
> >>
> >> org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.ja
> >>
> >> > >va:5 55) at
> >> > > org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:64)
> >> > > at
> >>
> >> org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLit
> >>
> >> > >eral InInterceptor.java:102) at
> >>
> >> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptor
> >>
> >> > >Chai n.java:221) at
> >> > > org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:429) at
> >> > > org.apache.cxf.transport.http.HTTPConduit
> >> > > $WrappedOutputStream.handleResponse(HTTPConduit.java:1988)
> >> > > at org.apache.cxf.transport.http.HTTPConduit
> >> > > $WrappedOutputStream.close(HTTPConduit.java:1824)
> >> > > at
> >>
> >> org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
> >>
> >> > > at
> >> > > org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:583
> >> > >) at org.apache.cxf.interceptor.MessageSenderInterceptor
> >>
> >> $MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.
> >>
> >> > >java
> >> > >
> >> > >:62) at
> >>
> >> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptor
> >>
> >> > >Chai n.java:221) at
> >> > > org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
> >> > > at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
> >> > > at
> >>
> >> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
> >>
> >> > > at
> >>
> >> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:177)
> >>
> >> > > ... 111 more
> >> > > Caused by: javax.xml.bind.UnmarshalException
> >> > > - with linked exception:
> >> > > [com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character
> >> > > ((CTRL-CHAR, code 27))
> >> > > at [row,col {unknown-source}]: [7,1]]
> >> > > at
> >>
> >> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamE
> >>
> >> > >xcep tion(UnmarshallerImpl.java:422) at
> >>
> >> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Un
> >>
> >> > >mars hallerImpl.java:360) at
> >>
> >> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unm
> >>
> >> > >arsh allerImpl.java:337) at
> >>
> >> org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.ja
> >>
> >> > >va:6 28) ... 126 more
> >> > > Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal
> >> > > character ((CTRL-CHAR, code 27))
> >> > > at [row,col {unknown-source}]: [7,1]
> >> > > at
> >>
> >> com.ctc.wstx.sr.StreamScanner.throwInvalidSpace(StreamScanner.java:650)
> >>
> >> > > at
> >>
> >> com.ctc.wstx.sr.BasicStreamReader.readTextSecondary(BasicStreamReader.j
> >>
> >> > >ava: 4666) at
> >>
> >> com.ctc.wstx.sr.BasicStreamReader.readCoalescedText(BasicStreamReader.j
> >>
> >> > >ava: 4124) at
> >>
> >> com.ctc.wstx.sr.BasicStreamReader.finishToken(BasicStreamReader.java:36
> >>
> >> > >99) at
> >>
> >> com.ctc.wstx.sr.BasicStreamReader.safeFinishToken(BasicStreamReader.jav
> >>
> >> > >a:36 47) at
> >>
> >> com.ctc.wstx.sr.BasicStreamReader.getTextCharacters(BasicStreamReader.j
> >>
> >> > >ava: 830) at
> >>
> >> org.apache.cxf.staxutils.DepthXMLStreamReader.getTextCharacters(DepthXM
> >>
> >> > >LStr eamReader.java:159) at
> >>
> >> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleChar
> >>
> >> > >acte rs(StAXStreamConnector.java:356) at
> >>
> >> com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StA
> >>
> >> > >XStr eamConnector.java:220) at
> >>
> >> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Un
> >>
> >> > >mars hallerImpl.java:358) ... 128 more
> >
> > --
> > Daniel Kulp
> > [EMAIL PROTECTED]
> > http://www.dankulp.com/blog



-- 
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog

Reply via email to