jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1551382 - in /jena/branches/jena-fuseki-new-ui/src: main/java/org/apache/jena/fuseki/servlets/ test/java/org/apache/jena/fuseki/
Date Mon, 16 Dec 2013 22:18:45 GMT
Author: andy
Date: Mon Dec 16 22:18:45 2013
New Revision: 1551382

URL: http://svn.apache.org/r1551382
Log:
Add conneg for GET /dataset.
Add tests.

Added:
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java
      - copied, changed from r1551061, jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestGSP.java
Removed:
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestGSP.java
Modified:
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
    jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_R.java
    jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java?rev=1551382&r1=1551381&r2=1551382&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
Mon Dec 16 22:18:45 2013
@@ -18,25 +18,6 @@
 
 package org.apache.jena.fuseki.servlets ;
 
-import static java.lang.String.format ;
-
-import java.io.IOException ;
-
-import javax.servlet.ServletOutputStream ;
-
-import org.apache.jena.atlas.web.MediaType ;
-import org.apache.jena.atlas.web.TypedOutputStream ;
-import org.apache.jena.fuseki.FusekiLib ;
-import org.apache.jena.fuseki.HttpNames ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.RiotException ;
-import org.apache.jena.riot.system.StreamRDF ;
-import org.apache.jena.riot.system.StreamRDFLib ;
-
-import com.hp.hpl.jena.sparql.core.DatasetGraph ;
-import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
 
 /**
  * Servlet for operations directly on a dataset - REST(ish) behaviour on the
@@ -52,84 +33,29 @@ public abstract class REST_Quads extends
 
     @Override
     protected void validate(HttpAction action) {
-        // already checked?
-    }
-
-    @Override
-    protected void doGet(HttpAction action) {
-        MediaType mediaType = HttpAction.contentNegotationQuads(action) ;
-        ServletOutputStream output ;
-        try {
-            output = action.response.getOutputStream() ;
-        } catch (IOException ex) {
-            ServletOps.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 )
-            action.log.info(format("[%d]   Get: Content-Type=%s, Charset=%s => %s", action.id,
-                                   mediaType.getContentType(), mediaType.getCharset(), lang.getName()))
;
-        if ( !RDFLanguages.isQuads(lang) )
-            ServletOps.errorBadRequest("Not a quads format: " + mediaType) ;
-
-        action.beginRead() ;
-        try {
-            DatasetGraph dsg = action.getActiveDSG() ;
-            RDFDataMgr.write(out, dsg, lang) ;
-            ServletOps.success(action) ;
-        } finally {
-            action.endRead() ;
-        }
+        // Check in the operations itself.
     }
 
     @Override
     protected void doOptions(HttpAction action) {
-        action.response.setHeader(HttpNames.hAllow, "GET, HEAD, OPTIONS") ;
-        action.response.setHeader(HttpNames.hContentLengh, "0") ;
-        ServletOps.success(action) ;
+        ServletOps.errorMethodNotAllowed("OPTIONS") ;
     }
 
     @Override
     protected void doHead(HttpAction action) {
-        action.beginRead() ;
-        try {
-            MediaType mediaType = HttpAction.contentNegotationQuads(action) ;
-            ServletOps.success(action) ;
-        } finally {
-            action.endRead() ;
-        }
+        ServletOps.errorMethodNotAllowed("HEAD") ;
     }
 
     @Override
     protected void doPost(HttpAction action) {
-        if ( !action.getDatasetRef().allowDatasetUpdate )
-            ServletOps.errorMethodNotAllowed("POST") ;
-
-        if ( action.isTransactional() )
-            doPutPostTxn(action, false) ;
-        else
-            doPutPostNonTxn(action, false) ;
+        ServletOps.errorMethodNotAllowed("POST") ;
     }
 
     @Override
     protected void doPut(HttpAction action) {
-        if ( !action.getDatasetRef().allowDatasetUpdate )
-            ServletOps.errorMethodNotAllowed("POST") ;
-
-        if ( action.isTransactional() )
-            doPutPostTxn(action, false) ;
-        else
-            doPutPostNonTxn(action, false) ;
+        ServletOps.errorMethodNotAllowed("PUT") ;
     }
 
-    // These are very similar to SPARQL_REST_RW.addDataIntoTxn/nonTxn
-    // Maybe can be usually DRYed.
-
     @Override
     protected void doDelete(HttpAction action) {
         ServletOps.errorMethodNotAllowed("DELETE") ;
@@ -140,64 +66,12 @@ public abstract class REST_Quads extends
         ServletOps.errorMethodNotAllowed("PATCH") ;
     }
 
-    private void doPutPostTxn(HttpAction action, boolean clearFirst) {
-        action.beginWrite() ;
-        try {
-            DatasetGraph dsg = action.getActiveDSG() ;
-            StreamRDF dest = StreamRDFLib.dataset(dsg) ;
-            Upload.incomingData(action, dest, false) ;
-            action.commit() ;
-            ServletOps.success(action) ;
-        } catch (RiotException ex) {
-            // Parse error
-            action.abort() ;
-            ServletOps.errorBadRequest(ex.getMessage()) ;
-        } catch (Exception ex) {
-            // Something else went wrong. Backout.
-            action.abort() ;
-            ServletOps.errorOccurred(ex.getMessage()) ;
-        } finally {
-            action.endWrite() ;
-        }
-    }
-    
-    // XXX Logging
-    // XXX Logging in Upload.incomingData
-
-    private void doPutPostNonTxn(HttpAction action, boolean clearFirst) {
-        DatasetGraph dsgTmp = DatasetGraphFactory.createMem() ;
-        StreamRDF dest = StreamRDFLib.dataset(dsgTmp) ;
-
-        try {
-            Upload.incomingData(action, dest, false) ;
-        } catch (RiotException ex) {
-            ServletOps.errorBadRequest(ex.getMessage()) ;
-        }
-        // Now insert into dataset
-        action.beginWrite() ;
-        try {
-            FusekiLib.addDataInto(dsgTmp, action.getActiveDSG()) ;
-            action.commit() ;
-            ServletOps.success(action) ;
-        } catch (Exception ex) {
-            // We're in the non-transactional branch, this probably will not
-            // work
-            // but it might and there is no harm safely trying.
-            try {
-                action.abort() ;
-            } catch (Exception ex2) {}
-            ServletOps.errorOccurred(ex.getMessage()) ;
-        } finally {
-            action.endWrite() ;
-        }
-
-    }
-
 //    static int counter = 0 ;
 //
 //    protected void doPostTriplesGSP(HttpAction action, Lang lang) {
 //        // Old code.
 //        // Assumes transactional.
+//        // Auto create sub-graph on POST    
 //        action.beginWrite() ;
 //        try {
 //            DatasetGraph dsg = action.getActiveDSG() ;

Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_R.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_R.java?rev=1551382&r1=1551381&r2=1551382&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_R.java
(original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_R.java
Mon Dec 16 22:18:45 2013
@@ -27,9 +27,7 @@ import javax.servlet.ServletOutputStream
 import org.apache.jena.atlas.web.MediaType ;
 import org.apache.jena.atlas.web.TypedOutputStream ;
 import org.apache.jena.fuseki.HttpNames ;
-import org.apache.jena.riot.Lang ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.RDFLanguages ;
+import org.apache.jena.riot.* ;
 
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 
@@ -71,7 +69,10 @@ public class REST_Quads_R extends REST_Q
         action.beginRead() ;
         try {
             DatasetGraph dsg = action.getActiveDSG() ;
-            RDFDataMgr.write(out, dsg, lang) ;
+            action.response.setHeader("Content-type", lang.getContentType().toHeaderString());
+            RDFFormat fmt =
+                ( lang == Lang.RDFXML ) ? RDFFormat.RDFXML_PLAIN : RDFWriterRegistry.defaultSerialization(lang)
; 
+            RDFDataMgr.write(out, dsg, fmt) ;
             ServletOps.success(action) ;
         } finally {
             action.endRead() ;

Modified: jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java?rev=1551382&r1=1551381&r2=1551382&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TS_Fuseki.java Mon
Dec 16 22:18:45 2013
@@ -38,7 +38,7 @@ import org.junit.runners.Suite ;
     , TestDatasetAccessorHTTP.class
     , TestQuery.class
     , TestAuth.class
-    , TestGSP.class
+    , TestDatasetOps.class
     , TestFileUpload.class
 })
 public class TS_Fuseki extends ServerTest

Copied: jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java
(from r1551061, jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestGSP.java)
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java?p2=jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java&p1=jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestGSP.java&r1=1551061&r2=1551382&rev=1551382&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestGSP.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java
Mon Dec 16 22:18:45 2013
@@ -24,7 +24,6 @@ import static org.apache.jena.fuseki.Ser
 
 import java.io.IOException ;
 import java.io.OutputStream ;
-import java.io.StringReader ;
 
 import org.apache.http.HttpEntity ;
 import org.apache.http.entity.ContentProducer ;
@@ -32,9 +31,12 @@ import org.apache.http.entity.EntityTemp
 import org.apache.jena.atlas.junit.BaseTest ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.atlas.web.HttpException ;
-import org.apache.jena.riot.Lang ;
+import org.apache.jena.atlas.web.TypedInputStream ;
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.riot.RDFFormat ;
+import org.apache.jena.riot.WebContent ;
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
 import org.apache.jena.riot.web.HttpOp ;
 import org.apache.jena.web.HttpSC ;
 import org.junit.AfterClass ;
@@ -49,7 +51,7 @@ import com.hp.hpl.jena.sparql.sse.SSE ;
 /** TestDatasetAccessorHTTP does most of the GSP testing.
  *  This class adds the testing of Fuseki extras.
  */
-public class TestGSP extends BaseTest 
+public class TestDatasetOps extends BaseTest 
 {
     @BeforeClass
     public static void beforeClass() {
@@ -105,17 +107,61 @@ public class TestGSP extends BaseTest 
     @Test public void gsp_x_04() {
         gsp_x(serviceREST, urlDataset) ;
     }
+
     private void gsp_x(String outward, String inward) {
         HttpEntity e = datasetToHttpEntity(data) ;
         HttpOp.execHttpPut(outward, e);
-        String x = HttpOp.execHttpGetString(inward, "application/n-quads") ;
         DatasetGraph dsg = DatasetGraphFactory.createMem() ;
-        RDFDataMgr.read(dsg, new StringReader(x), null, Lang.NQUADS) ;
+        RDFDataMgr.read(dsg, inward) ;
+//        String x = HttpOp.execHttpGetString(inward, "application/n-quads") ;
+//        RDFDataMgr.read(dsg, new StringReader(x), null, Lang.NQUADS) ;
         assertEquals(2, dsg.getDefaultGraph().size()) ;
     }
 
+    // Get dataset.  Tests conneg.
+    @Test 
+    public void gsp_x_10() {
+        gsp_x_ct(urlDataset, WebContent.contentTypeNQuads, WebContent.contentTypeNQuads)
;
+    }
+
+    @Test 
+    public void gsp_x_11() {
+        gsp_x_ct(urlDataset, WebContent.contentTypeNQuadsAlt1, WebContent.contentTypeNQuads)
;
+    }
+
+    @Test 
+    public void gsp_x_12() {
+        gsp_x_ct(urlDataset, WebContent.contentTypeTriG, WebContent.contentTypeTriG) ;
+    }
+
+    @Test 
+    public void gsp_x_13() {
+        gsp_x_ct(urlDataset, WebContent.contentTypeTriGAlt1, WebContent.contentTypeTriG)
;
+    }
+
+    @Test 
+    public void gsp_x_14() {
+        gsp_x_ct(urlDataset, WebContent.defaultDatasetAcceptHeader, WebContent.contentTypeTriG)
;
+    }
+
+    @Test 
+    public void gsp_x_15() {
+        // Anything!
+        gsp_x_ct(urlDataset, WebContent.defaultRDFAcceptHeader, WebContent.contentTypeTriG)
;
+    }
+    
+    private void gsp_x_ct(String urldataset, String acceptheader, String contentTypeResponse)
{
+        HttpEntity e = datasetToHttpEntity(data) ;
+        HttpOp.execHttpPut(urlDataset, e);
+        TypedInputStream in = HttpOp.execHttpGet(urlDataset, acceptheader) ;
+        assertEqualsIgnoreCase(in.getContentType(), contentTypeResponse) ;
+        DatasetGraph dsg = DatasetGraphFactory.createMem() ;
+        StreamRDF dest = StreamRDFLib.dataset(dsg) ;
+        RDFDataMgr.parse(dest, in) ;
+    }
+
     @Test 
-    public void gsp_x_10()
+    public void gsp_x_20()
     {
         HttpEntity e = datasetToHttpEntity(data) ;
         try { 



Mime
View raw message