acceptedTypes = Collections.singletonList(MarmottaHttpUtils.parseContentType(RDFXML.getDefaultMIMEType()));
} else {
acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(request.getHeader("Accept"));
}
ContentType _bestType = null;
RDFFormat _format = null;
for (ContentType ct : acceptedTypes) {
final RDFFormat f = Rio.getWriterFormatForMIMEType(ct.getMime());
if (f != null) {
_bestType = ct;
_format = f;
break;
}
}
if (_bestType == null || _format == null) {
// FIXME: todo
return Response.status(Status.BAD_REQUEST).entity("Could not determine Format").build();
}
final RDFFormat format = _format;
final ContentType returnType = _bestType;
final StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream outputStream) throws IOException,
WebApplicationException {
try {
final RDFWriter writer = Rio.createWriter(format, outputStream);
sparqlService.createServiceDescription(writer, request.getRequestURL().toString(), isUpdate);
} catch (RDFHandlerException e) {
log.warn("Could not send SpaqlServiceDescription: {}", e);
throw new NoLogWebApplicationException(e, Response.serverError().entity(e).build());
}
}
};
return Response.ok(entity, new MediaType(returnType.getType(), returnType.getSubtype(), returnType.getCharset().name())).build();
}