org.apache.cxf.interceptor.Fault:编组错误:遇到非法字符(NULL,Unicode 0):在任何内容中均无效 [英] org.apache.cxf.interceptor.Fault: Unmarshalling Error: Illegal character (NULL, unicode 0) encountered: not valid in any content

查看:923
本文介绍了org.apache.cxf.interceptor.Fault:编组错误:遇到非法字符(NULL,Unicode 0):在任何内容中均无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cxf Web服务,该服务使用本地传输并从Java应用程序访问该Web服务. Web服务正在读取文件并通过Web服务调用进行发送.我使用的字节大小为512.假定文件大小为1200.检索文件的前两次尝试均成功,对于最后一个块,我得到org.apache.cxf.interceptor.Fault:编组错误:非法字符(NULL ,遇到unicode 0):在任何内容中均无效.

I am using a cxf webservice which uses local transport and accessing the webservice from java application. Webservice is reading a file and sending through webservice call. I am using the byte size as 512. Suppose the file size is 1200. First two attempt of retrieving the file is success and for the last chunk i am getting org.apache.cxf.interceptor.Fault: Unmarshalling Error: Illegal character (NULL, unicode 0) encountered: not valid in any content.

此处块代表512字节.我正在将字节转换为字符串并从Web服务返回.在最后一个块中,仅填充16个字节的值,其余填充为零. 任何帮助将不胜感激. 我正在使用cxf webservice 2.7.5,jdk1.7和Redhat Linux.

Here chunk represents 512 bytes. I am converting bytes to string and returning from web service.In the last chunk only 16 byte value is filled and remaining are filled with zeros. Any help will be appreciated. I am using cxf webservice 2.7.5, jdk1.7 ,Redhat Linux.

堆栈跟踪:

org.apache.cxf.interceptor.Fault: Unmarshalling Error: Illegal character (NULL, unicode 0) encountered: not valid in any content
 at [row,col {unknown-source}]: [2,1]
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:808)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:629)
        at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157)
        at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:103)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:800)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1592)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1490)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309)
        at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622)
        at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:133)
        at $Proxy62.getJobLog(Unknown Source)
        at com.java.process.AClass.getMessage(AClass.java:468)
        at com.java.process.AClass.getXXXX(AClass.java:156)
        at com.java.process.AClass.main(CLIClientStartup.java:409)
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character (NULL, unicode 0) encountered: not valid in any content
 at [row,col {unknown-source}]: [2,1]]
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:436)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:372)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:349)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:769)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:94)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:797)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:795)
        ... 23 more
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character (NULL, unicode 0) encountered: not valid in any content
 at [row,col {unknown-source}]: [2,1]
        at com.ctc.wstx.sr.StreamScanner.constructNullCharException(StreamScanner.java:630)
        at com.ctc.wstx.sr.StreamScanner.throwInvalidSpace(StreamScanner.java:660)
        at com.ctc.wstx.sr.BasicStreamReader.readTextPrimary(BasicStreamReader.java:4576)
        at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2879)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1072)
        at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:196)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:370)
        ... 29 more

推荐答案

来自

导致这些XmlExceptions的问题是正在处理的数据 根据 XML规范.这些字符几乎总是以ASCII表示 控制字符范围(请考虑一些怪异的字符,例如null,bell, 退格键等).这些不是与生意有关的人物 在XML数据中;它们是应该删除的非法字符, 通常已经从文件格式中找到了进入数据的方式 转换,例如有人尝试从Excel创建XML文件时 数据,或将其数据从可能以以下格式存储的格式导出为XML: 二进制.

The problem that causes these XmlExceptions is that the data being read or loaded contains characters that are illegal according to the XML specifications. Almost always, these characters are in the ASCII control character range (think whacky characters like null, bell, backspace, etc). These aren’t characters that have any business being in XML data; they’re illegal characters that should be removed, usually having found their way into the data from file format conversions, like when someone tries to create an XML file from Excel data, or export their data to XML from a format that may be stored as binary.

还有一个在解组前清理数据的示例. 关于Java上无效XML字符的错误

And an example for sanitizing the data before unmarshal. Error about invalid XML characters on Java

也许您应该使用开箱即用的东西来传输文件,例如MTOM 在此处检查

Maybe you should use something out of the box for transferring files, like MTOM check here

或者您可以使用 CDATA语法来包装内容,因此该部分评估为空 将作为文字接收.

Or you could use CDATA syntax to wrap the content, so the part that evaluates to null will be received as literal.

这篇关于org.apache.cxf.interceptor.Fault:编组错误:遇到非法字符(NULL,Unicode 0):在任何内容中均无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆