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());
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class Upload method fileUploadWorker.
/** Process an HTTP upload of RDF files (triples or quads)
* Stream straight into a graph or dataset -- unlike SPARQL_Upload the destination
* is known at the start of the multipart file body
*/
public static UploadDetails fileUploadWorker(HttpAction action, StreamRDF dest) {
String base = ActionLib.wholeRequestURL(action.request);
ServletFileUpload upload = new ServletFileUpload();
//log.info(format("[%d] Upload: Field=%s ignored", action.id, fieldName)) ;
// Overall counting.
StreamRDFCounting countingDest = StreamRDFLib.count(dest);
try {
FileItemIterator iter = upload.getItemIterator(action.request);
while (iter.hasNext()) {
FileItemStream fileStream = iter.next();
if (fileStream.isFormField()) {
// Ignore?
String fieldName = fileStream.getFieldName();
InputStream stream = fileStream.openStream();
String value = Streams.asString(stream, "UTF-8");
ServletOps.errorBadRequest(format("Only files accepted in multipart file upload (got %s=%s)", fieldName, value));
}
//Ignore the field name.
//String fieldName = fileStream.getFieldName();
InputStream stream = fileStream.openStream();
// Process the input stream
String contentTypeHeader = fileStream.getContentType();
ContentType ct = ContentType.create(contentTypeHeader);
Lang lang = null;
if (!matchContentType(ctTextPlain, ct))
lang = RDFLanguages.contentTypeToLang(ct.getContentType());
if (lang == null) {
String name = fileStream.getName();
if (name == null || name.equals(""))
ServletOps.errorBadRequest("No name for content - can't determine RDF syntax");
lang = RDFLanguages.filenameToLang(name);
if (name.endsWith(".gz"))
stream = new GZIPInputStream(stream);
}
if (lang == null)
// Desperate.
lang = RDFLanguages.RDFXML;
String printfilename = fileStream.getName();
if (printfilename == null || printfilename.equals(""))
printfilename = "<none>";
// Before
// action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s",
// action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName())) ;
// count just this step
StreamRDFCounting countingDest2 = StreamRDFLib.count(countingDest);
try {
ActionSPARQL.parse(action, countingDest2, stream, lang, base);
UploadDetails details1 = new UploadDetails(countingDest2.count(), countingDest2.countTriples(), countingDest2.countQuads());
action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), details1.detailsStr()));
} catch (RiotParseException ex) {
action.log.info(format("[%d] Filename: %s, Content-Type=%s, Charset=%s => %s : %s", action.id, printfilename, ct.getContentType(), ct.getCharset(), lang.getName(), ex.getMessage()));
throw ex;
}
}
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
ServletOps.errorOccurred(ex.getMessage());
}
// Overall results.
UploadDetails details = new UploadDetails(countingDest.count(), countingDest.countTriples(), countingDest.countQuads());
return details;
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class SPARQL_REST_RW method doPutPost.
private void doPutPost(HttpAction action, boolean overwrite) {
ContentType ct = FusekiLib.getContentType(action);
if (ct == null)
errorBadRequest("No Content-Type:");
// Helper case - if it's a possible HTTP file upload, pretend that's the action.
if (WebContent.contentTypeMultipartFormData.equalsIgnoreCase(ct.getContentType())) {
String base = wholeRequestURL(action.request);
SPARQL_Upload.upload(action, base);
return;
}
if (WebContent.matchContentType(WebContent.ctMultipartMixed, ct))
error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/mixed not supported");
boolean existedBefore = false;
if (action.isTransactional())
existedBefore = addDataIntoTxn(action, overwrite);
else
existedBefore = addDataIntoNonTxn(action, overwrite);
if (existedBefore)
ServletBase.successNoContent(action);
else
ServletBase.successCreated(action);
}
Aggregations