use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class REST_Quads method doPost.
@Override
protected void doPost(HttpAction action) {
if (!action.getDatasetRef().allowDatasetUpdate)
errorMethodNotAllowed("POST");
// Graph Store Protocol mode - POST triples to dataset causes
// a new graph to be created and the new URI returned via Location.
// Normally off.
// When off, POST of triples goes to default graph.
boolean gspMode = Fuseki.graphStoreProtocolPostCreate;
// Code to pass the GSP test suite.
// Not necessarily good code.
String x = action.request.getContentType();
if (x == null)
errorBadRequest("Content-type required for data format");
MediaType mediaType = MediaType.create(x);
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType());
if (lang == null)
lang = RDFLanguages.TRIG;
if (action.verbose)
log.info(format("[%d] Post: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));
if (RDFLanguages.isQuads(lang))
doPostQuads(action, lang);
else if (gspMode && RDFLanguages.isTriples(lang))
doPostTriplesGSP(action, lang);
else if (RDFLanguages.isTriples(lang))
doPostTriples(action, lang);
else
errorBadRequest("Not a triples or quads format: " + mediaType);
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class REST_Quads method doGet.
@Override
protected void doGet(HttpAction action) {
MediaType mediaType = HttpAction.contentNegotationQuads(action);
ServletOutputStream output;
try {
output = action.response.getOutputStream();
} catch (IOException ex) {
errorOccurred(ex);
output = null;
}
TypedOutputStream out = new TypedOutputStream(output, mediaType);
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType());
if (lang == null)
lang = RDFLanguages.TRIG;
if (action.verbose)
log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));
if (!RDFLanguages.isQuads(lang))
errorBadRequest("Not a quads format: " + mediaType);
action.beginRead();
try {
DatasetGraph dsg = action.getActiveDSG();
RDFDataMgr.write(out, dsg, lang);
success(action);
} finally {
action.endRead();
}
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class ServletOps method successPage.
public static void successPage(HttpAction action, String message) {
String x = action.getRequestHeader(HttpNames.hAccept);
MediaType mt = null;
if (x != null && x.equals("*/*")) {
if (action.getRequestContentType().equals(WebContent.contentTypeHTMLForm))
mt = mtTextHTML;
}
if (mt == null && x != null)
mt = ConNeg.chooseContentType(action.getRequest(), successReponseAccept, MediaType.create("text/plain"));
if (mt == null)
mt = mtTextHTML;
if (WebContent.ctTextPlain.agreesWith(mt)) {
successPageText(action, message);
return;
}
if (WebContent.ctJSON.agreesWith(mt)) {
successPageJson(action, message);
return;
}
// Default.
successPageHtml(action, message);
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class ConNeg method chooseCharset.
/**
* <p>
* Chooses the charset by using the Accept-Charset HTTP header.
* </p>
* <p>
* See {@link ConNeg#choose(String, AcceptList, MediaType)}.
* </p>
*
* @param httpRequest HTTP request
* @param myPrefs accept list
* @param defaultMediaType default media type
* @return media type chosen
*/
public static MediaType chooseCharset(HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType) {
String a = httpRequest.getHeader(hAcceptCharset);
if (log.isDebugEnabled())
log.debug("Accept-Charset request: " + a);
MediaType item = choose(a, myPrefs, defaultMediaType);
if (log.isDebugEnabled())
log.debug("Charset chosen: " + item);
return item;
}
use of org.apache.jena.atlas.web.MediaType in project jena by apache.
the class ConNeg method chooseContentType.
/**
* <p>
* Choose the content media type by extracting the Accept HTTP header from the
* HTTP request and choosing (see
* {@link ConNeg#choose(String, AcceptList, MediaType)}) a content media type
* that matches the header.
* </p>
*
* @param httpRequest HTTP request
* @param myPrefs accept list
* @param defaultMediaType default media type
* @return media type chosen
*/
public static MediaType chooseContentType(HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType) {
String a = FusekiNetLib.getAccept(httpRequest);
if (log.isDebugEnabled())
log.debug("Accept request: " + a);
MediaType item = choose(a, myPrefs, defaultMediaType);
if (log.isDebugEnabled())
log.debug("Content type chosen: " + item);
return item;
}
Aggregations