use of org.apache.clerezza.rdf.core.serializedform.UnsupportedFormatException in project stanbol by apache.
the class RootResource method storeOntology.
/**
* POSTs an ontology content as application/x-www-form-urlencoded
*
* @param content
* @param headers
* @return
*/
@POST
@Consumes(value = { RDF_XML, TURTLE, X_TURTLE, N3, N_TRIPLE, OWL_XML, FUNCTIONAL_OWL, MANCHESTER_OWL, RDF_JSON })
public Response storeOntology(InputStream content, @Context HttpHeaders headers) {
long before = System.currentTimeMillis();
ResponseBuilder rb;
MediaType mt = headers.getMediaType();
if (RDF_XML_TYPE.equals(mt) || TURTLE_TYPE.equals(mt) || X_TURTLE_TYPE.equals(mt) || N3_TYPE.equals(mt) || N_TRIPLE_TYPE.equals(mt) || RDF_JSON_TYPE.equals(mt)) {
OWLOntologyID key = null;
try {
key = ontologyProvider.loadInStore(content, headers.getMediaType().toString(), true);
rb = Response.ok();
} catch (UnsupportedFormatException e) {
log.warn("POST method failed for media type {}. This should not happen (should fail earlier)", headers.getMediaType());
rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
} catch (IOException e) {
throw new WebApplicationException(e, BAD_REQUEST);
}
// An exception should have been thrown earlier, but just in case.
if (key == null || key.isAnonymous()) {
rb = Response.status(Status.INTERNAL_SERVER_ERROR);
}
} else if (OWL_XML_TYPE.equals(mt) || FUNCTIONAL_OWL_TYPE.equals(mt) || MANCHESTER_OWL_TYPE.equals(mt)) {
try {
OntologyInputSource<OWLOntology> src = new OntologyContentInputSource(content);
ontologyProvider.loadInStore(src.getRootOntology(), true);
rb = Response.ok();
} catch (OWLOntologyCreationException e) {
throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
}
} else {
rb = Response.status(UNSUPPORTED_MEDIA_TYPE);
}
// addCORSOrigin(servletContext, rb, headers);
Response r = rb.build();
log.debug("POST request for ontology addition completed in {} ms with status {}.", (System.currentTimeMillis() - before), r.getStatus());
return r;
}
Aggregations