use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class ResponseDataset method doResponseDataset.
public static void doResponseDataset(HttpAction action, Dataset dataset) {
HttpServletRequest request = action.getRequest();
// Header request type
String mimeType = null;
MediaType i = ConNeg.chooseContentType(request, DEF.constructOffer, DEF.acceptTurtle);
if (i != null)
mimeType = i.getContentTypeStr();
String outputField = ResponseOps.paramOutput(request, shortNamesModel);
if (outputField != null)
mimeType = outputField;
String writerMimeType = mimeType;
if (mimeType == null) {
Fuseki.actionLog.warn("Can't find MIME type for response");
String x = FusekiNetLib.getAccept(request);
String msg;
if (x == null)
msg = "No Accept: header";
else
msg = "Accept: " + x + " : Not understood";
ServletOps.error(HttpSC.NOT_ACCEPTABLE_406, msg);
}
String contentType = mimeType;
String charset = charsetUTF8;
String forceAccept = ResponseOps.paramForceAccept(request);
if (forceAccept != null) {
contentType = forceAccept;
charset = charsetUTF8;
}
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null)
ServletOps.errorBadRequest("Can't determine output content type: " + contentType);
RDFFormat format = ActionLib.getNetworkFormatForLang(lang);
try {
ServletOps.success(action);
ServletOutputStream out = action.getResponseOutputStream();
try {
// Use the Content-Type from the content negotiation.
if (RDFLanguages.isQuads(lang))
ActionLib.datasetResponse(action, dataset.asDatasetGraph(), format, contentType);
else
ActionLib.graphResponse(action, dataset.getDefaultModel().getGraph(), format, contentType);
out.flush();
} catch (JenaException ex) {
ServletOps.errorOccurred("Failed to write output: " + ex.getMessage(), ex);
}
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
action.log.info("Exception while writing the response model: " + ex.getMessage(), ex);
ServletOps.errorOccurred("Exception while writing the response model: " + ex.getMessage(), ex);
}
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class GSP_R method execHeadQuads.
protected void execHeadQuads(HttpAction action) {
ActionLib.setCommonHeaders(action);
MediaType mediaType = ActionLib.contentNegotationQuads(action);
if (action.verbose)
action.log.info(format("[%d] Head: Content-Type=%s", action.id, mediaType.getContentTypeStr()));
ServletOps.success(action);
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class RDFLanguages method getCharsetForContentType.
public static String getCharsetForContentType(String contentType) {
MediaType ct = MediaType.create(contentType);
if (ct.getCharset() != null)
return ct.getCharset();
String mt = ct.getContentTypeStr();
if (contentTypeNTriples.equals(mt))
return charsetUTF8;
if (contentTypeNTriplesAlt.equals(mt))
return charsetASCII;
if (contentTypeNQuads.equals(mt))
return charsetUTF8;
if (contentTypeNQuadsAlt1.equals(mt))
return charsetASCII;
return charsetUTF8;
}
Aggregations