xml - org.xml.sax.SAXParseExceptionpublicId:http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd
问题描述
执行时突然抛出错误:
org.xml.sax.SAXParseExceptionpublicId:
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd; lineNumber:
1; columnNumber: 1; Deployment descriptor file META-INF/persistence.xml
in archive [classes]. Premature end of file.
curl -v http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd
* Trying 2600:1402:f000:392::f6b...
* TCP_NODELAY set
* Connected to xmlns.jcp.org (2600:1402:f000:392::f6b) port 80 (#0)
> GET /xml/ns/persistence/persistence_2_1.xsd HTTP/1.1
> Host: xmlns.jcp.org
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Server: AkamaiGHost
< Content-Length: 0
< Location: https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd
< Cache-Control: max-age=0
< Expires: Sun, 23 Jun 2019 23:21:20 GMT
< Date: Sun, 23 Jun 2019 23:21:20 GMT
< Connection: keep-alive
<
* Connection #0 to host xmlns.jcp.org left intact
直到今天这还不是问题,而且似乎该文件不再可用,但它是 JPA 持久性 xml 文件的标准参考:
HTTP/1.1 301 Moved Permanently
有没有人突然出现这个问题。我无法将其追溯到任何更改,并且我在本地和服务器上都遇到了这种情况。
解决方案
问题的根源似乎在于 Oracle 和对安全性的担忧,促使最近切换到 HTTPS 协议。
org.apache.openjpa.lib.meta 中的 XMLMetaDataParser 在 parseNewResource 方法中使用 SaxParser 读取 xml 文件,这会引发文件过早结束错误。错误文本不是特别有用。但是,借助 XML 复制编辑器[ http://xml-copy-editor.sourceforge.net]来验证架构揭示了实际涉及的
错误:第 0 行第 0 列的致命错误:URL 中不支持的协议。这些信息最终使我找到了这篇涉及 OpenEdge 的帖子,日期为 2018 年 11 月 6 日:[ https://knowledgebase.progress.com/articles/Article/Unsupported-protocol-in-URL-reading-XML-from-a- URI]。
在原因下,它指出,“以前用于 HTTP 的 URL 现在正在重定向到 HTTPS。”
在解决方案下,“这是 OpenEdge 客户端在内部使用的 Apache Xerces 解析器的一个限制。它只支持有限的 URL,因此解析器无法处理 URL 重定向或类似于 Web 浏览器的 HTTPS URL。”
因此,错误消息中标识为“systemId”的 xml 文本的重要部分是 http 协议语句,该语句现在被重定向到 Oracle 网站上的 https,从而导致解析错误。这就解释了为什么一天运行良好的代码在第二天早上突然停止工作。应该很快就知道有多少 ORM 实现有这个限制。
问题解决了。我
用
https://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd
和程序替换了https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd现在可以正常构建。
推荐阅读
- ios - 冗余约束'Self':'AnyObject'
- azure - 防止 Azure SQL 数据仓库中重复数据的策略
- kubernetes - 如何用 Helm 管理 200 多个微服务?
- javascript - Multer 未按要求创建文件
- .htaccess - htaccess 中的重定向问题
- javascript - Angular 发出多个 http 请求,但要等待每个请求完成,然后再发出一个新请求
- ubuntu - Python Flask Api - 图片上传和显示网址
- hyperledger-fabric - 无法使用 Fabric Java SDK 基于事务 id 获取 BlockInfo
- javascript - 如何阅读以下箭头功能
- c - 使用gcc直接编译成机器码,无需链接