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/12/14 18:58:12 UTC

svn commit: r1550961 - in /jena/branches/jena-fuseki-new-ui: src-dev/dev/PROJECT.java src-dev/webapp/ src-dev/webapp/FusekiServlet.java src-dev/webapp/ServerInit.java war-web.xml

Author: andy
Date: Sat Dec 14 17:58:12 2013
New Revision: 1550961

URL: http://svn.apache.org/r1550961
Log:
Material for a WAR packaging of Fuseki.

Added:
    jena/branches/jena-fuseki-new-ui/src-dev/webapp/
    jena/branches/jena-fuseki-new-ui/src-dev/webapp/FusekiServlet.java
    jena/branches/jena-fuseki-new-ui/src-dev/webapp/ServerInit.java
    jena/branches/jena-fuseki-new-ui/war-web.xml
Modified:
    jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java

Modified: jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java?rev=1550961&r1=1550960&r2=1550961&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java (original)
+++ jena/branches/jena-fuseki-new-ui/src-dev/dev/PROJECT.java Sat Dec 14 17:58:12 2013
@@ -28,5 +28,9 @@ public class PROJECT {
     
     // Document (write/update) all protocol modes.
     // TESTS
+    
+    // JENA-201 - WAR Fuseki.
+    //   WEB.xml
+    //   ContextPath in uber dispatch.
 }
 

Added: jena/branches/jena-fuseki-new-ui/src-dev/webapp/FusekiServlet.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src-dev/webapp/FusekiServlet.java?rev=1550961&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src-dev/webapp/FusekiServlet.java (added)
+++ jena/branches/jena-fuseki-new-ui/src-dev/webapp/FusekiServlet.java Sat Dec 14 17:58:12 2013
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package webapp;
+
+import javax.servlet.ServletContext ;
+import javax.servlet.ServletException ;
+import javax.servlet.http.HttpServletRequest ;
+import javax.servlet.http.HttpServletResponse ;
+
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.fuseki.servlets.ActionLib ;
+import org.apache.jena.fuseki.servlets.HttpAction ;
+import org.apache.jena.fuseki.servlets.SPARQL_UberServlet ;
+
+/** Various fixes to make the uber servlet work in named webapp contexts */ 
+public class FusekiServlet extends SPARQL_UberServlet.AccessByConfig {
+    
+    @Override 
+    public void init() throws ServletException {
+        Log.info(this, getServletContext().getServletContextName()) ;
+        super.init() ;
+    }
+    
+    
+    @Override public void doGet(HttpServletRequest request, HttpServletResponse response) {
+        /*
+         * getContextPath--
+         *   Either "/path" or "" for root app 
+         *   Canonical form is via ServletContext
+         * getServletPath--
+         *   Either "/path" or "" for matching "/*"
+         */
+        Log.info(this, "URI                     = '"+request.getRequestURI()) ;
+        Log.info(this, "Context path            = '"+request.getContextPath()+"'") ;
+        Log.info(this, "Servlet path            = '"+request.getServletPath()+"'") ;
+        ServletContext cxt = this.getServletContext() ;
+        Log.info(this, "ServletContext path     = '"+cxt.getContextPath()+"'") ;
+        //Log.info(this, "ServletContextName path = '"+cxt.getServletContextName()+"'") ;
+        super.doGet(request, response);
+    }
+    
+    @Override
+    protected String mapRequestToDataset(HttpAction action) 
+    {
+        String uri = action.request.getRequestURI() ;
+        String x = removeContextPath(uri) ;
+        return ActionLib.mapRequestToDatasetLongest$(action.request.getRequestURI()) ;
+    }
+    
+    /** Find the graph (direct naming) or service name */
+    @Override
+    protected String findTrailing(String uri, String dsname) 
+    {
+        String x = removeContextPath(uri) ;
+        return super.findTrailing(x, dsname) ;
+    }
+
+    /* 
+     * The context path can be:
+     * "" for the root context
+     * "/webapp" for named contexts
+     * so:
+     * "/dataset/server" becomes "/dataset/server"
+     * "/webapp/dataset/server" becomes "/dataset/server"
+     */
+    private String removeContextPath(String uri) {
+        String contextPath = getServletContext().getContextPath() ;
+        if ( contextPath == null )
+            return uri ;
+        if ( contextPath.isEmpty())
+            return uri ;
+        String x = uri ;
+        if ( uri.startsWith(contextPath) )
+            x = uri.substring(contextPath.length()) ;
+        //log.info("removeContext: uri = "+uri+" contextPath="+contextPath+ "--> x="+x) ;
+        return x ;
+    }
+
+}

Added: jena/branches/jena-fuseki-new-ui/src-dev/webapp/ServerInit.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src-dev/webapp/ServerInit.java?rev=1550961&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src-dev/webapp/ServerInit.java (added)
+++ jena/branches/jena-fuseki-new-ui/src-dev/webapp/ServerInit.java Sat Dec 14 17:58:12 2013
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package webapp;
+
+import javax.servlet.ServletContext ;
+import javax.servlet.ServletContextEvent ;
+import javax.servlet.ServletContextListener ;
+
+import org.apache.jena.fuseki.Fuseki ;
+import org.apache.jena.fuseki.server.DatasetRef ;
+import org.apache.jena.fuseki.server.DatasetRegistry ;
+import org.apache.jena.fuseki.server.FusekiConfig ;
+import org.apache.jena.fuseki.server.ServerConfig ;
+import org.slf4j.Logger ;
+
+/** Manage server initialization */
+public class ServerInit implements ServletContextListener {
+   private static Logger confLog = Fuseki.configLog ; 
+    
+    // Only works with the uber servlet.
+
+    // Default.
+    static public String rootDirectory     = "/usr/share/fuseki" ;
+//    static public String staticContentDir  = rootDirectory + "/pages" ;
+    static public String configurationFile = rootDirectory + "/config-fuseki.ttl" ;
+
+    static public ServerConfig serverConfig = null ;
+    static Boolean initialized = false ;
+
+    @Override
+    public void contextInitialized(ServletContextEvent sce) {
+        //confLog.info("contextInitialized");
+        ServletContext cxt = sce.getServletContext() ;
+        confLog.info(cxt.getServletContextName()) ;
+        init() ;
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent sce) {}
+
+    public static void init() {
+        if ( initialized )
+            return ;
+        synchronized(initialized)
+        {
+            if ( initialized )
+                return ;
+            Fuseki.init() ;
+           confLog.error("Unconverted code - need to find configuration");
+            
+            // Find configuration file.
+            if ( serverConfig != null )
+                // already set - the standalone server may set this early
+                // for command line use.
+                return ;
+            
+            if ( configurationFile == null )
+                confLog.error("No configuration file") ;
+            serverConfig = FusekiConfig.configure(configurationFile) ;
+            
+            for ( DatasetRef dsDesc : serverConfig.datasets ) {
+                String datasetPath = dsDesc.name ;
+                if ( datasetPath.equals("/") )
+                    datasetPath = "" ;
+                else
+                    if ( !datasetPath.startsWith("/") )
+                        datasetPath = "/" + datasetPath ;
+
+                if ( datasetPath.endsWith("/") )
+                    datasetPath = datasetPath.substring(0, datasetPath.length() - 1) ;
+
+                dsDesc.enable(); 
+                // Register with "/ds"
+                // Because config file says "ds" and command line + Uber usually says "/ds"
+                // hence somewhere non-uber does this as well.  Check.
+                // mapRequestToDatasetLongest$ vs ?
+                dsDesc.name = datasetPath ;
+                //confLog.info("Register: "+datasetPath+" : "+dsDesc.name);
+                DatasetRegistry.get().put(datasetPath, dsDesc) ;
+            }
+            
+            // Just the datasets
+
+            //serverConfig.pages = staticContentDir ;
+            //serverConfig.verboseLogging = false ;
+            
+            // Default, built-in.
+            //serverConfig = FusekiConfig.defaultConfiguration(datasetPath, dsg, allowUpdate, listenLocal) ;
+        
+            // NA -- serverConfig.port = port ;
+            // NA -- serverConfig.mgtPort = mgtPort ;
+            // NA -- serverConfig.pagesPort = port ;
+            // NA -- serverConfig.loopback = listenLocal ;
+            // NA? -- serverConfig.enableCompression = enableCompression ;
+            // NA -- serverConfig.jettyConfigFile = jettyConfigFile ;
+            // NA -- serverConfig.authConfigFile = authConfigFile ; // Use web container.
+            
+        }
+    }
+}
+

Added: jena/branches/jena-fuseki-new-ui/war-web.xml
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/war-web.xml?rev=1550961&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/war-web.xml (added)
+++ jena/branches/jena-fuseki-new-ui/war-web.xml Sat Dec 14 17:58:12 2013
@@ -0,0 +1,73 @@
+<?xml version="1.0"?>
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+	 version="3.0">
+
+  <display-name>Apache Jena Fuseki Server</display-name>
+
+  <listener>
+    <listener-class>webapp.ServerInit</listener-class>
+  </listener>
+
+  <servlet>
+    <servlet-name>FusekiServlet</servlet-name>
+    <servlet-class>webapp.FusekiServlet</servlet-class>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>FusekiServlet</servlet-name>
+    <url-pattern>/</url-pattern>
+  </servlet-mapping>
+
+  <!-- pages -->
+
+  <!--
+  <welcome-file-list>
+    <welcome-file>index.html</welcome-file>
+  </welcome-file-list>
+  -->
+  <mime-mapping>
+    <extension>rdf</extension>
+    <mime-type>application/rdf+xml;charset=utf-8</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ttl</extension>
+    <mime-type>text/turtle;charset=utf-8</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>nt</extension>
+    <mime-type>text/plain;charset=utf-8</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>nq</extension>
+    <mime-type>text/nquads;charset=utf-8</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>trig</extension>
+    <mime-type>application/trig;charset=utf-8</mime-type>
+  </mime-mapping>
+
+  <!-- If using security via Shiro - ->
+
+  <listener>
+    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
+  </listener>
+
+  <filter>
+    <filter-name>ShiroFilter</filter-name>
+    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
+  </filter>
+
+  <filter-mapping>
+    <filter-name>ShiroFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+    <dispatcher>REQUEST</dispatcher>
+    <dispatcher>FORWARD</dispatcher>
+    <dispatcher>INCLUDE</dispatcher>
+    <dispatcher>ERROR</dispatcher>
+  </filter-mapping>
+  -->
+
+</web-app>
\ No newline at end of file