'Invalid null character in text to output

I'm trying to Pass some data process in the server side to the client through my WS.

But I'm getting this error:

    SEVERE: caught throwable
    javax.xml.ws.WebServiceException: com.ctc.wstx.exc.WstxIOException: Invalid null   character in text to output
        at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:112)
        at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:278)
        at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:380)
        at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:92)
        at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:525)
        at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:285)
        at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:143)
        at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:155)
        at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:189)
        at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:76)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)
Caused by: com.ctc.wstx.exc.WstxIOException: Invalid null character in text to output
        at com.ctc.wstx.sw.BaseStreamWriter.writeCharacters(BaseStreamWriter.java:520)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:135)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:138)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:138)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:138)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:138)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:138)
        at com.sun.xml.ws.util.DOMUtil.serializeNode(DOMUtil.java:138)
        at com.sun.xml.ws.message.saaj.SAAJMessage.writeTo(SAAJMessage.java:365)
        at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:109)
        ... 24 more
Caused by: java.io.IOException: Invalid null character in text to output
        at com.ctc.wstx.sw.XmlWriter.throwInvalidChar(XmlWriter.java:538)
        at com.ctc.wstx.sw.BufferingXmlWriter.writeCharacters(BufferingXmlWriter.java:453)
        at com.ctc.wstx.sw.BaseStreamWriter.writeCharacters(BaseStreamWriter.java:518)

This exception is thrown while sending the response back to the client.

in the client side this is the response:

ParseError at [row,col]:[1,11347]

But looking At this Its very difficult to find where is the error. Is there anyway that I can resolve this error.



Solution 1:[1]

As exception suggests, some String (character data value) in object you trying to write out contains null character (Unicode zero). Beyond finding and fixing corrupt String value(s), you can also work around the problem by making Woodstox change such invalid character values. See How to alleviate the infamous "Xml Invalid Character" problem with Woodstox .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 StaxMan