jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1410561 - in /jena/trunk: jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/ jena-arq/src/main/java/org/openjena/riot/ jena-fuseki/src-dev/dev/ jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/
Date Fri, 16 Nov 2012 20:41:16 GMT
Author: andy
Date: Fri Nov 16 20:41:15 2012
New Revision: 1410561

URL: http://svn.apache.org/viewvc?rev=1410561&view=rev
Log:
Support for multifile upload (Graph Store Protocol)

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
    jena/trunk/jena-arq/src/main/java/org/openjena/riot/WebContent.java
    jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/DumpServlet.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java?rev=1410561&r1=1410560&r2=1410561&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/DatasetGraphTrackActive.java
Fri Nov 16 20:41:15 2012
@@ -58,8 +58,9 @@ public abstract class DatasetGraphTrackA
     public void abort()
     {
         checkActive() ;
-        _abort() ;
+        // Set before calling _abort, which might throw an exception. 
         inTransaction = false ;
+        _abort() ;
     }
     
     @Override

Modified: jena/trunk/jena-arq/src/main/java/org/openjena/riot/WebContent.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/openjena/riot/WebContent.java?rev=1410561&r1=1410560&r2=1410561&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/openjena/riot/WebContent.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/openjena/riot/WebContent.java Fri Nov 16 20:41:15
2012
@@ -55,7 +55,7 @@ public class WebContent
     public static final String contentTypeTriX              = "application/trix+xml" ;
     public static final String contentTypeOctets            = "application/octet-stream"
;
     public static final String contentTypeMultiMixed        = "multipart/mixed" ;
-    public static final String contentTypeMultiForm         = "multipart/form" ;
+    public static final String contentTypeMultiFormData     = "multipart/form-data" ;
     public static final String contentTypeMultiAlt          = "multipart/alternative" ;
 
     public static final String contentTypeRdfJson			= "application/rdf+json" ;

Modified: jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java?rev=1410561&r1=1410560&r2=1410561&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java (original)
+++ jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java Fri Nov 16 20:41:15 2012
@@ -53,9 +53,13 @@ public class RunFuseki
     private static void main1()
     {
         FusekiCmd.main(
-                     //"--update", "--mem", "--gsp", "--uber", "/ds"
+                     "--update", "--mem", "--gsp", "--uber", "/ds"
+                     
+                     //"--update", "--mem", "/ds"
+                     
                      //"--update", "--loc=/home/afs/tmp/DB", "--set=tdb:unionDefaultGraph=true",
"--update", "/ds"
-                     "--update", "--memtdb", "--set=tdb:unionDefaultGraph=true", "--update",
"/ds"
+                     //"--update", "--memtdb", "--set=tdb:unionDefaultGraph=true", "--update",
"/ds"
+                     
                     //"-v", 
                     //"--debug",
                     //"--update",

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/DumpServlet.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/DumpServlet.java?rev=1410561&r1=1410560&r2=1410561&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/DumpServlet.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/DumpServlet.java
Fri Nov 16 20:41:15 2012
@@ -81,9 +81,10 @@ public class DumpServlet extends HttpSer
             out.print(dumpRequest(req)) ;
             out.println() ;
                         
-            out.println("==== Body");
+            out.println(">>>> Body");
             out.println() ;
             printBody(out, req) ;
+            out.println("<<<< Body");
             
             out.println("==== ServletContext");
             out.println() ;
@@ -206,7 +207,7 @@ public class DumpServlet extends HttpSer
             }
 
             pw.println() ;
-            printBody(pw, req) ;
+            //printBody(pw, req) ;
 
             pw.close() ;
             sw.close() ;
@@ -226,12 +227,13 @@ public class DumpServlet extends HttpSer
             // This is a dump - try to do something that works, even if inefficient.
             in.mark(100*1024) ;
 
-
-        while(in.ready())
+        while(true)
         {
-            pw.println(in.readLine());
+            String x = in.readLine() ;
+            if ( x == null )
+                break ;
+            pw.println(x) ;
         }
-
         try { in.reset() ;} catch (IOException e) { System.out.println("DumpServlet: Reset
of content failed: "+e) ; }
     }
     

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java?rev=1410561&r1=1410560&r2=1410561&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
Fri Nov 16 20:41:15 2012
@@ -204,7 +204,7 @@ public abstract class SPARQL_REST extend
 
     private void dispatch(HttpActionREST action)
     {
-        HttpServletRequest req = action.request ;
+     HttpServletRequest req = action.request ;
         HttpServletResponse resp = action.response ;
         String method = req.getMethod().toUpperCase() ;
 
@@ -285,18 +285,22 @@ public abstract class SPARQL_REST extend
     protected static DatasetGraph parseBody(HttpActionREST action)
     {
         String contentTypeHeader = action.request.getContentType() ;
+        
         if ( contentTypeHeader == null )
             errorBadRequest("No content type: "+contentTypeHeader) ;
             // lang = Lang.guess(action.request.getRequestURI()) ;
         
         ContentType ct = ContentType.parse(contentTypeHeader) ;
         
+        String base = wholeRequestURL(action.request) ;
+        
         // Use WebContent names
-        if ( WebContent.contentTypeMultiForm.equalsIgnoreCase(ct.getContentType()) )
+        if ( WebContent.contentTypeMultiFormData.equalsIgnoreCase(ct.getContentType()) )
         {
-            //log.warn("multipart/form-data not supported (yet)") ;
-            error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/form-data not supported")
;
-            return null ;
+//            //log.warn("multipart/form-data not supported (yet)") ;
+//            error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "multipart/form-data not supported")
;
+            Graph graphTmp = SPARQL_Upload.upload(action.id,  action.getDatasetRef(), action.request,
action.response, base) ;
+            return DatasetGraphFactory.create(graphTmp) ;
         }
         
         if (WebContent.contentTypeMultiMixed.equals(ct.getContentType()) )
@@ -326,8 +330,6 @@ public abstract class SPARQL_REST extend
         
         try {
             InputStream input = action.request.getInputStream() ;
-            String base = wholeRequestURL(action.request) ;
-            
             boolean buffering = false ;
             if ( buffering )
             {

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java?rev=1410561&r1=1410560&r2=1410561&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
Fri Nov 16 20:41:15 2012
@@ -52,7 +52,7 @@ public class SPARQL_Upload extends SPARQ
 {
     private static ErrorHandler errorHandler = ErrorHandlerFactory.errorHandlerStd(log) ;
     
-    private class HttpActionUpload extends HttpAction {
+    private static class HttpActionUpload extends HttpAction {
         public HttpActionUpload(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse
response, boolean verbose)
         {
             super(id, desc, request, response, verbose) ;
@@ -91,18 +91,63 @@ public class SPARQL_Upload extends SPARQ
         if ( ! isMultipart )
             error(HttpSC.BAD_REQUEST_400 , "Not a file upload") ;
         
-        ServletFileUpload upload = new ServletFileUpload();
-        // Locking only needed over the insert into dataset
+        long tripleCount = -1 ;
+        action.beginWrite() ;
         try {
-            String graphName = null ;
-            Graph graphTmp = GraphFactory.createGraphMem() ;
-            Node gn = null ;
-            String name = null ;  
-            ContentType ct = null ;
-            Lang lang = null ;
-            int tripleCount = 0 ;
+            Graph graphTmp = GraphFactory.createDefaultGraph() ;
+            String graphName = upload(action, graphTmp, "http://example/upload-base/") ;
+            tripleCount = graphTmp.size() ;
             
-            FileItemIterator iter = upload.getItemIterator(request);
+            log.info(format("[%d] Upload: Graph: %s (%d triple(s))", 
+                            action.id, graphName,  tripleCount)) ;
+
+            if ( graphName.equals(HttpNames.valueDefault) ) 
+                action.getActiveDSG().getDefaultGraph().getBulkUpdateHandler().add(graphTmp)
;
+            else
+            {
+                Node gn = Node.createURI(graphName) ;
+                action.getActiveDSG().getGraph(gn).getBulkUpdateHandler().add(graphTmp) ;
+            }
+            tripleCount = graphTmp.size();
+            action.commit() ;
+        } catch (RuntimeException ex)
+        {
+            // If anything went wrong, try to backout.
+            try { action.abort() ; } catch (Exception ex2) {}
+            errorOccurred(ex.getMessage()) ;
+        } 
+        finally { action.endWrite() ; }
+        try {
+            response.setContentType("text/plain") ;
+            response.getOutputStream().print("Triples = "+tripleCount) ;
+            success(action) ;
+        }
+        catch (Exception ex) { errorOccurred(ex) ; }
+    }
+    
+    static public Graph upload(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse
response, String destination)
+    {
+        HttpActionUpload action = new HttpActionUpload(id, desc, request, response, false)
;
+        Graph graphTmp = GraphFactory.createDefaultGraph() ;
+        String graphName = upload(action, graphTmp, destination) ;
+        return graphTmp ;
+    }
+    
+    /** @return any graph name found.
+     */
+    
+    static private String upload(HttpActionUpload action, Graph graphDst, String base)
+    {
+        ServletFileUpload upload = new ServletFileUpload();
+        // Locking only needed over the insert into the dataset
+        String graphName = null ;
+        String name = null ;  
+        ContentType ct = null ;
+        Lang lang = null ;
+        int tripleCount = 0 ;
+
+        try {
+            FileItemIterator iter = upload.getItemIterator(action.request);
             while (iter.hasNext()) {
                 FileItemStream item = iter.next();
                 String fieldName = item.getFieldName();
@@ -131,81 +176,52 @@ public class SPARQL_Upload extends SPARQ
                                 if ( iri.getRawPath().charAt(0) != '/' )
                                     errorBadRequest("Bad IRI: Path does not start '/': "+graphName)
;
                             } 
-                            gn = Node.createURI(graphName) ;
                         }
                     }
                     else if ( fieldName.equals(HttpNames.paramDefaultGraphURI) )
                         graphName = null ;
                     else
                         // Add file type?
-                        log.info(format("[%d] Upload: Field="+fieldName+" - ignored")) ;
+                        log.info(format("[%d] Upload: Field=%s ignored", action.id, fieldName))
;
                 } else {
                     // Process the input stream
                     name = item.getName() ; 
                     if ( name == null || name.equals("") || name.equals("UNSET FILE NAME")
) 
                         errorBadRequest("No name for content - can't determine RDF syntax")
;
-                    
+
                     String contentTypeHeader = item.getContentType() ;
                     ct = ContentType.parse(contentTypeHeader) ;
-                    
+
                     lang = FusekiLib.langFromContentType(ct.getContentType()) ;
                     if ( lang == null )
                         lang = Lang.guess(name) ;
                     if ( lang == null )
                         // Desperate.
                         lang = Lang.RDFXML ;
-                    
-                    String base = "http://example/upload-base/" ;
+
                     // We read into a in-memory graph, then (if successful) update the dataset.
                     // This isolates errors.
-                    Sink<Triple> sink = new SinkTriplesToGraph(graphTmp) ;
+                    Sink<Triple> sink = new SinkTriplesToGraph(graphDst) ;
                     LangRIOT parser = RiotReader.createParserTriples(stream, lang, base,
sink) ;
                     parser.getProfile().setHandler(errorHandler) ;
+                    log.info(format("[%d] Upload: Filename: %s, Content-Type=%s, Charset=%s
=> %s", 
+                                    action.id, name,  ct.getContentType(), ct.getCharset(),
lang.getName())) ;
                     try {
                         parser.parse() ;
                     } 
                     catch (RiotException ex) { errorBadRequest("Parse error: "+ex.getMessage())
; }
                     finally { sink.close() ; }
-                    
-                    tripleCount = graphTmp.size() ;
-                    //DatasetGraph dsgTmp = DatasetGraphFactory.create(graphTmp) ;
                 }
             }    
-                
+
             if ( graphName == null )
                 graphName = "default" ;
-            log.info(format("[%d] Upload: Filename: %s, Content-Type=%s, Charset=%s =>
(%s,%s,%d triple(s))", 
-                                      action.id, name,  ct.getContentType(), ct.getCharset(),
graphName, lang.getName(), tripleCount)) ;
-
-            // Delay updating until all form fields processed to get the graph name 
-            action.beginWrite() ;
-            try {
-                if ( graphName.equals(HttpNames.valueDefault) ) 
-                    action.getActiveDSG().getDefaultGraph().getBulkUpdateHandler().add(graphTmp)
;
-                else
-                    action.getActiveDSG().getGraph(gn).getBulkUpdateHandler().add(graphTmp)
;
-                action.commit() ;
-            } catch (RuntimeException ex)
-            {
-                // If anything went wrong, try to backout.
-                action.abort() ;
-                errorOccurred(ex.getMessage()) ;
-                return ;
-            } 
-            finally { action.endWrite() ; }
-                    
-            response.setContentType("text/plain") ;
-            response.getOutputStream().print("Triples = "+tripleCount) ;
-            success(action) ;
+            return graphName ;
         }
         catch (ActionErrorException ex) { throw ex ; }
-        catch (Exception ex)
-        {
-            errorOccurred(ex) ;
-            return ;
-        }
-    }
-    
+        catch (Exception ex)            { errorOccurred(ex) ; return null ; }
+    }            
+
     @Override
     protected void validate(HttpServletRequest request)
     {}



Mime
View raw message