使用docx4j时,OutputPropertiesFactory.java处的空指针异常

时间:2012-11-20 16:23:49

标签: java docx4j

我使用docx4j来提取上传的docx文件,但获得以下异常

java.lang.NullPointerException
        at org.apache.xml.serializer.OutputPropertiesFactory.getDefaultMethodProperties(OutputPropertiesFactory.java:260)
        at org.apache.xalan.templates.OutputProperties.(OutputProperties.java:83)
        at org.apache.xalan.transformer.TransformerIdentityImpl.(TransformerIdentityImpl.java:88)
        at org.apache.xalan.processor.TransformerFactoryImpl.newTransformerHandler(TransformerFactoryImpl.java:755)
        at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.createTransformerHandler(JAXBContextImpl.java:705)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.DomLoader$State.(DomLoader.java:52)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.DomLoader.startElement(DomLoader.java:102)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:44)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:470)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:448)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:60)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:228)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:265)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:234)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:111)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:94)
        at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:87)
        at com.sun.xml.internal.bind.v2.runtime.BinderImpl.associativeUnmarshal(BinderImpl.java:145)
        at com.sun.xml.internal.bind.v2.runtime.BinderImpl.unmarshal(BinderImpl.java:116)
        at org.docx4j.openpackaging.parts.JaxbXmlPartXPathAware.unmarshal(JaxbXmlPartXPathAware.java:171)
        at org.docx4j.openpackaging.io.LoadFromZipNG.getRawPart(LoadFromZipNG.java:560)
        at org.docx4j.openpackaging.io.LoadFromZipNG.getPart(LoadFromZipNG.java:429)
        at org.docx4j.openpackaging.io.LoadFromZipNG.addPartsFromRelationships(LoadFromZipNG.java:352)
        at org.docx4j.openpackaging.io.LoadFromZipNG.process(LoadFromZipNG.java:245)
        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:213)
        at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:184)
        at com.myapp.plugin.multipartfileparser.MsWordMultipartFileParser.getDocxHtml(MsWordMultipartFileParser.java:111)
        at com.myapp.plugin.multipartfileparser.MsWordMultipartFileParser.write(MsWordMultipartFileParser.java:68)
        at com.myapp.plugin.service.FileUploaderService.save(FileUploaderService.java:89)
        at com.myapp.plugin.controller.UploadFileController.upload(UploadFileController.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
        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.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        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.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:679)



实际上,我可以在第一时间上传该文件,但是第二次发生了这种异常。只是想知道是否有人曾见过它?

谢谢,

1 个答案:

答案 0 :(得分:0)

我在向glassfish 3部署Web服务时遇到了同样的问题。第一个请求有效,但后续请求失败。

当我查看我的war文件的内容时,我发现我有2个版本的 xalan :2.7.1和2.7.0。我使用7zip从战争中删除旧版本(2.7.0)然后重新部署。问题解决了。然后我相应地重新配置了我的项目依赖项。

因此,我建议您可能有类似的jar冲突,可以像我上面所做的那样解决。