I am trying to run the ERMSample.java against a local DNG server (v6.0.6.1). In order to simplify the example, I´ve deleted all the lines between 148 - 311, to avoid artifact creation and I´m just making a query to show all the requirements (lines 314 - 324 // SCENARIO 01 Do a query for type= Requirement) but it fails with the following error:
BlockquoteGRAVE: Error closing message content input stream.
javax.ws.rs.ProcessingException: Error closing message content input stream.
at org.glassfish.jersey.message.internal.EntityInputStream.close(EntityInputStream.java:138)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.close(XMLEntityManager.java:3145)
at java.xml/com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.close(UTF8Reader.java:675)
at java.xml/com.sun.xml.internal.stream.Entity$ScannedEntity.close(Entity.java:423)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.endEntity(XMLEntityManager.java:1485)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1720)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipSpaces(XMLEntityScanner.java:1459)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDriver.next(XMLDocumentScannerImpl.java:1374)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637)
at org.apache.jena.rdfxml.xmlinput.impl.RDFXMLParser.parse(RDFXMLParser.java:96)
at org.apache.jena.rdfxml.xmlinput.ARP.load(ARP.java:118)
at org.apache.jena.riot.lang.ReaderRIOTRDFXML.parse(ReaderRIOTRDFXML.java:186)
at org.apache.jena.riot.lang.ReaderRIOTRDFXML.read(ReaderRIOTRDFXML.java:84)
at org.apache.jena.riot.RDFParser.read(RDFParser.java:416)
at org.apache.jena.riot.RDFParser.parseNotUri(RDFParser.java:406)
at org.apache.jena.riot.RDFParser.parse(RDFParser.java:356)
at org.apache.jena.riot.RDFParserBuilder.parse(RDFParserBuilder.java:568)
at org.apache.jena.riot.RDFDataMgr.parseFromInputStream(RDFDataMgr.java:718)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:253)
at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:235)
at org.apache.jena.riot.adapters.RDFReaderRIOT.read(RDFReaderRIOT.java:69)
at org.apache.jena.rdf.model.impl.ModelCom.read(ModelCom.java:223)
at org.eclipse.lyo.client.query.OslcQueryResult.initializeRdf(OslcQueryResult.java:121)
at org.eclipse.lyo.client.query.OslcQueryResult.getMembersUrls(OslcQueryResult.java:232)
at test.sample.app.ERMSample.main(ERMSample.java:145)
Caused by: org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:268)
at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:227)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:186)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:215)
at org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:316)
at org.apache.http.impl.execchain.ResponseEntityProxy.streamClosed(ResponseEntityProxy.java:128)
at org.apache.http.conn.EofSensorInputStream.checkClose(EofSensorInputStream.java:228)
at org.apache.http.conn.EofSensorInputStream.close(EofSensorInputStream.java:174)
at java.base/java.util.zip.InflaterInputStream.close(InflaterInputStream.java:231)
at java.base/java.util.zip.GZIPInputStream.close(GZIPInputStream.java:136)
at org.apache.http.client.entity.LazyDecompressingInputStream.close(LazyDecompressingInputStream.java:97)
at java.base/java.io.BufferedInputStream.close(BufferedInputStream.java:481)
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:179)
at org.glassfish.jersey.apache.connector.ApacheConnector$2.close(ApacheConnector.java:635)
at java.base/java.io.FilterInputStream.close(FilterInputStream.java:179)
at org.glassfish.jersey.apache.connector.ApacheConnector$HttpClientResponseInputStream.close(ApacheConnector.java:612)
at org.glassfish.jersey.message.internal.EntityInputStream.close(EntityInputStream.java:135)
… 31 more
Instead, the other examples (both ETM and EWM) work for me. What happens with the RM example?
“Error closing message content input stream” issue has been bugging us for some time before. I essentially remember leaving closing Apache HttpClient (AHC) streams to the JAX-RS client and that failing, as well as forcibly closing (actually, consuming) the stream and having an issue similar to yours. After reading Which Java HTTP client should I use in 2020? | MockLab, I started to think that we should simply move from AHC 4 to AHC 5. Now that we are on Java 11 as a baseline, maybe to switch to the Java built-in HttpClient. Otherwise, maybe I was wrong in trying to eliminate the ProcessingException exception and we should just catch it. What’s making me reconsider is LazyDecompressingInputStream – it is totally possible for the compressed stream to end, the decompressor to fail to extract more bytes. Though ProcessingException is too general of an exception, I would be more comfortable catching something like a CompressedStreamEOFException.
Xerces library use is surprising to me. We worked hard to remove Xerces use from our code and AFAIK Jena 4 is not using Xerces either. Though java.xml/ seems like the code is coming from the built-in JPMS module.
Finally, the example I got working most recently was the EWM one, not ERM.
I just want to clarify one more thing. If I use the processRawResponse function to process the query result instead of the processPagedQueryResults, I got an RDF output in the console.
I just checked the code of processPagedQueryResults and I would modify it in the following way:
try {
//Get a single artifact by its URL
response = client.getResource(resultsUrl, OSLCConstants.CT_RDF);
boolean processed = false;
if (response != null) {
//De-serialize it as a Java object
if (asJavaObjects) {
//Requirement req = response.readEntity(Requirement.class);
//printRequirementInfo(req); //print a few attributes
} else {
//Just print the raw RDF/XML (or process the XML as desired)
processRawResponse(response);
processed = true;
}
}
if (!processed && response != null) {
// discard the result
response.readEntity(String.class);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Unable to process artfiact at url: " + resultsUrl, e);
}
AFAIK, the idea is that the response must be processed even if you don’t need it. Sometimes, we had problems with just calling close (i.e. exceptions). I think AHC 5 also implements AutoCloseable to avoid dealing with these low-level details.
I´ve just changed that function, but the problem is before at result.getMembersUrls(). Adding the catch for ProcessingException as in EWMSample, I see the following:
Blockquoteago 19, 2022 1:54:09 P. M. test.sample.app.ERMSample main
GRAVE: Server has closed the connection. Are you sure you have chosen between Basic and JAS Forms auth correctly?
I do remember this with Jazz, and I fixed it somehow with EWM example but not sure how exactly. But yeah, thanks for confirming that just swallowing the exception is not the solution.
If processRawResponse works, but not processPagedQueryResults, where in processPagedQueryResults (or the nested processCurrentPage function) does your code fails? Can you step through to identify exactly where it fails?
The code fails in class OslcQueryResult.class, function initializeRdf(), line 121: rdfModel.read(response.readEntity(InputStream.class), query.getCapabilityUrl());. From the point of view of the function “processCurrentPage”, it fails at result.getMembersUrls().