简体   繁体   English

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

I am using a cxf webservice which uses local transport and accessing the webservice from java application. 我正在使用使用本地传输的cxf Web服务,并从Java应用程序访问Web服务。 Webservice is reading a file and sending through webservice call. Web服务正在读取文件并通过Web服务调用进行发送。 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。假设文件大小为1200。检索文件的前两次尝试均成功,对于最后一个块,我得到org.apache.cxf.interceptor.Fault:编组错误:非法字符(NULL ,遇到unicode 0):在任何内容中均无效。

Here chunk represents 512 bytes. 此处块代表512字节。 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. 我正在将字节转换为字符串并从Web服务返回。在最后一块中,仅填充16个字节的值,其余填充为零。 Any help will be appreciated. 任何帮助将不胜感激。 I am using cxf webservice 2.7.5, jdk1.7 ,Redhat Linux. 我正在使用cxf webservice 2.7.5,jdk1.7和Redhat Linux。

Stack trace: 堆栈跟踪:

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

From here 这里

The problem that causes these XmlExceptions is that the data being read or loaded contains characters that are illegal according to the XML specifications. 导致这些XmlExceptions的问题在于,根据XML规范,正在读取或加载的数据包含非法字符。 Almost always, these characters are in the ASCII control character range (think whacky characters like null, bell, backspace, etc). 这些字符几乎总是在ASCII控制字符范围内(请考虑一些怪异的字符,例如null,bell,backspace等)。 These aren't characters that have any business being in XML data; 这些字符与XML数据无关。 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. 它们是非法字符,应将其删除,通常是从文件格式转换中找到了它们的方式,例如有人试图从Excel数据创建XML文件,或将其数据从可能存储为二进制文件。

And an example for sanitizing the data before unmarshal. 还有一个在解组前清理数据的示例。 Error about invalid XML characters on Java 关于Java上无效XML字符的错误

Maybe you should use something out of the box for transferring files, like MTOM check here 也许您应该使用开箱即用的方式来传输文件,例如此处的 MTOM

Or you could use CDATA syntax to wrap the content, so the part that evaluates to null will be received as literal. 或者,您可以使用CDATA语法包装内容,因此将评估为null的部分作为文字。

Go to project properties and change the project encoding to UTF-8. 转到项目属性,然后将项目编码更改为UTF-8。 Also use the following for marshaller and unmarchaller 还对marshaller和unmarchaller使用以下内容

    private static void exportToXML(JAXBContext ctx , Object obj , OutputStream stream) throws Exception{
    try {
        Marshaller m = ctx.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

        m.marshal(obj, stream);
    } catch (JAXBException e) {
        e.printStackTrace();
    }       
}

private static Object importXML(JAXBContext ctx , String xmlStr) throws Exception {
    try {           
        Unmarshaller m = ctx.createUnmarshaller();
        ByteArrayInputStream is = new ByteArrayInputStream(xmlStr.getBytes("UTF-8"));

        return m.unmarshal(is);

    } catch (Throwable e) {e.printStackTrace();}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.cxf.interceptor.Fault:编组错误:null - org.apache.cxf.interceptor.Fault: Marshalling Error: null CXF 2.7.7 org.apache.cxf.interceptor.Fault:意外元素 - CXF 2.7.7 org.apache.cxf.interceptor.Fault: Unexpected element 获取异常org.apache.cxf.interceptor.Fault:org / apache / camel / CamelContext - Getting exception org.apache.cxf.interceptor.Fault: org/apache/camel/CamelContext CXF:org.apache.cxf.interceptor.Fault:调用时arguments的编号错误 - CXF : org.apache.cxf.interceptor.Fault: wrong number of arguments while invoking org.apache.cxf.interceptor.Fault:[警告] org.eclipse.jetty.io.EofException:超时 - org.apache.cxf.interceptor.Fault: [warning] org.eclipse.jetty.io.EofException: timeout org.apache.cxf.interceptor.Fault:com / itextpdf / text / Document NoClassDefFoundError - org.apache.cxf.interceptor.Fault: com/itextpdf/text/Document NoClassDefFoundError org.apache.cxf.interceptor.Fault:找不到MIME边界 - org.apache.cxf.interceptor.Fault: Couldn't find MIME boundary org.apache.cxf.interceptor.Fault:无法初始化类net.sf.cglib.proxy.Enhancer - org.apache.cxf.interceptor.Fault: Could not initialize class net.sf.cglib.proxy.Enhancer org.apache.cxf.interceptor.Fault:无法发送消息。 引起:java.io.IOException: IOException invoking Service: Authentication failure - org.apache.cxf.interceptor.Fault: Could not send Message. Caused by: java.io.IOException: IOException invoking Service: Authentication failure 未调用Apache CXF故障拦截器 - Apache CXF Fault Interceptor not invoked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM