[
https://issues.apache.org/jira/browse/OPENJPA-2791?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16873018#comment-16873018
]
Francesco Chicchiriccò commented on OPENJPA-2791:
-------------------------------------------------
{quote}
Problem solved. I replaced
https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd with
https://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd
and the program now builds normally. Many thanks for your help.
{quote}
Glad that it solves your immediate need, but I see it more as a workaround.
Since the problem seems to be fetching the actual xsd content (due to multiple
redirects) rather than actual SAX validation, I have re-elaborated the snippet
above as follows:
{code}
// first get actual xsd via httpclient, which correctly follows
redirects
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new
HttpGet("http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd");
CloseableHttpResponse response = httpclient.execute(httpget);
// then obtain a Schema instance for the fetched xsd content
SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(new
StreamSource(response.getEntity().getContent()));
// finally do SAX parsing, with validation against the Schema instance
obtained above
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setSchema(schema);
SAXParser parser = saxParserFactory.newSAXParser();
parser.parse(App.class.getResourceAsStream("/persistence.xml"), new
DefaultHandler() {
@Override
public void error(final SAXParseException e) throws SAXException {
throw e;
}
});
{code}
This works either in case of valid and invalid {{persistence.xml}}.
Hence, the actual fix for the current issue could be changing
{{XMLMetaDataParser}} to work as above, but I have some doubts, especially
about:
# adding dependency on commons-hc
# making an explicit http connection, where we might be checking if there is an
HTTP proxy configured
[~struberg], [~romain.manni-bucau] what do you think?
> Parsing persistence.xml throws premature end of file error
> ----------------------------------------------------------
>
> Key: OPENJPA-2791
> URL: https://issues.apache.org/jira/browse/OPENJPA-2791
> Project: OpenJPA
> Issue Type: Bug
> Components: build / infrastructure, jpa
> Affects Versions: 2.4.3
> Environment: Linux Ubuntu 18.04
> Reporter: Robert F. Peake
> Priority: Major
> Labels: build
>
> XMLMetaDataParser in org.apache.openjpa.lib.meta uses the SaxParser to read
> persistence.xml. Just within the last few days, it has begun to throw this
> error:
> {quote}org.xml.sax.SAXException:
> [file:/home/robert/git/sccdata/target/classes/META-INF/persistence.xml|file:///home/robert/git/sccdata/target/classes/META-INF/persistence.xml]
> [Location: Line: 5, C: 64]: org.xml.sax.SAXParseException; systemId:
> [http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd]; lineNumber: 1;
> columnNumber: 1; Premature end of file.
> {quote}
> Resorting to XML Copy Editor to validate the schema shows the error actually
> involved: Fatal Error at line 0, column 0: unsupported protocol in URL. It
> seems that Oracle's web site has switched from HTTP to HTTPS, which is a
> protocol that parser cannot handle, as explained in this post:
> {color:#000000}[article|[https://knowledgebase.progress.com/articles/Article/Unsupported-protocol-in-URL-reading-XML-from-a-URI].]{color}
> {color:#000000} {color}
> {color:#000000}The problem has been reported elsewhere [Stack
> Overflow|https://stackoverflow.com/questions/56728487/org-xml-sax-saxparseexceptionpublicid-http-xmlns-jcp-org-xml-ns-persistence-p/56741356#56741356].{color}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)