You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2011/12/08 14:26:36 UTC

svn commit: r1211871 - in /incubator/stanbol/trunk: commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/ commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/ launchers/full-war/ launchers/full-war/src/main/bundles...

Author: suat
Date: Thu Dec  8 13:26:36 2011
New Revision: 1211871

URL: http://svn.apache.org/viewvc?rev=1211871&view=rev
Log:
STANBOL-348:
getStaticRootUrl() of BaseStanbolResource now returns the full URI of the static resource so that the static resources are correctly accessed by browsers. I had explained the problem at [1]. Also, when war file is deployed to application server, it starts automatically now.

Furthermore, static resources are deployed considering the configured web.alias property instead of considering only web.static.url property.

As far as I tried, configuring web.alias and/or web.static.url properties works as expected in war context and other launchers.  

[1] http://markmail.org/message/e25iczswtvtf5a7g

Modified:
    incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java
    incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
    incubator/stanbol/trunk/launchers/full-war/pom.xml
    incubator/stanbol/trunk/launchers/full-war/src/main/bundles/list.xml
    incubator/stanbol/trunk/launchers/full-war/src/main/webapp/WEB-INF/web.xml

Modified: incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java?rev=1211871&r1=1211870&r2=1211871&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java (original)
+++ incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/JerseyEndpoint.java Thu Dec  8 13:26:36 2011
@@ -1,19 +1,19 @@
 /*
-* 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.
-*/
+ * 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 org.apache.stanbol.commons.web.base;
 
 import java.io.IOException;
@@ -48,7 +48,6 @@ import org.slf4j.LoggerFactory;
 
 import com.sun.jersey.spi.container.servlet.ServletContainer;
 
-
 /**
  * Jersey-based RESTful endpoint for the Stanbol Enhancer engines and store.
  * <p>
@@ -66,12 +65,12 @@ public class JerseyEndpoint {
 
     @Property(value = "/static")
     public static final String STATIC_RESOURCES_URL_ROOT_PROPERTY = "org.apache.stanbol.commons.web.static.url";
-    
+
     /**
      * The origins allowed for multi-host requests
      */
-    @Property(cardinality=100,value = {"*"})
-    public static final String CORS_ORIGIN =  "org.apache.stanbol.commons.web.cors.origin";
+    @Property(cardinality = 100, value = {"*"})
+    public static final String CORS_ORIGIN = "org.apache.stanbol.commons.web.cors.origin";
 
     @Reference
     HttpService httpService;
@@ -83,8 +82,8 @@ public class JerseyEndpoint {
     protected final List<WebFragment> webFragments = new ArrayList<WebFragment>();
 
     protected final List<String> registeredAliases = new ArrayList<String>();
-    
-    protected Set<String> corsOrigins; 
+
+    protected Set<String> corsOrigins;
 
     public Dictionary<String,String> getInitParams() {
         Dictionary<String,String> initParams = new Hashtable<String,String>();
@@ -95,45 +94,50 @@ public class JerseyEndpoint {
     }
 
     @Activate
-    protected void activate(ComponentContext ctx) throws IOException, ServletException, NamespaceException, ConfigurationException {
+    protected void activate(ComponentContext ctx) throws IOException,
+                                                 ServletException,
+                                                 NamespaceException,
+                                                 ConfigurationException {
         componentContext = ctx;
-        //init corsOrigins
+        // init corsOrigins
         Object values = componentContext.getProperties().get(CORS_ORIGIN);
-        if(values instanceof String && !((String)values).isEmpty()){
-            corsOrigins = Collections.singleton((String)values);
-        } else if (values instanceof String[]){
-            corsOrigins = new HashSet<String>(Arrays.asList((String[])values));
-        } else if (values instanceof Iterable<?>){
+        if (values instanceof String && !((String) values).isEmpty()) {
+            corsOrigins = Collections.singleton((String) values);
+        } else if (values instanceof String[]) {
+            corsOrigins = new HashSet<String>(Arrays.asList((String[]) values));
+        } else if (values instanceof Iterable<?>) {
             corsOrigins = new HashSet<String>();
-            for(Object value : (Iterable<?>)values){
-                if(value != null && !value.toString().isEmpty()){
+            for (Object value : (Iterable<?>) values) {
+                if (value != null && !value.toString().isEmpty()) {
                     corsOrigins.add(value.toString());
                 }
             }
         } else {
-            throw new ConfigurationException(CORS_ORIGIN,"CORS origin(s) MUST be a String, String[], Iterable<String> (value:"+values+")");
+            throw new ConfigurationException(CORS_ORIGIN,
+                    "CORS origin(s) MUST be a String, String[], Iterable<String> (value:" + values + ")");
         }
         if (!webFragments.isEmpty()) {
             initJersey();
         }
     }
-    
+
     /** Initialize the Jersey subsystem */
     private synchronized void initJersey() throws NamespaceException, ServletException {
-        
-        if(componentContext == null) {
+
+        if (componentContext == null) {
             throw new IllegalStateException("Null ComponentContext, not activated?");
         }
-        
+
         shutdownJersey();
-        
+
         log.info("Initializing the Jersey subsystem");
-        
-        
+
         // register all the JAX-RS resources into a a JAX-RS application and bind it to a configurable URL
         // prefix
         JerseyEndpointApplication app = new JerseyEndpointApplication();
-        String staticUrlRoot = (String) componentContext.getProperties().get(STATIC_RESOURCES_URL_ROOT_PROPERTY);
+        String staticUrlRoot = (String) componentContext.getProperties().get(
+            STATIC_RESOURCES_URL_ROOT_PROPERTY);
+        String applicationAlias = (String) componentContext.getProperties().get(ALIAS_PROPERTY);
 
         // incrementally contribute fragment resources
         List<LinkResource> linkResources = new ArrayList<LinkResource>();
@@ -149,7 +153,11 @@ public class JerseyEndpoint {
             app.contributeTemplateLoader(fragment.getTemplateLoader());
             String staticPath = fragment.getStaticResourceClassPath();
             if (staticPath != null) {
-                String resourceAlias = staticUrlRoot + '/' + fragment.getName();
+                String resourceAlias = (applicationAlias.endsWith("/") ? applicationAlias.substring(0,
+                    applicationAlias.length() - 1) : applicationAlias)
+                                       + staticUrlRoot
+                                       + '/'
+                                       + fragment.getName();
                 httpService.registerResources(resourceAlias, staticPath, new BundleHttpContext(fragment));
                 registeredAliases.add(resourceAlias);
             }
@@ -160,7 +168,6 @@ public class JerseyEndpoint {
 
         // bind the aggregate JAX-RS application to a dedicated servlet
         ServletContainer container = new ServletContainer(app);
-        String applicationAlias = (String) componentContext.getProperties().get(ALIAS_PROPERTY);
         Bundle appBundle = componentContext.getBundleContext().getBundle();
         httpService.registerServlet(applicationAlias, container, getInitParams(), new BundleHttpContext(
                 appBundle));
@@ -176,10 +183,10 @@ public class JerseyEndpoint {
         servletContext.setAttribute(BaseStanbolResource.SCRIPT_RESOURCES, scriptResources);
         servletContext.setAttribute(BaseStanbolResource.NAVIGATION_LINKS, navigationLinks);
         servletContext.setAttribute(CORS_ORIGIN, corsOrigins);
-        
+
         log.info("JerseyEndpoint servlet registered at {}", applicationAlias);
     }
-    
+
     /** Shutdown Jersey, if there's anything to do */
     private synchronized void shutdownJersey() {
         log.info("Unregistering aliases {}", registeredAliases);

Modified: incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java?rev=1211871&r1=1211870&r2=1211871&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java (original)
+++ incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/resource/BaseStanbolResource.java Thu Dec  8 13:26:36 2011
@@ -1,19 +1,19 @@
 /*
-* 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.
-*/
+ * 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 org.apache.stanbol.commons.web.base.resource;
 
 import java.net.URI;
@@ -111,7 +111,9 @@ public class BaseStanbolResource {
     }
 
     public String getStaticRootUrl() {
-        return (String) servletContext.getAttribute(STATIC_RESOURCES_ROOT_URL); 
+        String baseURI = getPublicBaseUri().toString();
+        return baseURI.substring(0, baseURI.length() - 1)
+               + (String) servletContext.getAttribute(STATIC_RESOURCES_ROOT_URL);
     }
 
     @SuppressWarnings("unchecked")

Modified: incubator/stanbol/trunk/launchers/full-war/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/launchers/full-war/pom.xml?rev=1211871&r1=1211870&r2=1211871&view=diff
==============================================================================
--- incubator/stanbol/trunk/launchers/full-war/pom.xml (original)
+++ incubator/stanbol/trunk/launchers/full-war/pom.xml Thu Dec  8 13:26:36 2011
@@ -175,6 +175,13 @@
       <artifactId>org.apache.stanbol.entityhub.bundlelist</artifactId>
       <type>partialbundlelist</type>
     </dependency>
+    
+    <!-- Stanbol FactStore Bundle List -->
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.factstore.bundlelist</artifactId>
+      <type>partialbundlelist</type>
+    </dependency>
 
     <!-- Stanbol Ontology Manager Bundle List -->
     <dependency>

Modified: incubator/stanbol/trunk/launchers/full-war/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/launchers/full-war/src/main/bundles/list.xml?rev=1211871&r1=1211870&r2=1211871&view=diff
==============================================================================
--- incubator/stanbol/trunk/launchers/full-war/src/main/bundles/list.xml (original)
+++ incubator/stanbol/trunk/launchers/full-war/src/main/bundles/list.xml Thu Dec  8 13:26:36 2011
@@ -67,15 +67,6 @@
           (Enhancer, Entityhub, Contenthub, Factstore ... incl. Web Fragments)
        ********************************************************************* -->
 
-  <!-- FactStore -->
-  <startLevel level="20">
-    <bundle>
-      <groupId>org.apache.stanbol</groupId>
-      <artifactId>org.apache.stanbol.factstore</artifactId>
-      <version>0.9.0-incubating-SNAPSHOT</version>
-    </bundle>
-  </startLevel>
-
   <!-- KReS -->
   <startLevel level="22">
 		<bundle>

Modified: incubator/stanbol/trunk/launchers/full-war/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/launchers/full-war/src/main/webapp/WEB-INF/web.xml?rev=1211871&r1=1211870&r2=1211871&view=diff
==============================================================================
--- incubator/stanbol/trunk/launchers/full-war/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/stanbol/trunk/launchers/full-war/src/main/webapp/WEB-INF/web.xml Thu Dec  8 13:26:36 2011
@@ -27,6 +27,7 @@
 		<display-name>Sling Servlet</display-name>
 		<servlet-name>sling</servlet-name>
 		<servlet-class>org.apache.sling.launchpad.webapp.SlingServlet</servlet-class>
+        <load-on-startup>100</load-on-startup>
 	</servlet>
 
 	<!-- Default Mapping for the Context -->