tomcat 封送行程JaxbXmlPart/word/document.xml时发生错误

n7taea2i  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(167)

我在将docx 4j文档保存到OutputStream时遇到了一个问题,我不确定应该如何调试它。
我使用的是8.3.8版本的docx 4j-ImportXHTML和docx 4j版本的java 8。
一般来说,我会将一个html文档解析为docx 4j,并将其保存到OutputStream中,即

WordprocessingMLPackage docx = WordprocessingMLPackage.createPackage();
DocumentPart docPart = docx.getMainDocumentPart();
docPart.getContent().addAll(new XHTMLImporterImpl(docx).convert(htmlString, null));
docx.save(myOutputStream);.

不总是,这个进程崩溃,而其他一些它工作正常。所以我不能总是重现它。
我已经注销了org.docx4j.openpackaging,因为似乎有这个错误,但我不知道如何修复它。日志给予了以下结果:

2022-07-25 13:22:45 [http-thread-pool::http-listener-1(2)] | [514b616a-9211-4aae-a60a-affe61ff3d2f SuperUser user ]                                                   | DEBUG in org.docx4j.openpackaging.io3.stores.ZipPartStore -> marshalling /word/document.xml 
2022-07-25 13:22:45 [http-thread-pool::http-listener-1(2)] | [514b616a-9211-4aae-a60a-affe61ff3d2f SuperUser user ]                                                   | DEBUG in org.docx4j.openpackaging.parts.JaxbXmlPart -> marshalling org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart 
2022-07-25 13:22:45 [http-thread-pool::http-listener-1(2)] | [514b616a-9211-4aae-a60a-affe61ff3d2f SuperUser user ]                                                   | DEBUG in org.docx4j.openpackaging.parts.JaxbXmlPart -> Marshalling to org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream 
2022-07-25 13:22:45 [http-thread-pool::http-listener-1(2)] | [514b616a-9211-4aae-a60a-affe61ff3d2f SuperUser user ]                                                   | DEBUG in org.docx4j.openpackaging.parts.Part -> package name: null 
2022-07-25 13:22:45 [http-thread-pool::http-listener-1(2)] | [514b616a-9211-4aae-a60a-affe61ff3d2f SuperUser user ]                                                   | DEBUG in org.docx4j.openpackaging.parts.Part -> package name: null 
2022-07-25 13:22:45 [http-thread-pool::http-listener-1(2)] | [514b616a-9211-4aae-a60a-affe61ff3d2f SuperUser user ]                                                   | ERROR in org.docx4j.openpackaging.io3.Save -> Error marshalling JaxbXmlPart /word/document.xml 
org.docx4j.openpackaging.exceptions.Docx4JException: Error marshalling JaxbXmlPart /word/document.xml
    at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:394)
    at org.docx4j.openpackaging.io3.Save.saveRawXmlPart(Save.java:289)
    at org.docx4j.openpackaging.io3.Save.savePart(Save.java:436)
    at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:399)
    at org.docx4j.openpackaging.io3.Save.save(Save.java:193)
    at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:799)
    at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:729)
    at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:717)
    at myClass.save2Docx(MyClass.java:69)
    ...
Caused by: javax.xml.bind.JAXBException: null
    at org.docx4j.openpackaging.parts.JaxbXmlPart.marshal(JaxbXmlPart.java:937)
    at org.docx4j.openpackaging.parts.JaxbXmlPart.marshal(JaxbXmlPart.java:748)
    at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveJaxbXmlPart(ZipPartStore.java:337)
    ... 89 common frames omitted
Caused by: javax.xml.bind.MarshalException: null
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:303)
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:226)
    at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:80)
    at org.docx4j.openpackaging.parts.JaxbXmlPart.marshal(JaxbXmlPart.java:865)
    ... 91 common frames omitted
Caused by: java.io.IOException: Connection is closed
    at org.glassfish.grizzly.nio.NIOConnection.assertOpen(NIOConnection.java:445)
    at org.glassfish.grizzly.http.io.OutputBuffer.write(OutputBuffer.java:677)
    at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:336)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:323)
    ...
Caused by: java.io.IOException: An established connection was aborted by the software in your host machine
    at sun.nio.ch.SocketDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
    at sun.nio.ch.IOUtil.write(IOUtil.java:51)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
    ...

在docx.save(myOutputStream)上调试时;它向我展示了一个例外:

org.docx4j.openpackaging.exceptions.Docx4JException: Problem saving part /word/document.xml
Failed to add parts from relationships of /

我不知道该如何解决这个问题。
先谢谢你

htrmnn0y

htrmnn0y1#

不知道为什么它的工作,但我写的情况下,别人有同样的问题。
我的代码中包含以下内容:

StreamingOutput myOutput = out -> generateDocx(htmlString, out);

并将其更改为:

StreamingOutput myOutput = new StreamingOutput() {
                @Override
                public void write(OutputStream outputStream) throws IOException, WebApplicationException {
                    generateDocx(htmlString, outputStream);
                }
            };

这段代码是在osgi框架之上的,由于某种原因lambda表达式关闭了连接...不确定为什么会发生这种情况。

相关问题