Docx4J Bad [Content_Types].xml with WebLogic 12c

怎甘沉沦 提交于 2019-12-24 05:32:35

问题


I'm wondering if anyone has had the same problem with the setup:

  1. WebLogic 12c
  2. Docx4J 2.8.1
  3. Java EE 6

I tried to get the content of a certain Microsoft Word 2007 Document with Docx4J but got an error like the following:

When I try to do:

WordprocessingMLPackage package = WordprocessingMLPackage.load(new File((path));

it will throw exception like:

2013-06-05 15:29:12.0283 ERROR Thread-18 org.docx4j.jaxb.NamespacePrefixMapperUtils – name: com.sun.xml.internal.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapperSunInternal@2b0bf3 .. trying RI.
javax.xml.bind.PropertyException: name: com.sun.xml.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapper@2a3c7c
at org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:590)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.tryUsingRI(NamespacePrefixMapperUtils.java:73)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:64)
at org.docx4j.jaxb.Context.<clinit>(Context.java:56)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
2013-06-05 15:29:12.0455 ERROR Thread-18 org.docx4j.jaxb.NamespacePrefixMapperUtils – JAXB: neither Reference Implementation nor Java 6 implementation present?
javax.xml.bind.PropertyException: name: com.sun.xml.bind.namespacePrefixMapper value: org.docx4j.jaxb.NamespacePrefixMapper@2a3c7c
at org.eclipse.persistence.jaxb.JAXBMarshaller.setProperty(JAXBMarshaller.java:590)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.tryUsingRI(NamespacePrefixMapperUtils.java:73)
at org.docx4j.jaxb.NamespacePrefixMapperUtils.getPrefixMapper(NamespacePrefixMapperUtils.java:64)
at org.docx4j.jaxb.Context.<clinit>(Context.java:56)
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)

As mentioned above, I am using JDK 6, so that should've been an impossible message. But the above message is suppressed internally by Docx4J, and instead throws the following exception:

2013-06-05 15:46:38.0392 ERROR Thread-18 com.jonathan.business.catalog.impl.ProductCatalogServiceImpl – Bad [Content_Types].xml
org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:699)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
... 12 more
2013-06-05 15:46:38.0392 ERROR Thread-18 com.jonathan.business.catalog.impl.ProductCatalogServiceImpl – Bad [Content_Types].xml
org.docx4j.openpackaging.exceptions.InvalidFormatException: Bad [Content_Types].xml
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:699)
at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:206)
at org.docx4j.openpackaging.io.LoadFromZipNG.get(LoadFromZipNG.java:193)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:301)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:245)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:195)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:178)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.contenttype.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:666)
... 12 more

I tried this as suggested in Docx4J forum, but no use.

This question also yield no answer.

Java 6 should have it's own implementation of JAXB internally, but so far I've tried:

  1. not putting any jaxb jar inside the library
  2. putting jaxb jar of versions: 2.1.7, 2.2.4, also 2.2.6, neither works.

Also if it's of any help, the same method works if I run it from void main, it just doesn't work if it's executed from WebLogic server, so I'm convinced that there's class loading problem.


回答1:


To get docx4j working with Weblogic 12c, reportedly you can either upgrade eclipselink, or switch to the JAXB reference implementation.

To upgrade Eclipselink, see http://www.docx4java.org/forums/weblogic-f25/how-to-update-to-eclipselink-2-5-in-web-t1574.html

http://www.docx4java.org/forums/weblogic-f25/classcastexception-in-weblogic-12c-t1643.html#p5675 suggests switching to the JAXB RI is a better approach, for now anyway.

Note that to use the Eclipselink JAXB implementation with docx4j, you should use docx4j 3 beta or later.



来源:https://stackoverflow.com/questions/16934344/docx4j-bad-content-types-xml-with-weblogic-12c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!