You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/05/21 15:09:28 UTC

svn commit: r1484793 [1/2] - in /jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki: mgt/ server/ servlets/

Author: andy
Date: Tue May 21 13:09:27 2013
New Revision: 1484793

URL: http://svn.apache.org/r1484793
Log:
JENA-427
Add a formally lifecycle of HTTP request - HttpAction carries around the state for the request.
Dataset level stats collecting as example of request lifecycle.

Removed:
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/WebRequest.java
Modified:
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionBackup.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpServletResponseTracker.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryDataset.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.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_REST_R.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_UberServlet.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionBackup.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionBackup.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionBackup.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/mgt/ActionBackup.java Tue May 21 13:09:27 2013
@@ -84,20 +84,22 @@ public class ActionBackup extends Servle
             return ;
         }
 
-        DatasetRef ref = DatasetRegistry.get().get(dataset) ;
+        
         long id = allocRequestId(request, response);
-        HttpAction action = new HttpAction(id, ref, request, response, false) ;
-        scheduleBackup(action, dataset) ;
+        HttpAction action = new HttpAction(id, request, response, false) ;
+        DatasetRef ref = DatasetRegistry.get().get(dataset) ;
+        scheduleBackup(action) ;
     }
 
     static final String BackupArea = "backups" ;  
     
-    private void scheduleBackup(final HttpAction action, String dataset)
+    private void scheduleBackup(final HttpAction action)
     {
-        final String ds = dataset.startsWith("/")? dataset : "/"+dataset ;
+        String dsName = action.desc.name ;
+        final String ds = dsName.startsWith("/")? dsName : "/"+dsName ;
         
         String timestamp = Utils.nowAsString("yyyy-MM-dd_HH-mm-ss") ;
-        final String filename = BackupArea + dataset + "_" + timestamp ;
+        final String filename = BackupArea + ds + "_" + timestamp ;
         FileOps.ensureDir(BackupArea) ;
         
         try {
@@ -122,7 +124,7 @@ public class ActionBackup extends Servle
                     return Boolean.TRUE ;
                 }} ;
             
-            log.info(format("[%d] Schedule backup %s to '%s'", action.id, dataset, filename)) ;                
+            log.info(format("[%d] Schedule backup %s to '%s'", action.id, ds, filename)) ;                
             backupService.submit(task) ;
         } 
         //catch (FusekiException ex)

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/server/DatasetRef.java Tue May 21 13:09:27 2013
@@ -48,6 +48,47 @@ public class DatasetRef
     /** Cumulative counter of writer transactions */
     public AtomicLong   totalWriteTxn           = new AtomicLong(0) ;
     
+    /** Count of requests received - any service */
+    public AtomicLong   countServiceRequests    = new AtomicLong(0) ;
+    /** Count of requests received that fail in some way */
+    public AtomicLong   countServiceRequestsBad = new AtomicLong(0) ;
+    /** Count of requests received that fail in some way */
+    public AtomicLong   countServiceRequestsOK  = new AtomicLong(0) ;
+
+    // SPARQL Query
+    
+    /** Count of SPARQL Queries successfully executed */
+    public AtomicLong   countQueryOK            = new AtomicLong(0) ;
+    /** Count of SPARQL Queries with syntax errors */
+    public AtomicLong   countQueryBadSyntax     = new AtomicLong(0) ;
+    /** Count of SPARQL Queries with timeout on execution */
+    public AtomicLong   countQueryTimeout       = new AtomicLong(0) ;
+    /** Count of SPARQL Queries with execution errors (not timeouts) */
+    public AtomicLong   countQueryBadExecution  = new AtomicLong(0) ;
+
+    // SPARQL Update
+
+    /** Count of SPARQL Update */
+    public AtomicLong   countUpdate             = new AtomicLong(0) ;
+    
+    // File upload
+    
+    /** Count of Uploads */
+    public AtomicLong   countUpload             = new AtomicLong(0) ;
+    
+    // SPARQL Graph Store Protocol:
+
+    /** Count of GSP GET */
+    public AtomicLong   countGET                = new AtomicLong(0) ;
+    /** Count of GSP POST */
+    public AtomicLong   countPOST               = new AtomicLong(0) ;
+    /** Count of GSP PUT */
+    public AtomicLong   countPUT                = new AtomicLong(0) ;
+    /** Count of GSP DELETE */
+    public AtomicLong   countDELETE             = new AtomicLong(0) ;
+    /** Count of GSP HEAD */
+    public AtomicLong   countHEAD               = new AtomicLong(0) ;
+    
     public void startTxn(ReadWrite mode)
     {
         switch(mode)

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java Tue May 21 13:09:27 2013
@@ -21,6 +21,9 @@ package org.apache.jena.fuseki.servlets;
 import static com.hp.hpl.jena.query.ReadWrite.READ ;
 import static com.hp.hpl.jena.query.ReadWrite.WRITE ;
 
+import java.util.HashMap ;
+import java.util.Map ;
+
 import javax.servlet.http.HttpServletRequest ;
 import javax.servlet.http.HttpServletResponse ;
 
@@ -40,16 +43,35 @@ import com.hp.hpl.jena.sparql.core.Trans
 public class HttpAction
 {
     public  final long id ;
+    public final boolean verbose ;
+    
+    
+    // Phase two items - set and valida after the datasetRef is known.  
     private DatasetGraph dsg ;                  // The data
-    private final Transactional transactional ;
-    private final boolean isTransactional;
-    private final DatasetRef desc ;
+    public DatasetRef desc ;
+    
+    private Transactional transactional ;
+    private boolean isTransactional;
     private DatasetGraph    activeDSG ;             // Set when inside begin/end.
     private ReadWrite       activeMode ;            // Set when inside begin/end.
     
-    public final HttpServletRequest request;
-    public final HttpServletResponse response ;
-    public final boolean verbose ;
+    private boolean startTimeIsSet = false ;
+    private boolean finishTimeIsSet = false ;
+
+    private long startTime = -2 ;
+    private long finishTime = -2 ;
+    
+    // Outcome.
+    int statusCode = -1 ;
+    String message = null ;
+    int contentLength = -1 ;
+    String contentType = null ;
+    
+    // Cleared to archive:
+    Map <String, String> headers = new HashMap<String, String>() ;
+    public HttpServletRequest request;
+    public HttpServletResponseTracker response ;
+
     
 //    // ---- Concurrency checking.
 //    private static Map<Lock, ConcurrencyPolicyMRSW> lockCounters = new HashMap<Lock, ConcurrencyPolicyMRSW>() ;
@@ -67,9 +89,16 @@ public class HttpAction
 //        }
 //    }
 
-    public HttpAction(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response, boolean verbose)
+    public HttpAction(long id, HttpServletRequest request, HttpServletResponse response, boolean verbose)
     {
         this.id = id ;
+        this.request = request ;
+        this.response = new HttpServletResponseTracker(this, response) ;
+        this.verbose = verbose ;
+    }
+
+    public void setDataset(DatasetRef desc)
+    {
         this.desc = desc ;
         this.dsg = desc.dataset ;
 
@@ -87,9 +116,6 @@ public class HttpAction
             isTransactional = false ;
             dsg = dsglock ;
         }
-        this.request = request ;
-        this.response = response ;
-        this.verbose = verbose ;
     }
     
     /**
@@ -161,18 +187,61 @@ public class HttpAction
         return desc ;
     }
     
-    // External, additional lock.
-    private void enter(DatasetGraph dsg, Lock lock, boolean readLock)
+    /** Reduce to a size that can be kept around for sometime */  
+    public void minimize()
     {
-        if ( lock == null && dsg == null )
-            return ;
-        if ( lock == null )
-            lock = dsg.getLock() ;
-        if ( lock == null )
-            return ;
-        lock.enterCriticalSection(readLock) ;
+        this.request = null ;
+        this.response = null ;
+    }
+
+    public void setStartTime() {
+        if ( startTimeIsSet ) 
+            Log.warn(this,  "Start time reset") ;
+        startTimeIsSet = true ;
+        this.startTime = System.nanoTime() ;
+    }
+
+    public void setFinishTime() {
+        if ( finishTimeIsSet ) 
+            Log.warn(this,  "Finish time reset") ;
+        finishTimeIsSet = true ;
+        this.finishTime = System.nanoTime() ;
     }
     
+
+//    public Map <String, String> getHeaders()    { return headers ; } 
+//    
+//    public HttpServletRequest getRequest()      { return request ; }
+//
+//    public HttpServletResponseTracker getResponse()    { return response ; }
+    
+
+    /** Return the recorded time taken in milliseconds. 
+     *  {@linkplain #setStartTime} and {@linkplain #setFinishTime}
+     *  must have been called.
+     */
+    public long getTime()
+    {
+        if ( ! startTimeIsSet ) 
+            Log.warn(this,  "Start time not set") ;
+        if ( ! finishTimeIsSet ) 
+            Log.warn(this,  "Finish time not set") ;
+        return (finishTime-startTime)/(1000*1000) ;
+    }
+
+    
+//    // External, additional lock.
+//    private void enter(DatasetGraph dsg, Lock lock, boolean readLock)
+//    {
+//        if ( lock == null && dsg == null )
+//            return ;
+//        if ( lock == null )
+//            lock = dsg.getLock() ;
+//        if ( lock == null )
+//            return ;
+//        lock.enterCriticalSection(readLock) ;
+//    }
+    
     private void leave(DatasetGraph dsg, Lock lock, boolean readLock)
     {
         if ( lock == null && dsg == null )

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpServletResponseTracker.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpServletResponseTracker.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpServletResponseTracker.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/HttpServletResponseTracker.java Tue May 21 13:09:27 2013
@@ -29,27 +29,27 @@ import org.apache.jena.atlas.logging.Log
 
 public class HttpServletResponseTracker extends HttpServletResponseWrapper
 {
-    private final WebRequest webRequest ;
+    private final HttpAction action ;
 
-    public HttpServletResponseTracker(WebRequest webRequest, HttpServletResponse response)
+    public HttpServletResponseTracker(HttpAction action, HttpServletResponse response)
     {
         super(response) ;
-        this.webRequest = webRequest ;
+        this.action = action ;
     }
 
     @Override
     public void sendError(int sc, String msg) throws IOException
     {
-        webRequest.statusCode = sc ;
-        webRequest.message = msg ;
+        action.statusCode = sc ;
+        action.message = msg ;
         super.sendError(sc, msg) ;
     }
 
     @Override
     public void sendError(int sc) throws IOException
     {
-        webRequest.statusCode = sc ;
-        webRequest.message = null ;
+        action.statusCode = sc ;
+        action.message = null ;
         super.sendError(sc) ;
     }
 
@@ -57,7 +57,7 @@ public class HttpServletResponseTracker 
     public void setHeader(String name, String value)
     {
         super.setHeader(name, value) ;
-        webRequest.headers.put(name, value) ;
+        action.headers.put(name, value) ;
     }
 
     @Override
@@ -69,8 +69,8 @@ public class HttpServletResponseTracker 
     @Override
     public void setStatus(int sc) 
     {
-        webRequest.statusCode = sc ;
-        webRequest.message = null ;
+        action.statusCode = sc ;
+        action.message = null ;
         super.setStatus(sc) ;
     }
 
@@ -78,22 +78,22 @@ public class HttpServletResponseTracker 
     @Deprecated
     public void setStatus(int sc, String sm)
     {
-        webRequest.statusCode = sc ;
-        webRequest.message = sm ;
+        action.statusCode = sc ;
+        action.message = sm ;
         super.setStatus(sc, sm) ;
     }
 
     @Override
     public void setContentLength(int len)
     {
-        webRequest.contentLength = len ;
+        action.contentLength = len ;
         super.setContentLength(len) ;
     }
 
     @Override
     public void setContentType(String type)
     {
-        webRequest.contentType = type ;
+        action.contentType = type ;
         super.setContentType(type) ;
     }
       

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java Tue May 21 13:09:27 2013
@@ -23,7 +23,6 @@ import static java.lang.String.format ;
 import java.io.IOException ;
 
 import javax.servlet.ServletOutputStream ;
-import javax.servlet.http.HttpServletRequest ;
 
 import org.apache.jena.atlas.web.MediaType ;
 import org.apache.jena.atlas.web.TypedOutputStream ;
@@ -49,13 +48,13 @@ public class REST_Quads extends SPARQL_R
     { super(verbose) ; }
     
     @Override
-    protected void validate(HttpServletRequest request)
+    protected void validate(HttpAction action)
     {
         // already checked?
     }
     
     @Override
-    protected void doGet(HttpActionREST action)
+    protected void doGet(HttpAction action)
     {
         MediaType mediaType = HttpAction.contentNegotationQuads(action) ;
         ServletOutputStream output ;
@@ -82,7 +81,7 @@ public class REST_Quads extends SPARQL_R
     }
     
     @Override
-    protected void doOptions(HttpActionREST action)
+    protected void doOptions(HttpAction action)
     {
         action.response.setHeader(HttpNames.hAllow, "GET, HEAD, OPTIONS") ;
         action.response.setHeader(HttpNames.hContentLengh, "0") ;
@@ -90,7 +89,7 @@ public class REST_Quads extends SPARQL_R
     }
 
     @Override
-    protected void doHead(HttpActionREST action)
+    protected void doHead(HttpAction action)
     {
         action.beginRead() ;
         try { 
@@ -101,7 +100,7 @@ public class REST_Quads extends SPARQL_R
 
     static int counter = 0 ;
     @Override
-    protected void doPost(HttpActionREST action)
+    protected void doPost(HttpAction action)
     { 
         if ( ! action.getDatasetRef().allowDatasetUpdate )
             errorMethodNotAllowed("POST") ;
@@ -137,7 +136,7 @@ public class REST_Quads extends SPARQL_R
             errorBadRequest("Not a triples or quads format: "+mediaType) ;
     }
         
-    protected void doPostQuads(HttpActionREST action, Lang lang)
+    protected void doPostQuads(HttpAction action, Lang lang)
     {
         action.beginWrite() ;
         try {
@@ -154,7 +153,7 @@ public class REST_Quads extends SPARQL_R
     
   
     // POST triples to dataset -- send to default graph.  
-    protected void doPostTriples(HttpActionREST action, Lang lang) 
+    protected void doPostTriples(HttpAction action, Lang lang) 
     {
         action.beginWrite() ;
         try {
@@ -172,7 +171,7 @@ public class REST_Quads extends SPARQL_R
         finally { action.endWrite() ; }
     }
     
-    protected void doPostTriplesGSP(HttpActionREST action, Lang lang) 
+    protected void doPostTriplesGSP(HttpAction action, Lang lang) 
     {
         action.beginWrite() ;
         try {
@@ -197,15 +196,15 @@ public class REST_Quads extends SPARQL_R
     }
 
     @Override
-    protected void doDelete(HttpActionREST action)
+    protected void doDelete(HttpAction action)
     { errorMethodNotAllowed("DELETE") ; }
 
     @Override
-    protected void doPut(HttpActionREST action)
+    protected void doPut(HttpAction action)
     { errorMethodNotAllowed("PUT") ; }
 
     @Override
-    protected void doPatch(HttpActionREST action)
+    protected void doPatch(HttpAction action)
     { errorMethodNotAllowed("PATCH") ; }
 }
 

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java Tue May 21 13:09:27 2013
@@ -19,7 +19,11 @@
 package org.apache.jena.fuseki.servlets;
 
 import static java.lang.String.format ;
-import static org.apache.jena.fuseki.servlets.ServletBase.* ;
+import static org.apache.jena.atlas.lib.Lib.equal ;
+import static org.apache.jena.fuseki.servlets.ServletBase.errorBadRequest ;
+import static org.apache.jena.fuseki.servlets.ServletBase.errorOccurred ;
+import static org.apache.jena.fuseki.servlets.ServletBase.log ;
+
 import java.io.IOException ;
 import java.util.HashMap ;
 import java.util.Map ;
@@ -35,10 +39,8 @@ import org.apache.jena.atlas.web.MediaTy
 import org.apache.jena.fuseki.DEF ;
 import org.apache.jena.fuseki.FusekiException ;
 import org.apache.jena.fuseki.conneg.ConNeg ;
-import org.apache.jena.fuseki.servlets.SPARQL_Query.HttpActionQuery ;
 import org.apache.jena.riot.WebContent ;
 import org.apache.jena.web.HttpSC ;
-import static org.apache.jena.atlas.lib.Lib.equal ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
@@ -79,12 +81,12 @@ public class ResponseResultSet
     static AcceptList prefContentTypeResultSet     = DEF.rsOffer ; 
     static AcceptList prefContentTypeRDF           = DEF.rdfOffer ;
 
-    public static void doResponseResultSet(HttpActionQuery action, Boolean booleanResult)
+    public static void doResponseResultSet(HttpAction action, Boolean booleanResult)
     {
         doResponseResultSet$(action, null, booleanResult, null) ;
     }
 
-    public static void doResponseResultSet(HttpActionQuery action, ResultSet resultSet, Prologue qPrologue)
+    public static void doResponseResultSet(HttpAction action, ResultSet resultSet, Prologue qPrologue)
     {
         doResponseResultSet$(action, resultSet, null, qPrologue) ;
     }
@@ -92,7 +94,7 @@ public class ResponseResultSet
     // If we refactor the conneg into a single function, we can split boolean and result set handling. 
     
     // One or the other argument must be null
-    private static void doResponseResultSet$(HttpActionQuery action,
+    private static void doResponseResultSet$(HttpAction action,
                                              final ResultSet resultSet, final Boolean booleanResult, 
                                              final Prologue qPrologue) 
     {

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Protocol.java Tue May 21 13:09:27 2013
@@ -26,13 +26,10 @@ import java.util.Collections ;
 import java.util.List ;
 
 import javax.servlet.http.HttpServletRequest ;
-import javax.servlet.http.HttpServletResponse ;
 
 import org.apache.jena.atlas.iterator.Filter ;
 import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.fuseki.server.DatasetRef ;
-import org.apache.jena.fuseki.servlets.SPARQL_Query.HttpActionQuery ;
 
 import com.hp.hpl.jena.query.Query ;
 import com.hp.hpl.jena.query.QueryParseException ;
@@ -42,14 +39,6 @@ import com.hp.hpl.jena.sparql.core.Datas
  */
 public  abstract class SPARQL_Protocol extends SPARQL_ServletBase
 {
-    protected static class HttpActionProtocol extends HttpAction {
-
-        public HttpActionProtocol(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response, boolean verbose)
-        {
-            super(id, desc, request, response, verbose) ;
-        }
-    }
-    
     protected SPARQL_Protocol(boolean verbose_debug)
     {
         super(verbose_debug) ;
@@ -64,7 +53,7 @@ public  abstract class SPARQL_Protocol e
         return null ;
     }
     
-    protected static DatasetDescription getDatasetDescription(HttpActionQuery action)
+    protected static DatasetDescription getDatasetDescription(HttpAction action)
     {
         List<String> graphURLs = toStrList(action.request.getParameterValues(paramDefaultGraphURI)) ;
         List<String> namedGraphs = toStrList(action.request.getParameterValues(paramNamedGraphURI)) ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Query.java Tue May 21 13:09:27 2013
@@ -44,30 +44,17 @@ import org.apache.jena.atlas.web.MediaTy
 import org.apache.jena.fuseki.FusekiException ;
 import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.fuseki.HttpNames ;
-import org.apache.jena.fuseki.server.DatasetRef ;
 import org.apache.jena.riot.WebContent ;
 import org.apache.jena.riot.web.HttpOp ;
 import org.apache.jena.web.HttpSC ;
 
 import com.hp.hpl.jena.query.* ;
 import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.sparql.core.DatasetDescription ;
 import com.hp.hpl.jena.sparql.core.Prologue ;
 import com.hp.hpl.jena.sparql.resultset.SPARQLResult ;
 
 public abstract class SPARQL_Query extends SPARQL_Protocol
 {
-    protected class HttpActionQuery extends HttpActionProtocol {
-        
-        // Used if the protocol or query has a dataset description.
-        DatasetDescription datasetDesc = null ;
-        
-        public HttpActionQuery(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response, boolean verbose)
-        {
-            super(id, desc, request, response, verbose) ;
-        }
-    }
-    
     public SPARQL_Query(boolean verbose)
     { super(verbose) ; }
 
@@ -97,17 +84,16 @@ public abstract class SPARQL_Query exten
     }
     
     @Override
-    protected final void perform(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response)
+    protected final void perform(HttpAction action)
     {
-        HttpActionQuery action = new HttpActionQuery(id, desc, request, response, verbose_debug) ;
         // GET
-        if ( request.getMethod().equals(HttpNames.METHOD_GET) )
+        if ( action.request.getMethod().equals(HttpNames.METHOD_GET) )
         {
             executeWithParameter(action) ;
             return ;
         }
 
-        MediaType ct = FusekiLib.contentType(request) ;
+        MediaType ct = FusekiLib.contentType(action.request) ;
         String incoming = ct.getContentType() ;
         
         // POST application/sparql-query
@@ -138,27 +124,33 @@ public abstract class SPARQL_Query exten
                                                              paramForceAccept,
                                                              paramTimeout) ;
     
+    @Override
+    protected void startRequest(HttpAction action)
+    {
+    }
+    
     /** Called to validate arguments */
     @Override
-    protected void validate(HttpServletRequest request)
+    protected void validate(HttpAction action)
     {
-        String method = request.getMethod().toUpperCase(Locale.ENGLISH) ;
+        String method = action.request.getMethod().toUpperCase(Locale.ENGLISH) ;
         
         if ( ! HttpNames.METHOD_POST.equals(method) && ! HttpNames.METHOD_GET.equals(method) )
             errorMethodNotAllowed("Not a GET or POST request") ;
             
-        if ( HttpNames.METHOD_GET.equals(method) && request.getQueryString() == null )
+        if ( HttpNames.METHOD_GET.equals(method) && action.request.getQueryString() == null )
         {
-            warning("Service Description / SPARQL Query / "+request.getRequestURI()) ;
-            errorNotFound("Service Description: "+request.getRequestURI()) ;
+            warning("Service Description / SPARQL Query / "+action.request.getRequestURI()) ;
+            errorNotFound("Service Description: "+action.request.getRequestURI()) ;
         }
             
         // Use of the dataset describing parameters is check later.
-        validate(request, allParams) ;
-        validateRequest(request) ;
+        validate(action.request, allParams) ;
+        validateRequest(action) ;
     }
     
-    protected abstract void validateRequest(HttpServletRequest request) ;
+    /** Validate the request after checking HTTP method and HTTP Parameters */ 
+    protected abstract void validateRequest(HttpAction action) ;
     
     /** Helper for validating request */
     protected void validate(HttpServletRequest request, Collection<String> params)
@@ -209,13 +201,13 @@ public abstract class SPARQL_Query exten
         }
     }
 
-    private void executeWithParameter(HttpActionQuery action)
+    private void executeWithParameter(HttpAction action)
     {
         String queryString = action.request.getParameter(paramQuery) ;
         execute(queryString, action) ;
     }
 
-    private void executeBody(HttpActionQuery action)
+    private void executeBody(HttpAction action)
     {
         String queryString = null ;
         try { 
@@ -226,7 +218,7 @@ public abstract class SPARQL_Query exten
         execute(queryString, action) ;
     }
 
-    private void execute(String queryString, HttpActionQuery action)
+    private void execute(String queryString, HttpAction action)
     {
         String queryStringLog = formatForLog(queryString) ;
         if ( super.verbose_debug || action.verbose )
@@ -260,14 +252,14 @@ public abstract class SPARQL_Query exten
     }
 
     /** Check the query - if unacceptable, throw ActionErrorException or call super.error */
-    protected abstract void validateQuery(HttpActionQuery action, Query query) ;
+    protected abstract void validateQuery(HttpAction action, Query query) ;
 
     protected QueryExecution createQueryExecution(Query query, Dataset dataset)
     {
         return QueryExecutionFactory.create(query, dataset) ;
     }
 
-    protected SPARQLResult executeQuery(HttpActionQuery action, QueryExecution qExec, Query query, String queryStringLog)
+    protected SPARQLResult executeQuery(HttpAction action, QueryExecution qExec, Query query, String queryStringLog)
     {
         setAnyTimeouts(qExec, action);
 
@@ -321,7 +313,7 @@ public abstract class SPARQL_Query exten
         return null ;
     }
 
-    private void setAnyTimeouts(QueryExecution qexec, HttpActionQuery action) {
+    private void setAnyTimeouts(QueryExecution qexec, HttpAction action) {
         if (!(action.getDatasetRef().allowTimeoutOverride))
             return;
 
@@ -347,9 +339,9 @@ public abstract class SPARQL_Query exten
             qexec.setTimeout(desiredTimeout);
     }
 
-    protected abstract Dataset decideDataset(HttpActionQuery action, Query query, String queryStringLog) ;
+    protected abstract Dataset decideDataset(HttpAction action, Query query, String queryStringLog) ;
 
-    protected void sendResults(HttpActionQuery action, SPARQLResult result, Prologue qPrologue)
+    protected void sendResults(HttpAction action, SPARQLResult result, Prologue qPrologue)
     {
         if ( result.isResultSet() )
             ResponseResultSet.doResponseResultSet(action, result.getResultSet(), qPrologue) ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryDataset.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryDataset.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryDataset.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryDataset.java Tue May 21 13:09:27 2013
@@ -18,8 +18,6 @@
 
 package org.apache.jena.fuseki.servlets;
 
-import javax.servlet.http.HttpServletRequest ;
-
 import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.query.DatasetFactory ;
 import com.hp.hpl.jena.query.Query ;
@@ -36,15 +34,15 @@ public class SPARQL_QueryDataset extends
     { this(false) ; }
     
     @Override
-    protected void validateRequest(HttpServletRequest request) 
+    protected void validateRequest(HttpAction action) 
     { }
 
     @Override
-    protected void validateQuery(HttpActionQuery action, Query query) 
+    protected void validateQuery(HttpAction action, Query query) 
     { }
    
     @Override
-    protected Dataset decideDataset(HttpActionQuery action, Query query, String queryStringLog) 
+    protected Dataset decideDataset(HttpAction action, Query query, String queryStringLog) 
     { 
         DatasetGraph dsg = action.getActiveDSG() ;
         

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_QueryGeneral.java Tue May 21 13:09:27 2013
@@ -22,8 +22,6 @@ import static java.lang.String.format ;
 
 import java.util.List ;
 
-import javax.servlet.http.HttpServletRequest ;
-
 import org.apache.jena.atlas.lib.InternalErrorException ;
 import org.apache.jena.fuseki.migrate.GraphLoadUtils ;
 import org.apache.jena.riot.RiotException ;
@@ -48,21 +46,19 @@ public class SPARQL_QueryGeneral extends
     { this(false) ; }
 
     @Override
-    protected void validateRequest(HttpServletRequest request) {}
+    protected void validateRequest(HttpAction action) {}
 
     @Override
-    protected void validateQuery(HttpActionQuery action, Query query) {}
+    protected void validateQuery(HttpAction action, Query query) {}
     
     @Override
     protected String mapRequestToDataset(String uri)
     { return null ; }
     
     @Override
-    protected Dataset decideDataset(HttpActionQuery action, Query query, String queryStringLog) 
+    protected Dataset decideDataset(HttpAction action, Query query, String queryStringLog) 
     {
-        action.datasetDesc = getDatasetDescription(action) ;
-        // To the context.
-        DatasetDescription datasetDesc = action.datasetDesc ;
+        DatasetDescription datasetDesc = getDatasetDescription(action) ;
         if ( datasetDesc == null )
             datasetDesc = getDatasetDescription(query) ;
         if ( datasetDesc == null )
@@ -75,7 +71,7 @@ public class SPARQL_QueryGeneral extends
      * Construct a Dataset based on a dataset description.
      */
     
-    protected static Dataset datasetFromDescription(HttpActionQuery action, DatasetDescription datasetDesc)
+    protected static Dataset datasetFromDescription(HttpAction action, DatasetDescription datasetDesc)
     {
         try {
             if ( datasetDesc == null )

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=1484793&r1=1484792&r2=1484793&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 Tue May 21 13:09:27 2013
@@ -19,7 +19,15 @@
 package org.apache.jena.fuseki.servlets;
 
 import static java.lang.String.format ;
-import static org.apache.jena.fuseki.HttpNames.* ;
+import static org.apache.jena.fuseki.HttpNames.HEADER_LASTMOD ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_DELETE ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_GET ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_HEAD ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_OPTIONS ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_PATCH ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_POST ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_PUT ;
+import static org.apache.jena.fuseki.HttpNames.METHOD_TRACE ;
 
 import java.io.ByteArrayInputStream ;
 import java.io.IOException ;
@@ -34,7 +42,6 @@ import javax.servlet.http.HttpServletRes
 import org.apache.jena.atlas.web.ContentType ;
 import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.fuseki.HttpNames ;
-import org.apache.jena.fuseki.server.DatasetRef ;
 import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RiotException ;
 import org.apache.jena.riot.RiotReader ;
@@ -59,41 +66,45 @@ public abstract class SPARQL_REST extend
     
     protected static ErrorHandler errorHandler = ErrorHandlerFactory.errorHandlerStd(log) ;
 
-    protected static class HttpActionREST extends HttpAction
+    protected final static Target determineTarget(HttpAction action) 
     {
-        HttpActionREST(long id, DatasetRef desc, String absUri, HttpServletRequest request, HttpServletResponse response, boolean verbose)
-        {
-            super(id, desc, request, response, verbose) ;
-            Node gn = NodeFactory.createURI(absUri) ;
-            _target = Target.createNamed(desc.dataset, absUri, gn) ; 
-        }
+        // Delayed until inside a transaction.
+        if ( action.getActiveDSG() == null )
+                errorOccurred("Internal error : No action graph (not in a transaction?)") ;
         
-        private Target _target = null ; 
-        protected HttpActionREST(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response, boolean verbose)
-        {
-            super(id, desc, request, response, verbose) ;
-        }
-
-        protected final boolean hasTarget()
-        {
-            return true ;
-//                request.getParameter(HttpNames.paramGraphDefault) == null &&
-//                request.getParameter(HttpNames.paramGraph) == null ;
-        }
+        boolean dftGraph = getOneOnly(action.request, HttpNames.paramGraphDefault) != null ;
+        String uri = getOneOnly(action.request, HttpNames.paramGraph) ;
         
-        protected final Target getTarget() 
+        if ( !dftGraph && uri == null )
         {
-            // Delayed until inside a transaction.
-            if ( _target == null )
-            {
-                if ( super.getActiveDSG() == null )
-                    errorOccurred("Internal error : No action graph (not in a transaction?)") ;
-                _target = targetGraph(request, super.getDatasetRef(), super.getActiveDSG() ) ;
-            }
-            return _target ;
+            // Direct naming or error.
+            uri = action.request.getRequestURL().toString() ;
+            if ( action.request.getRequestURI().equals(action.getDatasetRef().name) )
+                // No name 
+                errorBadRequest("Neither default graph nor named graph specified; no direct name") ;
         }
+        
+        if ( dftGraph )
+            return Target.createDefault(action.getActiveDSG()) ;
+        
+        // Named graph
+        if ( uri.equals(HttpNames.valueDefault ) )
+            // But "named" default
+            return Target.createDefault(action.getActiveDSG()) ;
+        
+        // Strictly, a bit naughty on the URI resolution.  But more sensible. 
+        // Base is dataset.
+        String base = action.request.getRequestURL().toString() ; //wholeRequestURL(request) ;
+        // Make sure it ends in "/", ie. dataset as container.
+        if ( action.request.getQueryString() != null && ! base.endsWith("/") )
+            base = base + "/" ;
+        
+        String absUri = IRIResolver.resolveString(uri, base) ;
+        Node gn = NodeFactory.createURI(absUri) ;
+        return Target.createNamed(action.getActiveDSG(), absUri, gn) ;
     }
     
+
     // struct for target
     protected static final class Target
     {
@@ -185,14 +196,12 @@ public abstract class SPARQL_REST extend
     }
     
     @Override
-    protected void perform(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response)
+    protected void perform(HttpAction action)
     {
-        validate(request) ;
-        HttpActionREST action = new HttpActionREST(id, desc, request, response, verbose_debug) ;
         dispatch(action) ;
     }
 
-    private void dispatch(HttpActionREST action)
+    private void dispatch(HttpAction action)
     {
         HttpServletRequest req = action.request ;
         HttpServletResponse resp = action.response ;
@@ -222,20 +231,21 @@ public abstract class SPARQL_REST extend
             errorNotImplemented("Unknown method: "+method) ;
     }
         
-    protected abstract void doGet(HttpActionREST action) ;
-    protected abstract void doHead(HttpActionREST action) ;
-    protected abstract void doPost(HttpActionREST action) ;
-    protected abstract void doPatch(HttpActionREST action) ;
-    protected abstract void doDelete(HttpActionREST action) ;
-    protected abstract void doPut(HttpActionREST action) ;
-    protected abstract void doOptions(HttpActionREST action) ;
-
-    protected static void deleteGraph(HttpActionREST action)
-    {
-        if ( action.getTarget().isDefault )
-            action.getTarget().graph().clear() ;
+    protected abstract void doGet(HttpAction action) ;
+    protected abstract void doHead(HttpAction action) ;
+    protected abstract void doPost(HttpAction action) ;
+    protected abstract void doPatch(HttpAction action) ;
+    protected abstract void doDelete(HttpAction action) ;
+    protected abstract void doPut(HttpAction action) ;
+    protected abstract void doOptions(HttpAction action) ;
+
+    protected static void deleteGraph(HttpAction action)
+    {
+        Target target = determineTarget(action) ;
+        if ( target.isDefault )
+            target.graph().clear() ;
         else
-            action.getActiveDSG().removeGraph(action.getTarget().graphName) ;
+            action.getActiveDSG().removeGraph(target.graphName) ;
     }
 
     protected static void clearGraph(Target target)
@@ -247,11 +257,11 @@ public abstract class SPARQL_REST extend
         }
     }
 
-    protected static void addDataInto(Graph data, HttpActionREST action)
+    protected static void addDataInto(Graph data, HttpAction action)
     {   
         try
         {
-            Target dest = action.getTarget() ;
+            Target dest = determineTarget(action) ;
             FusekiLib.addDataInto(data, dest.dsg, dest.graphName) ;
             
 //            Graph g = dest.graph() ;
@@ -275,7 +285,7 @@ public abstract class SPARQL_REST extend
         }
     }
     
-    protected static DatasetGraph parseBody(HttpActionREST action)
+    protected static DatasetGraph parseBody(HttpAction action)
     {
         String contentTypeHeader = action.request.getContentType() ;
         
@@ -292,7 +302,7 @@ public abstract class SPARQL_REST extend
         {
 //            //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) ;
+            Graph graphTmp = SPARQL_Upload.upload(action, base) ;
             return DatasetGraphFactory.create(graphTmp) ;
         }
         
@@ -347,7 +357,7 @@ public abstract class SPARQL_REST extend
         } catch (IOException ex) { errorOccurred(ex) ; return null ; }
     }
 
-    private static DatasetGraph parse(HttpActionREST action, Lang lang, String base, InputStream input)
+    private static DatasetGraph parse(HttpAction action, Lang lang, String base, InputStream input)
     {
         Graph graphTmp = GraphFactory.createGraphMem() ;
         
@@ -361,8 +371,9 @@ public abstract class SPARQL_REST extend
     }
     
     @Override
-    protected void validate(HttpServletRequest request)
+    protected void validate(HttpAction action)
     {
+        HttpServletRequest request = action.request ;
         // Direct naming.
         if ( request.getQueryString() == null )
             //errorBadRequest("No query string") ;
@@ -397,40 +408,6 @@ public abstract class SPARQL_REST extend
         }
     }
 
-    protected static Target targetGraph(HttpServletRequest request, DatasetRef desc, DatasetGraph dsg)
-    {
-        boolean dftGraph = getOneOnly(request, HttpNames.paramGraphDefault) != null ;
-        String uri = getOneOnly(request, HttpNames.paramGraph) ;
-        
-        if ( !dftGraph && uri == null )
-        {
-            // Direct naming or error.
-            uri = request.getRequestURL().toString() ;
-            if ( request.getRequestURI().equals(desc.name) )
-                // No name 
-                errorBadRequest("Neither default graph nor named graph specified; no direct name") ;
-        }
-        
-        if ( dftGraph )
-            return Target.createDefault(dsg) ;
-        
-        // Named graph
-        if ( uri.equals(HttpNames.valueDefault ) )
-            // But "named" default
-            return Target.createDefault(dsg) ;
-        
-        // Strictly, a bit naughty on the URI resolution.  But more sensible. 
-        // Base is dataset.
-        String base = request.getRequestURL().toString() ; //wholeRequestURL(request) ;
-        // Make sure it ends in "/", ie. dataset as container.
-        if ( request.getQueryString() != null && ! base.endsWith("/") )
-            base = base + "/" ;
-        
-        String absUri = IRIResolver.resolveString(uri, base) ;
-        Node gn = NodeFactory.createURI(absUri) ;
-        return Target.createNamed(dsg, absUri, gn) ;
-    }
-    
     protected static String getOneOnly(HttpServletRequest request, String name)
     {
         String[] values = request.getParameterValues(name) ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_R.java Tue May 21 13:09:27 2013
@@ -21,14 +21,12 @@ package org.apache.jena.fuseki.servlets;
 import static java.lang.String.format ;
 
 import java.io.IOException ;
-import java.util.Iterator ;
 
 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.fuseki.server.DatasetRegistry ;
 import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.riot.WebContent ;
@@ -48,43 +46,10 @@ public class SPARQL_REST_R extends SPARQ
     
     
     @Override
-    protected String mapRequestToDataset(String uri) 
-    {
-        if ( uri == null )
-            return null ;
-        
-        // Mapping a request for GSP needs to find the "best"
-        // (longest matching) dataset URI.
-        // This covers local using the URI as a direct name for
-        // a graph, not just using the indirect ?graph= or ?default 
-        // forms.
-        // Service matching, which is a matter of removing the service component,
-        // would only work for indirect. 
-
-        String ds = null ;
-        Iterator<String> iter = DatasetRegistry.get().keys() ;
-        while(iter.hasNext())
-        {
-            String ds2 = iter.next();
-            if ( ! uri.startsWith(ds2) )
-                continue ;
-
-            if ( ds == null )
-            {
-                ds = ds2 ;
-                continue ; 
-            }
-            if ( ds.length() < ds2.length() )
-            {
-                ds = ds2 ;
-                continue ;
-            }
-        }
-        return ds ;
-    }
+    protected String mapRequestToDataset(String uri) { return mapRequestToDatasetLongest$(uri) ; } 
 
     @Override
-    protected void doGet(HttpActionREST action)
+    protected void doGet(HttpAction action)
     {
         // Assume success - do the set up before grabbing the lock.
         // Sets content type.
@@ -102,17 +67,19 @@ public class SPARQL_REST_R extends SPARQ
                                   action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName())) ;
 
         action.beginRead() ;
+
         try {
+            Target target = determineTarget(action) ;
             if ( log.isDebugEnabled() )
-                log.debug("GET->"+action.getTarget()) ;
-            boolean exists = action.getTarget().exists() ;
+                log.debug("GET->"+target) ;
+            boolean exists = target.exists() ;
             if ( ! exists )
-                errorNotFound("No such graph: <"+action.getTarget().name+">") ;
+                errorNotFound("No such graph: <"+target.name+">") ;
             // If we want to set the Content-Length, we need to buffer.
             //response.setContentLength(??) ;
             String ct = WebContent.mapLangToContentType(lang) ;
             action.response.setContentType(ct) ;
-            Graph g = action.getTarget().graph() ;
+            Graph g = target.graph() ;
             Model model = ModelFactory.createModelForGraph(g) ;
             RDFDataMgr.write(out, model, lang) ;
             success(action) ;
@@ -120,7 +87,7 @@ public class SPARQL_REST_R extends SPARQ
     }
     
     @Override
-    protected void doOptions(HttpActionREST action)
+    protected void doOptions(HttpAction action)
     {
         action.response.setHeader(HttpNames.hAllow, "GET,HEAD,OPTIONS") ;
         action.response.setHeader(HttpNames.hContentLengh, "0") ;
@@ -128,13 +95,14 @@ public class SPARQL_REST_R extends SPARQ
     }
 
     @Override
-    protected void doHead(HttpActionREST action)
+    protected void doHead(HttpAction action)
     {
         action.beginRead() ;
         try { 
+            Target target = determineTarget(action) ;
             if ( log.isDebugEnabled() )
-                log.debug("HEAD->"+action.getTarget()) ;
-            if ( ! action.getTarget().exists() )
+                log.debug("HEAD->"+target) ;
+            if ( ! target.exists() )
             {
                 successNotFound(action) ;
                 return ;
@@ -145,18 +113,18 @@ public class SPARQL_REST_R extends SPARQ
     }
 
     @Override
-    protected void doPost(HttpActionREST action)
+    protected void doPost(HttpAction action)
     { errorMethodNotAllowed("POST") ; }
 
     @Override
-    protected void doDelete(HttpActionREST action)
+    protected void doDelete(HttpAction action)
     { errorMethodNotAllowed("DELETE") ; }
 
     @Override
-    protected void doPut(HttpActionREST action)
+    protected void doPut(HttpAction action)
     { errorMethodNotAllowed("PUT") ; }
 
     @Override
-    protected void doPatch(HttpActionREST action)
+    protected void doPatch(HttpAction action)
     { errorMethodNotAllowed("PATCH") ; }
 }

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST_RW.java Tue May 21 13:09:27 2013
@@ -32,7 +32,7 @@ public class SPARQL_REST_RW extends SPAR
     { this(false) ; }
 
     @Override
-    protected void doOptions(HttpActionREST action)
+    protected void doOptions(HttpAction action)
     {
         action.response.setHeader(HttpNames.hAllow, "GET,HEAD,OPTIONS,PUT,DELETE,POST");
         action.response.setHeader(HttpNames.hContentLengh, "0") ;
@@ -40,18 +40,19 @@ public class SPARQL_REST_RW extends SPAR
     }
     
     @Override
-    protected void doDelete(HttpActionREST action)
+    protected void doDelete(HttpAction action)
     {
         action.beginWrite() ;
         try {
+            Target target = determineTarget(action) ;
             if ( log.isDebugEnabled() )
-                log.debug("DELETE->"+action.getTarget()) ;
-            boolean existedBefore = action.getTarget().exists() ; 
+                log.debug("DELETE->"+target) ;
+            boolean existedBefore = target.exists() ; 
             if ( ! existedBefore)
             {
                 // commit, not abort, because locking "transactions" don't support abort. 
                 action.commit() ;
-                errorNotFound("No such graph: "+action.getTarget().name) ;
+                errorNotFound("No such graph: "+target.name) ;
             }
             deleteGraph(action) ;
             action.commit() ;
@@ -61,17 +62,18 @@ public class SPARQL_REST_RW extends SPAR
     }
 
     @Override
-    protected void doPut(HttpActionREST action)
+    protected void doPut(HttpAction action)
     {
         DatasetGraph body = parseBody(action) ;
         action.beginWrite() ;
         boolean existedBefore = false ;
         try {
+            Target target = determineTarget(action) ;
             if ( log.isDebugEnabled() )
-                log.debug("PUT->"+action.getTarget()) ;
-            existedBefore = action.getTarget().exists() ; 
+                log.debug("PUT->"+target) ;
+            existedBefore = target.exists() ; 
             if ( existedBefore )
-                clearGraph(action.getTarget()) ;
+                clearGraph(target) ;
             addDataInto(body.getDefaultGraph(), action) ;
             action.commit() ;
         } finally { action.endWrite() ; }
@@ -83,15 +85,16 @@ public class SPARQL_REST_RW extends SPAR
     }
 
     @Override
-    protected void doPost(HttpActionREST action)
+    protected void doPost(HttpAction action)
     {
         DatasetGraph body = parseBody(action) ;
         action.beginWrite() ;
         boolean existedBefore ; 
         try {
+            Target target = determineTarget(action) ;
             if ( log.isDebugEnabled() )
-                log.debug("POST->"+action.getTarget()) ;
-            existedBefore = action.getTarget().exists() ; 
+                log.debug("POST->"+target) ;
+            existedBefore = target.exists() ; 
             addDataInto(body.getDefaultGraph(), action) ;
             action.commit() ;
         } finally { action.endWrite() ; }

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_ServletBase.java Tue May 21 13:09:27 2013
@@ -22,7 +22,9 @@ import static java.lang.String.format ;
 
 import java.io.IOException ;
 import java.util.Enumeration ;
+import java.util.Iterator ;
 import java.util.Map ;
+import java.util.concurrent.atomic.AtomicLong ;
 
 import javax.servlet.ServletException ;
 import javax.servlet.http.HttpServletRequest ;
@@ -58,20 +60,19 @@ public abstract class SPARQL_ServletBase
             long id = allocRequestId(request, response);
             
             // Lifecycle
-            WebRequest wRequest = allocWebAction(id, request, response) ;
+            HttpAction action = allocHttpAction(id, request, response) ;
             // then add to doCommonWorker
             // work with HttpServletResponseTracker
             
-            printRequest(wRequest) ;
-            wRequest.setStartTime() ;
+            printRequest(action) ;
+            action.setStartTime() ;
             
-            response = wRequest.getResponse() ;
+            response = action.response ;
             initResponse(request, response) ;
             Context cxt = ARQ.getContext() ;
     
             try {
-                validate(request) ;
-                doCommonWorker(id, request, response) ;
+                execCommonWorker(action) ;
             } catch (QueryCancelledException ex) {
                 // Also need the per query info ...
                 String message = String.format("The query timed out (restricted to %s ms)", cxt.get(ARQ.queryTimeout));
@@ -92,44 +93,98 @@ public abstract class SPARQL_ServletBase
                 responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()) ;
             }
     
-            wRequest.setFinishTime() ;
-            printResponse(wRequest) ;
+            action.setFinishTime() ;
+            printResponse(action) ;
+            archiveHttpAction(action) ;
         } catch (Throwable th) {
             log.error("Internal error", th) ;
         }
     }
 
+
+    // ---- Operation lifecycle
+
     /** Return a fresh WebAction for this request */
-    protected WebRequest allocWebAction(long id, HttpServletRequest request, HttpServletResponse response) {
-        return new WebRequest(id, request, response) ;
+    protected HttpAction allocHttpAction(long id, HttpServletRequest request, HttpServletResponse response) {
+        return new HttpAction(id, request, response, verbose_debug) ;
     }
 
-    protected abstract void validate(HttpServletRequest request) ;
+//XXX     protected abstract void startRequest(HttpAction action) ;
+    protected void startRequest(HttpAction action) {}
+
+    protected abstract void validate(HttpAction action) ;
+    protected abstract void perform(HttpAction action) ;
     
-    protected void doCommonWorker(long id, HttpServletRequest request, HttpServletResponse response)
+//XXX     protected abstract void finishRequest(HttpAction action) ;
+    protected void finishRequest(HttpAction action) {}
+
+    private void archiveHttpAction(HttpAction action)
+    {
+        action.minimize() ;
+    }
+
+    private void execCommonWorker(HttpAction action)
     {
         DatasetRef desc = null ;
-        String uri = request.getRequestURI() ;
+        String uri = action.request.getRequestURI() ;
 
         uri = mapRequestToDataset(uri) ;
 
-        if ( uri != null )
-        {
+        if ( uri != null ) {
             desc = DatasetRegistry.get().get(uri) ;
-            if ( desc == null )
-            {
+            if ( desc == null ) {
                 errorNotFound("No dataset for URI: "+uri) ;
                 return ;
             }
-            //cxt = desc.dataset.getContext() ;
-        }
-        else {
+        } else {
             desc = new DatasetRef();
             desc.dataset = dummyDSG;
         }
-        perform(id, desc, request, response) ;
+        action.setDataset(desc) ;
+        executeAction(action) ;
     }
+        
+    protected void inc(AtomicLong x)
+    {
+        x.incrementAndGet() ;
+    }
+
+    // Execute - no stats.
+    // Intecept point for the UberServlet 
+    protected void executeAction(HttpAction action)
+    {
+        executeLifecycle(action) ;
+    }
+    
+    // This is the service request lifecycle.
+    // Called directly by the UberServlet which as not done any stats by this point.
+    protected void executeLifecycle(HttpAction action)
+    {
+        // Fits with uberservlet?
+        inc(action.desc.countServiceRequests) ;
+        startRequest(action) ;
+        try {
+            validate(action) ;
+        } catch (ActionErrorException ex) {
+            inc(action.desc.countServiceRequestsBad) ;
+            throw ex ;
+        }
 
+        try {
+            perform(action) ;
+            // Success
+            inc(action.desc.countServiceRequestsOK) ;
+        } catch (ActionErrorException ex) {
+            inc(action.desc.countServiceRequestsBad) ;
+            throw ex ;
+        } catch (QueryCancelledException ex) {
+            inc(action.desc.countServiceRequestsBad) ;
+            throw ex ;
+        }
+
+        finishRequest(action) ;
+    }
+   
     @SuppressWarnings("unused") // ServletException
     protected void doPatch(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException
@@ -137,25 +192,22 @@ public abstract class SPARQL_ServletBase
         response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "HTTP PATCH not supported");
     }
     
-    private void printRequest(WebRequest wAction)
+    private void printRequest(HttpAction action)
     {
-        String url = wholeRequestURL(wAction.getRequest()) ;
-        String method = wAction.getRequest().getMethod() ;
+        String url = wholeRequestURL(action.request) ;
+        String method = action.request.getMethod() ;
 
-        log.info(format("[%d] %s %s", wAction.id, method, url)) ; 
-        if ( verbose_debug )
-        {
-            Enumeration<String> en = wAction.getRequest().getHeaderNames() ;
-            for ( ; en.hasMoreElements() ; )
-            {
+        log.info(format("[%d] %s %s", action.id, method, url)) ;
+        if (verbose_debug) {
+            Enumeration<String> en = action.request.getHeaderNames() ;
+            for (; en.hasMoreElements();) {
                 String h = en.nextElement() ;
-                Enumeration<String> vals = wAction.getRequest().getHeaders(h) ;
-                if ( ! vals.hasMoreElements() )
-                    log.info(format("[%d]   ", wAction.id, h)) ;
-                else
-                {
-                    for ( ; vals.hasMoreElements() ; )
-                        log.info(format("[%d]   %-20s %s", wAction.id, h, vals.nextElement())) ;
+                Enumeration<String> vals = action.request.getHeaders(h) ;
+                if (!vals.hasMoreElements())
+                    log.info(format("[%d]   ", action.id, h)) ;
+                else {
+                    for (; vals.hasMoreElements();)
+                        log.info(format("[%d]   %-20s %s", action.id, h, vals.nextElement())) ;
                 }
             }
         }
@@ -170,27 +222,27 @@ public abstract class SPARQL_ServletBase
             setVaryHeader(response) ;
     }
     
-    private void printResponse(WebRequest wRequest)
+    private void printResponse(HttpAction action)
     {
-        long time = wRequest.getTime() ;
+        long time = action.getTime() ;
         
-        HttpServletResponseTracker response = wRequest.getResponse() ;
+        HttpServletResponseTracker response = action.response ;
         if ( verbose_debug )
         {
-            if ( wRequest.contentType != null )
-                log.info(format("[%d]   %-20s %s", wRequest.id, HttpNames.hContentType, wRequest.contentType)) ;
-            if ( wRequest.contentLength != -1 )
-                log.info(format("[%d]   %-20s %d", wRequest.id, HttpNames.hContentLengh, wRequest.contentLength)) ;
-            for ( Map.Entry<String, String> e: wRequest.getHeaders().entrySet() )
-                log.info(format("[%d]   %-20s %s", wRequest.id, e.getKey(), e.getValue())) ;
+            if ( action.contentType != null )
+                log.info(format("[%d]   %-20s %s", action.id, HttpNames.hContentType, action.contentType)) ;
+            if ( action.contentLength != -1 )
+                log.info(format("[%d]   %-20s %d", action.id, HttpNames.hContentLengh, action.contentLength)) ;
+            for ( Map.Entry<String, String> e: action.headers.entrySet() )
+                log.info(format("[%d]   %-20s %s", action.id, e.getKey(), e.getValue())) ;
         }
 
         String timeStr = fmtMillis(time) ;
 
-        if ( wRequest.message == null )
-            log.info(String.format("[%d] %d %s (%s) ", wRequest.id, wRequest.statusCode, HttpSC.getMessage(wRequest.statusCode), timeStr)) ;
+        if ( action.message == null )
+            log.info(String.format("[%d] %d %s (%s) ", action.id, action.statusCode, HttpSC.getMessage(action.statusCode), timeStr)) ;
         else
-            log.info(String.format("[%d] %d %s (%s) ", wRequest.id, wRequest.statusCode, wRequest.message, timeStr)) ;
+            log.info(String.format("[%d] %d %s (%s) ", action.id, action.statusCode, action.message, timeStr)) ;
     }
     
     private static String fmtMillis(long time)
@@ -229,5 +281,41 @@ public abstract class SPARQL_ServletBase
         return uri.substring(0, i) ;
     }
     
-    protected abstract void perform(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response) ;
+    /** Implementation of mapRequestToDataset(String) that looks for the longest match.
+     *  This includes use in direct naming GSP. 
+     */
+    protected static String mapRequestToDatasetLongest$(String uri) 
+    {
+        if ( uri == null )
+            return null ;
+        
+        // Mapping a request for GSP needs to find the "best"
+        // (longest matching) dataset URI.
+        // This covers local, using the URI as a direct name for
+        // a graph, not just using the indirect ?graph= or ?default 
+        // forms.
+        // Service matching, which is a matter of removing the service component,
+        // would only work for indirect. 
+
+        String ds = null ;
+        Iterator<String> iter = DatasetRegistry.get().keys() ;
+        while(iter.hasNext())
+        {
+            String ds2 = iter.next();
+            if ( ! uri.startsWith(ds2) )
+                continue ;
+
+            if ( ds == null )
+            {
+                ds = ds2 ;
+                continue ; 
+            }
+            if ( ds.length() < ds2.length() )
+            {
+                ds = ds2 ;
+                continue ;
+            }
+        }
+        return ds ;
+    }
 }

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_UberServlet.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_UberServlet.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_UberServlet.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_UberServlet.java Tue May 21 13:09:27 2013
@@ -20,25 +20,21 @@ package org.apache.jena.fuseki.servlets;
 
 import static java.lang.String.format ;
 
-import java.util.Iterator ;
 import java.util.List ;
 
 import javax.servlet.http.HttpServletRequest ;
 import javax.servlet.http.HttpServletResponse ;
 
-import org.apache.jena.atlas.iterator.Filter ;
-import org.apache.jena.atlas.iterator.Iter ;
 import org.apache.jena.atlas.web.MediaType ;
 import org.apache.jena.fuseki.DEF ;
+import org.apache.jena.fuseki.FusekiException ;
 import org.apache.jena.fuseki.HttpNames ;
 import org.apache.jena.fuseki.conneg.ConNeg ;
 import org.apache.jena.fuseki.server.DatasetRef ;
-import org.apache.jena.fuseki.server.DatasetRegistry ;
 import org.apache.jena.riot.WebContent ;
-import org.apache.jena.web.HttpSC ;
 
 /** This servlet can be attached to a dataset location
- *  and acts as a falserouter for all SPARQL operations
+ *  and acts as a router for all SPARQL operations
  *  (query, update, graph store, both direct and indirect naming). 
  */
 public abstract class SPARQL_UberServlet extends SPARQL_ServletBase
@@ -60,7 +56,7 @@ public abstract class SPARQL_UberServlet
         @Override protected boolean allowQuadsR(HttpAction action)   { return true ; }
         @Override protected boolean allowQuadsW(HttpAction action)   { return false ; }
     }
-    
+
     public static class ReadWrite extends SPARQL_UberServlet
     {
         public ReadWrite(boolean verbose_debug) { super(verbose_debug) ; }
@@ -71,21 +67,20 @@ public abstract class SPARQL_UberServlet
         @Override protected boolean allowQuadsR(HttpAction action)   { return true ; }
         @Override protected boolean allowQuadsW(HttpAction action)   { return true ; }
     }
-    
+
     public static class AccessByConfig extends SPARQL_UberServlet
     {
         public AccessByConfig(boolean verbose_debug) { super(verbose_debug) ; }
-        @Override protected boolean allowQuery(HttpAction action)    { return isEnabled(action.getDatasetRef().queryEP) ; }
-        @Override protected boolean allowUpdate(HttpAction action)   { return isEnabled(action.getDatasetRef().updateEP) ; }
-        @Override protected boolean allowREST_R(HttpAction action)   { return isEnabled(action.getDatasetRef().readGraphStoreEP) || allowREST_W(action); }
-        @Override protected boolean allowREST_W(HttpAction action)   { return isEnabled(action.getDatasetRef().readWriteGraphStoreEP) ; }
+        @Override protected boolean allowQuery(HttpAction action)    { return isEnabled(action.desc.queryEP) ; }
+        @Override protected boolean allowUpdate(HttpAction action)   { return isEnabled(action.desc.updateEP) ; }
+        @Override protected boolean allowREST_R(HttpAction action)   { return isEnabled(action.desc.readGraphStoreEP) || allowREST_W(action); }
+        @Override protected boolean allowREST_W(HttpAction action)   { return isEnabled(action.desc.readWriteGraphStoreEP) ; }
         // Quad operations tied to presence/absence of GSP.
-        @Override protected boolean allowQuadsR(HttpAction action)   { return isEnabled(action.getDatasetRef().readGraphStoreEP) ; }
-        @Override protected boolean allowQuadsW(HttpAction action)   { return isEnabled(action.getDatasetRef().readWriteGraphStoreEP) ; }
-        
+        @Override protected boolean allowQuadsR(HttpAction action)   { return isEnabled(action.desc.readGraphStoreEP) ; }
+        @Override protected boolean allowQuadsW(HttpAction action)   { return isEnabled(action.desc.readWriteGraphStoreEP) ; }
+
         private boolean isEnabled(List<String> ep) { return ep.size() > 0 ; } 
     }
-        
     
     /*  This can be used for a single servlet for everything (über-servlet)
      *  
@@ -119,19 +114,36 @@ public abstract class SPARQL_UberServlet
         return x ;
     }
     
+    // Left to the underlying implementations, when known
+    // These calls shoudl not happen becuase we hook in at execute$
+    @Override protected void validate(HttpAction action) { throw new FusekiException("Call to SPARQL_UberServlet.validate") ; }
+    @Override protected void perform(HttpAction action)  { throw new FusekiException("Call to SPARQL_UberServlet.perform") ; }
+
+    /** Map request to uri in the registry.
+     *  null means no mapping done 
+     */
     @Override
-    protected void validate(HttpServletRequest request)
-    { 
-        // Left to the underlying implementations.
+    protected String mapRequestToDataset(String uri) 
+    {
+        return mapRequestToDatasetLongest$(uri) ;
     }
+    
 
+    /** Intercept the processing cycle at the  point where the action has been set up,
+     *  the dataset target decided but no validation or execution has been done, 
+     *  nor any stats have been done.
+     */
     @Override
-    protected void doCommonWorker(long id, HttpServletRequest request, HttpServletResponse response)
+    protected void executeAction(HttpAction action)
     {
+        long id = action.id ;
+        HttpServletRequest request = action.request ;
+        HttpServletResponse response = action.response ;
         String uri = request.getRequestURI() ;
         String method = request.getMethod() ;
-        String dsname = findDataset(uri) ;
-        String trailing = findTrailing(uri, dsname) ;
+        DatasetRef desc = action.desc ;
+        
+        String trailing = findTrailing(uri, desc.name) ;
         String qs = request.getQueryString() ;
 
         boolean hasParams = request.getParameterMap().size() > 0 ;
@@ -151,18 +163,13 @@ public abstract class SPARQL_UberServlet
         if ( ct != null )
             mt = MediaType.create(ct, charset) ;
         
-        DatasetRef desc = DatasetRegistry.get().get(dsname) ;
-        // The servlets create their own, subclass, action, but it's 
-        // convenient to collect everything together. 
-        HttpAction action = new HttpAction(id, desc, request, response, verbose_debug) ;
-        
-        log.info(format("[%d] All: %s %s :: '%s' :: %s ? %s", id, method, dsname, trailing, (mt==null?"<none>":mt), (qs==null?"":qs))) ;
+        log.info(format("[%d] All: %s %s :: '%s' :: %s ? %s", id, method, desc.name, trailing, (mt==null?"<none>":mt), (qs==null?"":qs))) ;
                        
         boolean hasTrailing = ( trailing.length() != 0 ) ;
         
         if ( ! hasTrailing && ! hasParams )
         {
-            restQuads.doCommonWorker(id, request, response) ;
+            restQuads.executeLifecycle(action) ;
             return ;
         }
         
@@ -174,7 +181,7 @@ public abstract class SPARQL_UberServlet
                 // SPARQL Query
                 if ( ! allowQuery(action))
                     errorForbidden("Forbidden: SPARQL query") ; 
-                executeRequest(desc, queryServlet, desc.queryEP, id, request, response) ;
+                executeRequest(action, queryServlet, desc.queryEP) ;
                 return ;
             }
                  
@@ -183,7 +190,7 @@ public abstract class SPARQL_UberServlet
                 // SPARQL Update
                 if ( ! allowQuery(action))
                     errorForbidden("Forbidden: SPARQL query") ; 
-                executeRequest(desc, updateServlet, desc.updateEP, id, request, response) ;
+                executeRequest(action, updateServlet, desc.updateEP) ;
                 return ;
             }
             
@@ -202,11 +209,11 @@ public abstract class SPARQL_UberServlet
             // There is a trailing part.
             // Check it's not the same name as a registered service.
             // If so, dispatch to that service.
-            if ( checkDispatch(desc.queryEP, trailing, queryServlet, desc, id, request, response) ) return ; 
-            if ( checkDispatch(desc.updateEP, trailing, updateServlet, desc, id, request, response) ) return ; 
-            if ( checkDispatch(desc.uploadEP, trailing, uploadServlet, desc, id, request, response) ) return ; 
-            if ( checkDispatch(desc.readGraphStoreEP, trailing, restServlet_R, desc, id, request, response) ) return ; 
-            if ( checkDispatch(desc.readWriteGraphStoreEP, trailing, restServlet_RW, desc, id, request, response) ) return ; 
+            if ( checkDispatch(action, desc.queryEP, trailing, queryServlet) ) return ; 
+            if ( checkDispatch(action, desc.updateEP, trailing, updateServlet) ) return ; 
+            if ( checkDispatch(action, desc.uploadEP, trailing, uploadServlet) ) return ; 
+            if ( checkDispatch(action, desc.readGraphStoreEP, trailing, restServlet_R) ) return ; 
+            if ( checkDispatch(action, desc.readWriteGraphStoreEP, trailing, restServlet_RW) ) return ; 
         }       
         // There is a trailing part - params are illegal by this point.
         if ( hasParams )
@@ -220,7 +227,7 @@ public abstract class SPARQL_UberServlet
     private void doGraphStoreProtocol(HttpAction action)
     {
         // The GSP servlets handle direct and indirect naming. 
-        DatasetRef desc = action.getDatasetRef();
+        DatasetRef desc = action.desc ;
         String method = action.request.getMethod() ;
         
         if ( HttpNames.METHOD_GET.equalsIgnoreCase(method) ||
@@ -231,9 +238,9 @@ public abstract class SPARQL_UberServlet
            // Graphs Store Protocol, indirect naming, read
            // Indirect naming. Prefer the R service if available.
            if ( desc.readGraphStoreEP.size() > 0 )
-               executeRequest(desc, restServlet_R, desc.readGraphStoreEP, action.id, action.request, action.response) ;
+               executeRequest(action, restServlet_R, desc.readGraphStoreEP) ;
            else if ( desc.readWriteGraphStoreEP.size() > 0 )
-               executeRequest(desc, restServlet_RW, desc.readWriteGraphStoreEP, action.id, action.request, action.response) ;
+               executeRequest(action, restServlet_RW, desc.readWriteGraphStoreEP) ;
            else
                errorMethodNotAllowed(method) ;
            return ;
@@ -242,22 +249,20 @@ public abstract class SPARQL_UberServlet
        // Graphs Store Protocol, indirect naming, write
        if ( ! allowREST_W(action))
            errorForbidden("Forbidden: SPARQL Graph Store Protocol : Write operation : "+method) ;
-       executeRequest(desc, restServlet_RW, desc.readWriteGraphStoreEP, action.id, action.request, action.response) ;
+       executeRequest(action, restServlet_RW, desc.readWriteGraphStoreEP) ;
        return ;
     }
 
-    private void executeRequest(DatasetRef desc, SPARQL_ServletBase servlet, List<String> endpointList, long id,
-                                HttpServletRequest request, HttpServletResponse response)
+    private void executeRequest(HttpAction action, SPARQL_ServletBase servlet, List<String> endpointList)
     {
         if ( endpointList == null || endpointList.size() == 0 )
-            errorMethodNotAllowed(request.getMethod()) ;
-        servlet.doCommonWorker(id, request, response) ;
+            errorMethodNotAllowed(action.request.getMethod()) ;
+        servlet.executeLifecycle(action) ;
     }
 
-    private void executeRequest(DatasetRef desc, SPARQL_ServletBase servlet, long id,
-                                HttpServletRequest request, HttpServletResponse response)
+    private void executeRequest(HttpAction action,SPARQL_ServletBase servlet)
     {
-        servlet.doCommonWorker(id, request, response) ;
+        servlet.executeLifecycle(action) ;
 //      // Forwarded dispatch.
 //      try
 //      {
@@ -265,14 +270,14 @@ public abstract class SPARQL_UberServlet
 //          if ( target == null )
 //              errorMethodNotAllowed(request.getMethod()) ;
 //          // ** relative servlet forward
-//          request.getRequestDispatcher(target).forward(request, response) ;
+//          request.getRequestDispatcher(target).forward(request, response) ;    
+        
+
 //          // ** absolute srvlet forward
 //          // getServletContext().getRequestDispatcher(target) ;
 //      } catch (Exception e) { errorOccurred(e) ; }        
     }
 
-    
-    
     protected static MediaType contentNegotationQuads(HttpAction action)
     {
         MediaType mt = ConNeg.chooseContentType(action.request, DEF.quadsOffer, DEF.acceptNQuads) ;
@@ -285,39 +290,14 @@ public abstract class SPARQL_UberServlet
         return mt ;
     }
 
-    private boolean checkDispatch(List<String> endpointNames, String srvName , SPARQL_ServletBase servlet , DatasetRef desc, long id, 
-                                  HttpServletRequest request, HttpServletResponse response)
+    private boolean checkDispatch(HttpAction action, List<String> endpointNames, String srvName , SPARQL_ServletBase servlet)
     {
         if ( ! endpointNames.contains(srvName) )
             return false ;
-        servlet.doCommonWorker(id, request, response) ;
+        servlet.executeLifecycle(action) ;
         return true ;
     }
 
-    @Override
-    protected void perform(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response)
-    {
-        // Dummy - restructure SPARQL_ServletBase?
-        error(HttpSC.INTERNAL_SERVER_ERROR_500, "Operation directed to general indirection servlet") ;
-    }
-    
-    /** Find the dataset name even if direct naming */ 
-    protected static String findDataset(final String uri) 
-    {
-        // Find the dataset.
-        Iterator<String> datasets = DatasetRegistry.get().keys() ;
-        Filter<String> matchDS = new Filter<String>()
-            {
-                @Override
-                public boolean accept(String datasetname)
-                {
-                    return uri.startsWith(datasetname) ;
-                }
-            } ;
-        String ds = Iter.first(datasets, matchDS) ;
-        return ds ;
-    }
-
     /** Find the dataset name even if direct naming */ 
     protected static String findTrailing(String uri, String dsname) 
     {

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java?rev=1484793&r1=1484792&r2=1484793&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Update.java Tue May 21 13:09:27 2013
@@ -28,7 +28,10 @@ import static org.apache.jena.fuseki.Htt
 import java.io.ByteArrayInputStream ;
 import java.io.IOException ;
 import java.io.InputStream ;
-import java.util.* ;
+import java.util.Arrays ;
+import java.util.Collection ;
+import java.util.Enumeration ;
+import java.util.List ;
 
 import javax.servlet.ServletException ;
 import javax.servlet.http.HttpServletRequest ;
@@ -38,7 +41,6 @@ import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.atlas.web.MediaType ;
 import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.fuseki.HttpNames ;
-import org.apache.jena.fuseki.server.DatasetRef ;
 import org.apache.jena.iri.IRI ;
 import org.apache.jena.riot.WebContent ;
 import org.apache.jena.riot.system.IRIResolver ;
@@ -60,13 +62,6 @@ public class SPARQL_Update extends SPARQ
     private static final String UpdateParseBase = "http://example/update-base/" ;
     private static final IRIResolver resolver = IRIResolver.create(UpdateParseBase) ;
     
-    private class HttpActionUpdate extends HttpActionProtocol {
-        public HttpActionUpdate(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response, boolean verbose)
-        {
-            super(id, desc, request, response, verbose) ;
-        }
-    }
-    
     public SPARQL_Update(boolean verbose)
     { super(verbose) ; }
 
@@ -95,16 +90,12 @@ public class SPARQL_Update extends SPARQ
     }
 
     @Override
-    protected void perform(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse response)
+    protected void perform(HttpAction action)
     {
-        // validate -> action.
-        validate(request) ;
-        HttpActionUpdate action = new HttpActionUpdate(id, desc, request, response, verbose_debug) ;
-        
         // WebContent needs to migrate to using ContentType.
         String ctStr ;
         {
-            MediaType incoming = FusekiLib.contentType(request) ;
+            MediaType incoming = FusekiLib.contentType(action.request) ;
             if ( incoming == null )
                 ctStr = WebContent.contentTypeSPARQLUpdate ;
             else
@@ -121,7 +112,7 @@ public class SPARQL_Update extends SPARQ
             executeForm(action) ;
             return ;
         }
-        error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + request.getContentType()) ;
+        error(HttpSC.UNSUPPORTED_MEDIA_TYPE_415, "Bad content type: " + action.request.getContentType()) ;
     }
 
     protected static List<String> paramsForm = Arrays.asList(paramRequest, paramUpdate, 
@@ -129,19 +120,15 @@ public class SPARQL_Update extends SPARQ
     protected static List<String> paramsPOST = Arrays.asList(paramUsingGraphURI, paramUsingNamedGraphURI) ;
     
     @Override
-    protected void validate(HttpServletRequest request)
+    protected void validate(HttpAction action)
     {
+        HttpServletRequest request = action.request ;
+        
         if ( ! HttpNames.METHOD_POST.equalsIgnoreCase(request.getMethod()) )
             errorMethodNotAllowed("SPARQL Update : use POST") ;
         
-        String ctStr ;
-        {
-            MediaType incoming = FusekiLib.contentType(request) ;
-            if ( incoming == null )
-                ctStr = WebContent.contentTypeSPARQLUpdate ;
-            else
-                ctStr = incoming.getContentType() ;
-        }
+        MediaType incoming = FusekiLib.contentType(request) ;
+        String ctStr = ( incoming == null ) ? WebContent.contentTypeSPARQLUpdate : incoming.getContentType() ;
         // ----
         
         if ( WebContent.contentTypeSPARQLUpdate.equals(ctStr) )
@@ -155,7 +142,7 @@ public class SPARQL_Update extends SPARQ
         
         if ( WebContent.contentTypeForm.equals(ctStr) )
         {
-            int x = countParamOccurences(request,paramUpdate) + countParamOccurences(request, paramRequest) ;
+            int x = countParamOccurences(request, paramUpdate) + countParamOccurences(request, paramRequest) ;
             if ( x == 0 )
                 errorBadRequest("SPARQL Update: No 'update=' parameter") ;
             if ( x != 1 )
@@ -187,7 +174,7 @@ public class SPARQL_Update extends SPARQ
         }
     }
 
-    private void executeBody(HttpActionUpdate action)
+    private void executeBody(HttpAction action)
     {
         InputStream input = null ;
         try { input = action.request.getInputStream() ; }
@@ -209,7 +196,7 @@ public class SPARQL_Update extends SPARQ
         successNoContent(action) ;
     }
 
-    private void executeForm(HttpActionUpdate action)
+    private void executeForm(HttpAction action)
     {
         String requestStr = action.request.getParameter(paramUpdate) ;
         if ( requestStr == null )
@@ -228,7 +215,7 @@ public class SPARQL_Update extends SPARQ
         successPage(action,"Update succeeded") ;
     }
     
-    private void execute(HttpActionUpdate action, InputStream input)
+    private void execute(HttpAction action, InputStream input)
     {
         UsingList usingList = processProtocol(action.request) ;