use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class Upload method incomingData.
public static UploadDetails incomingData(HttpAction action, StreamRDF dest) {
ContentType ct = FusekiLib.getContentType(action);
if (ct == null) {
ServletOps.errorBadRequest("No content type");
return null;
}
if (matchContentType(ctMultipartFormData, ct)) {
return fileUploadWorker(action, dest);
}
// Single graph (or quads) in body.
String base = ActionLib.wholeRequestURL(action.request);
Lang lang = RDFLanguages.contentTypeToLang(ct.getContentType());
if (lang == null) {
ServletOps.errorBadRequest("Unknown content type for triples: " + ct);
return null;
}
InputStream input = null;
try {
input = action.request.getInputStream();
} catch (IOException ex) {
IO.exception(ex);
}
int len = action.request.getContentLength();
StreamRDFCounting countingDest = StreamRDFLib.count(dest);
try {
ActionSPARQL.parse(action, countingDest, input, lang, base);
UploadDetails details = new UploadDetails(countingDest.count(), countingDest.countTriples(), countingDest.countQuads());
action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), details.detailsStr()));
return details;
} catch (RiotParseException ex) {
action.log.info(format("[%d] Body: Content-Length=%d, Content-Type=%s, Charset=%s => %s : %s", action.id, len, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage()));
throw ex;
}
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_GSP_RW method doPutPost.
private void doPutPost(HttpAction action, boolean overwrite) {
ContentType ct = FusekiLib.getContentType(action);
if (ct == null)
ServletOps.errorBadRequest("No Content-Type:");
if (matchContentType(ctMultipartMixed, ct)) {
ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/mixed not supported");
}
UploadDetails details;
if (action.isTransactional())
details = addDataIntoTxn(action, overwrite);
else
details = addDataIntoNonTxn(action, overwrite);
MediaType mt = ConNeg.chooseCharset(action.request, DEF.jsonOffer, DEF.acceptJSON);
if (mt == null) {
// No return body.
if (details.getExistedBefore().equals(PreState.ABSENT))
ServletOps.successCreated(action);
else
ServletOps.successNoContent(action);
return;
}
ServletOps.uploadResponse(action, details);
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_Query method validateParams.
/**
* Helper method for validating request.
* @param request HTTP request
* @param params parameters in a collection of Strings
*/
protected void validateParams(HttpAction action, Collection<String> params) {
HttpServletRequest request = action.request;
ContentType ct = FusekiLib.getContentType(request);
boolean mustHaveQueryParam = true;
if (ct != null) {
String incoming = ct.getContentType();
if (matchContentType(ctSPARQLQuery, ct)) {
mustHaveQueryParam = false;
// Drop through.
} else if (matchContentType(ctHTMLForm, ct)) {
// Nothing specific to do
} else
ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Unsupported: " + incoming);
}
if (mustHaveQueryParam) {
int N = countParamOccurences(request, paramQuery);
if (N == 0)
ServletOps.errorBadRequest("SPARQL Query: No 'query=' parameter");
if (N > 1)
ServletOps.errorBadRequest("SPARQL Query: Multiple 'query=' parameters");
// application/sparql-query does not use a query param.
String queryStr = request.getParameter(HttpNames.paramQuery);
if (queryStr == null)
ServletOps.errorBadRequest("SPARQL Query: No query specified (no 'query=' found)");
if (queryStr.isEmpty())
ServletOps.errorBadRequest("SPARQL Query: Empty query string");
}
if (params != null) {
Enumeration<String> en = request.getParameterNames();
for (; en.hasMoreElements(); ) {
String name = en.nextElement();
if (!params.contains(name))
ServletOps.warning(action, "SPARQL Query: Unrecognize request parameter (ignored): " + name);
}
}
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_Query method perform.
@Override
protected final void perform(HttpAction action) {
// OPTIONS
if (action.request.getMethod().equals(HttpNames.METHOD_OPTIONS)) {
// Share with update via SPARQL_Protocol.
doOptions(action);
return;
}
// GET
if (action.request.getMethod().equals(HttpNames.METHOD_GET)) {
executeWithParameter(action);
return;
}
ContentType ct = FusekiLib.getContentType(action);
// POST ?query= and no Content-Type
if (ct == null || isHtmlForm(ct)) {
// validation checked that if no Content-type, then its a POST with ?query=
executeWithParameter(action);
return;
}
// POST application/sparql-query
if (matchContentType(ct, ctSPARQLQuery)) {
executeBody(action);
return;
}
ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + ct.getContentType());
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_Update method perform.
@Override
protected void perform(HttpAction action) {
ContentType ct = FusekiLib.getContentType(action);
if (ct == null)
ct = ctSPARQLUpdate;
if (matchContentType(ctSPARQLUpdate, ct)) {
executeBody(action);
return;
}
if (isHtmlForm(ct)) {
executeForm(action);
return;
}
ServletOps.error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + action.request.getContentType());
}
Aggregations