You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by ja...@apache.org on 2011/06/30 16:05:29 UTC

svn commit: r1141544 - in /incubator/rave/trunk: ./ rave-shindig/ rave-shindig/src/main/java/org/apache/rave/commoncontainer/ rave-shindig/src/main/webapp/WEB-INF/ rave-shindig/src/test/ rave-shindig/src/test/java/ rave-shindig/src/test/java/org/ rave-...

Author: jasha
Date: Thu Jun 30 14:05:29 2011
New Revision: 1141544

URL: http://svn.apache.org/viewvc?rev=1141544&view=rev
Log:
RAVE-82 Override shindig.properties by setting its location in system property shindig.override.properties

Added:
    incubator/rave/trunk/rave-shindig/src/main/java/org/apache/rave/commoncontainer/
    incubator/rave/trunk/rave-shindig/src/main/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModule.java
    incubator/rave/trunk/rave-shindig/src/test/
    incubator/rave/trunk/rave-shindig/src/test/java/
    incubator/rave/trunk/rave-shindig/src/test/java/org/
    incubator/rave/trunk/rave-shindig/src/test/java/org/apache/
    incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/
    incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/commoncontainer/
    incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModuleTest.java
    incubator/rave/trunk/rave-shindig/src/test/resources/
    incubator/rave/trunk/rave-shindig/src/test/resources/containers/
    incubator/rave/trunk/rave-shindig/src/test/resources/containers/default/
    incubator/rave/trunk/rave-shindig/src/test/resources/containers/default/testcontainer.js
    incubator/rave/trunk/rave-shindig/src/test/resources/shindig.test.properties
Modified:
    incubator/rave/trunk/pom.xml
    incubator/rave/trunk/rave-shindig/pom.xml
    incubator/rave/trunk/rave-shindig/src/main/webapp/WEB-INF/web.xml

Modified: incubator/rave/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/pom.xml?rev=1141544&r1=1141543&r2=1141544&view=diff
==============================================================================
--- incubator/rave/trunk/pom.xml (original)
+++ incubator/rave/trunk/pom.xml Thu Jun 30 14:05:29 2011
@@ -137,6 +137,11 @@
                 <version>${org.springframework.version}</version>
             </dependency>
             <dependency>
+              <groupId>org.springframework</groupId>
+              <artifactId>spring-core</artifactId>
+              <version>${org.springframework.version}</version>
+            </dependency>
+            <dependency>
               <groupId>org.glassfish.web</groupId>
               <artifactId>jstl-impl</artifactId>
               <version>${jstl.version}</version>

Modified: incubator/rave/trunk/rave-shindig/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/pom.xml?rev=1141544&r1=1141543&r2=1141544&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/pom.xml (original)
+++ incubator/rave/trunk/rave-shindig/pom.xml Thu Jun 30 14:05:29 2011
@@ -59,6 +59,11 @@
     </dependency>
 
     <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-core</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.shindig</groupId>
       <artifactId>shindig-social-api</artifactId>
       <scope>provided</scope>
@@ -80,7 +85,7 @@
        <version>1.3</version>
        <scope>test</scope>
     </dependency>
-   </dependencies>
+  </dependencies>
 
   <build>
     <defaultGoal>install</defaultGoal>

Added: incubator/rave/trunk/rave-shindig/src/main/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModule.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/main/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModule.java?rev=1141544&view=auto
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/main/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModule.java (added)
+++ incubator/rave/trunk/rave-shindig/src/main/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModule.java Thu Jun 30 14:05:29 2011
@@ -0,0 +1,115 @@
+/*
+ * 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.rave.commoncontainer;
+
+import com.google.inject.CreationException;
+import com.google.inject.spi.Message;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shindig.common.PropertiesModule;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Properties;
+
+/**
+ * Injects everything from the a property file as a Named value.<br/>
+ * Uses the {@literal shindig.properties} file unless the system property
+ * {@literal shindig.override.properties} defines a different location.
+ */
+public class ConfigurablePropertiesModule extends PropertiesModule {
+
+    private static final String DEFAULT_PROPERTIES = "shindig.properties";
+    private static final String SHINDIG_OVERRIDE_PROPERTIES = "shindig.override.properties";
+
+    private static final String CLASSPATH = "classpath:";
+
+    private static final String CONTEXT_ROOT_PLACEHOLDER = "%contextRoot%";
+    private static final String CONTEXT_ROOT_SYSTEM_PROPERTY = "shindig.contextroot";
+
+
+    /**
+     * Injects everything from the a property file as a Named value.
+     * Only the entire properties file can be overridden.
+     * {@inheritDoc}
+     */
+    @Override
+    protected void configure() {
+        install(new PropertiesModule(loadProperties()));
+    }
+
+
+    /**
+     * If the system property {@literal shindig.override.properties} is set,
+     * it will load the file from that location,
+     * otherwise it will load the default Shindig {@literal shindig.properties} file
+     *
+     * @return {@link Properties} for the container
+     * @throws CreationException if the Properties file cannot be read
+     */
+    protected Properties loadProperties() {
+        Properties initProperties = new Properties();
+        final String overrideProperty = System.getProperty(SHINDIG_OVERRIDE_PROPERTIES);
+
+        Resource propertyResource;
+
+        if (StringUtils.isBlank(overrideProperty)) {
+            propertyResource = new ClassPathResource(DEFAULT_PROPERTIES);
+        } else if (overrideProperty.startsWith(CLASSPATH)) {
+            propertyResource = new ClassPathResource(
+                    overrideProperty.trim().substring(CLASSPATH.length()));
+        } else {
+            propertyResource = new FileSystemResource(
+                    overrideProperty.trim());
+        }
+
+        try {
+            initProperties.load(propertyResource.getInputStream());
+            for (Object key : initProperties.keySet()) {
+                String value = (String) initProperties.get(key);
+                if (value != null && value.contains(CONTEXT_ROOT_PLACEHOLDER)) {
+                    initProperties.put(key,
+                            value.replace((CONTEXT_ROOT_PLACEHOLDER), getContextRoot()));
+                }
+            }
+        } catch (IOException e) {
+            throw new CreationException(Arrays.asList(
+                    new Message("Unable to load properties: " + overrideProperty)));
+        }
+
+        return initProperties;
+    }
+
+    /**
+     * Should return the context root where the current web module is deployed with.
+     * Useful for testing and working out of the box configs.
+     * If not set uses fixed value of "".
+     *
+     * @return an context path as a string.
+     */
+    private String getContextRoot() {
+        return System.getProperty(CONTEXT_ROOT_SYSTEM_PROPERTY) != null ?
+                System.getProperty(CONTEXT_ROOT_SYSTEM_PROPERTY) : "";
+    }
+
+
+}

Modified: incubator/rave/trunk/rave-shindig/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/main/webapp/WEB-INF/web.xml?rev=1141544&r1=1141543&r2=1141544&view=diff
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/rave/trunk/rave-shindig/src/main/webapp/WEB-INF/web.xml Thu Jun 30 14:05:29 2011
@@ -30,7 +30,7 @@
   <context-param>
     <param-name>guice-modules</param-name>
     <param-value>
-      org.apache.shindig.common.PropertiesModule:
+      org.apache.rave.commoncontainer.ConfigurablePropertiesModule:
       org.apache.shindig.gadgets.DefaultGuiceModule:
       org.apache.shindig.social.core.config.SocialApiGuiceModule:
       org.apache.rave.os.JPAOpenSocialModule:

Added: incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModuleTest.java?rev=1141544&view=auto
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModuleTest.java (added)
+++ incubator/rave/trunk/rave-shindig/src/test/java/org/apache/rave/commoncontainer/ConfigurablePropertiesModuleTest.java Thu Jun 30 14:05:29 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.rave.commoncontainer;
+
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test for {@link ConfigurablePropertiesModule}
+ */
+public class ConfigurablePropertiesModuleTest {
+
+    @Test
+    public void testDefaultProperties() throws Exception {
+        System.setProperty("shindig.contextroot", "shindigcontext");
+
+        TestableConfigurablePropertiesModule propertiesModule = new TestableConfigurablePropertiesModule();
+        Properties properties = propertiesModule.getProperties();
+
+        assertEquals("Default container.js location", "res://containers/default/container.js",
+                properties.getProperty("shindig.containers.default"));
+        assertEquals("Replaced contextRoot", "shindigcontext/gadgets/proxy?container=default&url=",
+                properties.getProperty("shindig.content-rewrite.proxy-url"));
+    }
+
+    @Test
+    public void testCustomProperties() throws Exception {
+        System.setProperty("shindig.contextroot", "shindigcontext");
+        System.setProperty("shindig.override.properties", "classpath:shindig.test.properties");
+
+        TestableConfigurablePropertiesModule propertiesModule = new TestableConfigurablePropertiesModule();
+        Properties properties = propertiesModule.loadProperties();
+
+        assertEquals("Custom container.js location",
+                "res://containers/default/container.js,res://containers/default/testcontainer.js",
+                properties.getProperty("shindig.containers.default"));
+        assertEquals("Replaced contextRoot", "shindigcontext/gadgets/proxy?container=default&url=",
+                properties.getProperty("shindig.content-rewrite.proxy-url"));
+    }
+
+
+    /**
+     * Inner private class to access {@link org.apache.rave.commoncontainer.ConfigurablePropertiesModule#getProperties()}
+     */
+    private class TestableConfigurablePropertiesModule extends ConfigurablePropertiesModule {
+
+        @Override
+        protected Properties getProperties() {
+            return super.getProperties();
+        }
+    }
+}

Added: incubator/rave/trunk/rave-shindig/src/test/resources/containers/default/testcontainer.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/test/resources/containers/default/testcontainer.js?rev=1141544&view=auto
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/test/resources/containers/default/testcontainer.js (added)
+++ incubator/rave/trunk/rave-shindig/src/test/resources/containers/default/testcontainer.js Thu Jun 30 14:05:29 2011
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+{}
\ No newline at end of file

Added: incubator/rave/trunk/rave-shindig/src/test/resources/shindig.test.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-shindig/src/test/resources/shindig.test.properties?rev=1141544&view=auto
==============================================================================
--- incubator/rave/trunk/rave-shindig/src/test/resources/shindig.test.properties (added)
+++ incubator/rave/trunk/rave-shindig/src/test/resources/shindig.test.properties Thu Jun 30 14:05:29 2011
@@ -0,0 +1,176 @@
+# 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.
+
+# Location of feature manifests (comma separated)
+shindig.features.default=res://features/features.txt
+
+# Location of container configurations (comma separated)
+shindig.containers.default=res://containers/default/container.js,res://containers/default/testcontainer.js
+
+# A file containing blacklisted gadgets.
+shindig.blacklist.file=
+
+### Inbound OAuth support
+# The URL base to use for full OAuth support (three-legged)
+shindig.oauth.base-url=/oauth/
+shindig.oauth.authorize-action=/WEB-INF/authorize.jsp
+# The range to the past and future of timestamp for OAuth token validation. Default to 5 minutes
+shindig.oauth.validator-max-timestamp-age-ms=300000
+
+### Outbound OAuth support
+shindig.signing.state-key=
+shindig.signing.key-name=
+shindig.signing.key-file=
+shindig.signing.global-callback-url=http://localhost:8080%contextRoot%/gadgets/oauthcallback
+shindig.signing.enable-signed-callbacks=true
+
+# Set to true if you want to allow the use of 3-legged OAuth tokens when viewer != owner.
+# This setting is not recommeneded for pages that allow user-controlled javascript, since
+# that javascript could be used to make unauthorized requests on behalf of the viewer of the page
+shindig.signing.viewer-access-tokens-enabled=false
+
+# If enabled here, configuration values can be found in container configuration files.
+shindig.locked-domain.enabled=false
+
+# TODO: This needs to be moved to container configuration.
+shindig.content-rewrite.only-allow-excludes=false
+shindig.content-rewrite.include-urls=.*
+shindig.content-rewrite.exclude-urls=
+shindig.content-rewrite.include-tags=body,embed,img,input,link,script,style
+shindig.content-rewrite.expires=86400
+shindig.content-rewrite.proxy-url=%contextRoot%/gadgets/proxy?container=default&url=
+shindig.content-rewrite.concat-url=%contextRoot%/gadgets/concat?container=default&
+shindig.content-rewrite.enable-split-js-concat=true
+shindig.content-rewrite.enable-single-resource-concat=false
+
+#
+# Default set of forced libs to allow for better caching
+#
+# NOTE: setting this causes the EndToEnd test to fail the opensocial-templates test
+shindig.gadget-rewrite.default-forced-libs=core:rpc
+#shindig.gadget-rewrite.default-forced-libs=
+
+#
+# Allow supported JavaScript features required by a gadget to be externalized on demand
+shindig.gadget-rewrite.externalize-feature-libs=false
+
+# Configuration for image rewriter
+shindig.image-rewrite.max-inmem-bytes = 1048576
+shindig.image-rewrite.max-palette-size = 256
+shindig.image-rewrite.allow-jpeg-conversion = true
+shindig.image-rewrite.jpeg-compression = 0.90
+shindig.image-rewrite.min-threshold-bytes = 200
+shindig.image-rewrite.jpeg-retain-subsampling = false
+# Huffman optimization reduces the images size by addition 4-6% without
+# any loss in the quality of the image, but takes extra cpu cycles for
+# computing the optimized huffman tables.
+shindig.image-rewrite.jpeg-huffman-optimization = false
+
+# Configuration for the os:Flash tag
+shindig.flash.min-version = 9.0.115
+
+# Configuration for template rewriter
+shindig.template-rewrite.extension-tag-namespace=http://ns.opensocial.org/2009/extensions
+
+# These values provide default TTLs for HTTP responses that don't use caching headers.
+shindig.cache.http.defaultTtl=3600000
+shindig.cache.http.negativeCacheTtl=60000
+
+# Amount of time after which the entry in cache should be considered for a refetch for a
+# non-userfacing internal fetch when the response is strict-no-cache.
+shindig.cache.http.strict-no-cache-resource.refetch-after-ms=-1
+
+# A default refresh interval for XML files, since there is no natural way for developers to
+# specify this value, and most HTTP responses don't include good cache control headers.
+shindig.cache.xml.refreshInterval=300000
+
+# Add entries in the form shindig.cache.lru.<name>.capacity to specify capacities for different
+# caches when using the LruCacheProvider.
+# It is highly recommended that the EhCache implementation be used instead of the LRU cache.
+shindig.cache.lru.default.capacity=1000
+shindig.cache.lru.expressions.capacity=1000
+shindig.cache.lru.gadgetSpecs.capacity=1000
+shindig.cache.lru.messageBundles.capacity=1000
+shindig.cache.lru.httpResponses.capacity=10000
+
+# The location of the EhCache configuration file.
+shindig.cache.ehcache.config=res://org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml
+
+# True to enable JMX integration with cache stats
+shindig.cache.ehcache.jmx.enabled=true
+
+# true to enable JMX stats.
+shindig.cache.ehcache.jmx.stats=true
+
+# true to skip expensive encoding detection.
+# if true, will only attempt to validate utf-8. Assumes all other encodings are ISO-8859-1.
+shindig.http.fast-encoding-detection=true
+
+# Configuration for the HttpFetcher
+# Connection timeout, in milliseconds, for requests.
+shindig.http.client.connection-timeout-ms=5000
+
+# Maximum size, in bytes, of the object we fetched, 0 == no limit
+shindig.http.client.max-object-size-bytes=0
+
+# Strict-mode parsing for proxy and concat URIs ensures that the authority/host and path
+# for the URIs match precisely what is found in the container config for it. This is
+# useful where statistics and traffic routing patterns, typically in large installations,
+# key on hostname (and occasionally path). Enforcing this does come at the cost that
+# mismatches break, which in turn mandates that URI generation always happen in consistent
+# fashion, ie. by the class itself or tightly controlled code.
+shindig.uri.proxy.use-strict-parsing=false
+shindig.uri.concat.use-strict-parsing=false
+
+# Host:port of the proxy to use while fetching urls. Leave blank if proxy is
+# not to be used.
+org.apache.shindig.gadgets.http.basicHttpFetcherProxy=
+
+org.apache.shindig.serviceExpirationDurationMinutes=60
+
+#
+# Older versions of shindig used 'data' in the json-rpc response format
+# The spec calls for using 'result' instead, however to avoid breakage we
+# allow you to set it back to the old way here
+#
+# valid values are
+#  result  - new form
+#  data    - old broken form
+#  both    - return both fields for full compatibility
+#
+shindig.json-rpc.result-field=result
+
+# Remap "Internal server error"s received from the basicHttpFetcherProxy server to
+# "Bad Gateway error"s, so that it is clear to the user that the proxy server is
+# the one that threw the exception.
+shindig.accelerate.remapInternalServerError=true
+shindig.proxy.remapInternalServerError=true
+
+# Add debug data when using VanillaCajaHtmlParser.
+vanillaCajaParser.needsDebugData=true
+
+# Allow non-SSL OAuth 2.0 bearer tokens
+org.apache.shindig.auth.oauth2-require-ssl=false
+
+# Set gadget param in proxied uri as authority if this is true
+org.apache.shindig.gadgets.uri.setAuthorityAsGadgetParam=false
+
+# Maximum Get Url size limit
+org.apache.shindig.gadgets.uri.urlMaxLength=2048
+
+# Default cachettl value for versioned url in seconds. Here default value is 1 year.
+org.apache.shindig.gadgets.servlet.longLivedRefreshSec=31536000