It's all about the answers!

Ask a question

[Java] Can't read RQM Resource Shape RDF as an OSLC ResourceShape Java class: Error 400 Bad Request

Fernando Cabrera (1527) | asked Jun 25 '19, 3:41 p.m.

 I'm using the Lyo OSLC4J Client to connect to a Jazz Server:

I'm trying to map the Resource Shape RDF of an RQM artifact to a ResourceShape instance of the class: org.eclipse.lyo.oslc4j.core.model.ResourceShape

The way I'm doing this is using the getResource method from the Oslc client which returns a Response and then using the readEntity method from the response to read it as a ResourceShape:

final Response response = client.getResource("https://{server}:9443/qm/oslc_qm/contexts/{projectId}/shape/creation/", OSLCConstants.CT_RDF);
final ResourceShape rdf = response.readEntity(ResourceShape.class); 

The issue is that the last line throws a 400 Bad Request Exception. 

What do I need to modify from my approach to map this response correctly to the ResourceShape class?

Ralph Schoon commented Jun 26 '19, 1:33 a.m.

Maybe you have more luck in the Lyo forum. 

3 answers

permanent link
Jim Amsden (27837) | answered Jun 27 '19, 9:30 a.m.

 response.readEntity(ResourceShape.class) is expecting the HTTP entity response body to be an RDF resource about a ResourceShape. If you are not logged in, you may get an HTTP status code of 200, but the response body will be HTML indicating the browser should provide authentication. Try reading the entity into a String.class to see what you actually got.

permanent link
Fernando Cabrera (1527) | answered Jul 08 '19, 3:12 p.m.

 Long story short:

RQM returns resource shapes with the dcterms:title and dcterms:description tags repeated, one with the @xml:lang tag attribute specifying the English localization and one without it. This makes the direct unmarshalling to the ResourceShape class from the OSLC Lyo client to fail since it expects in there and in the Property attributes for those fields to be present once. The attribute is defined as String type and not as String[].

There are two ways to solve this situation: Either create a custom ResourceShape and Property classes with title and description defined as an array of Strings and unmarshal the response as that, or parse the response as String.class, read the XML, remove the repeated tags and then use Apache Jena to unmarshal it as ResourceShape.


permanent link
Andrew Berezovskyi (764) | answered Jul 17 '19, 9:15 a.m.

 Thanks Fernando,

We will look into adding some kind of support in Lyo for localised literals. Repeated properties with language tags do not violate any shape cardinality restrictions per se. In the short term, I think using shapes with sets/arrays is the best option. But we need to consider compat issues, let's discuss that here:

Just a note: oslc4j-client is a work-in-progress, which will be released in Lyo 4.0. The other client is stable in the current version 2.4.0.

(Eclipse Lyo project lead)

Your answer

Register or to post your answer.