Author: angelo.vandersijpt at luminis.eu Date: Tue Oct 19 16:11:28 2010 New Revision: 196
Log: AMDATU-124 The Shindig bundle now uses a Managed Service to get the Shindig configuration. Added: trunk/platform-bundles/filebased-configuration/src/main/resources/conf/org.amdatu.platform.shindig.application.cfg trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/module/ConfigurationAdminGuiceModule.java Removed: trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/module/PropertiesModule.java trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/service/ShindigConfigurator.java Modified: trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/osgi/Activator.java trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/service/ShindigRegistrationServiceImpl.java Added: trunk/platform-bundles/filebased-configuration/src/main/resources/conf/org.amdatu.platform.shindig.application.cfg ============================================================================== --- (empty file) +++ trunk/platform-bundles/filebased-configuration/src/main/resources/conf/org.amdatu.platform.shindig.application.cfg Tue Oct 19 16:11:28 2010 @@ -0,0 +1,121 @@ +# 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://conf/container.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=/dashboard/authorize.jsp +shindig.oauth.legacy-body-signing=true +shindig.oauth.enable-oauth-1.0=true +shindig.oauth.enable-signed-callbacks=true + +### Outbound OAuth support +shindig.signing.state-key= +shindig.signing.key-name=amdatu_public_key +#shindig.signing.key-file=res://conf/oauthkey.pem +shindig.signing.global-callback-url=http://${server.hostname}:${server.port}/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=link,script,embed,img,style +shindig.content-rewrite.expires=86400 +shindig.content-rewrite.proxy-url=/gadgets/proxy?url= +shindig.content-rewrite.concat-url=/gadgets/concat? + +# +# 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:core.io +shindig.gadget-rewrite.default-forced-libs= + +# 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.75 +shindig.image-rewrite.min-threshold-bytes = 200 + +# 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=0 +shindig.cache.http.negativeCacheTtl=0 + +# 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. +# this setting (1) prevents the XML files to be cached forever, handy during development +shindig.cache.xml.refreshInterval=1 + +# 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=15000 + +# Maximum size, in bytes, of the object we fetched, 0 == no limit +shindig.http.client.max-object-size-bytes=0 + +# true to force strict content type checking for requests made to API endpoints. +# E.g. require application/json for JSON-RPC +shindig.api.disallow-unknown-content-types=true + +socialsite.http.session.timeout=3600 \ No newline at end of file Added: trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/module/ConfigurationAdminGuiceModule.java ============================================================================== --- (empty file) +++ trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/module/ConfigurationAdminGuiceModule.java Tue Oct 19 16:11:28 2010 @@ -0,0 +1,55 @@ +/* + Copyright (C) 2010 Amdatu.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.amdatu.platform.shindig.application.module; + +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.Properties; + +import com.google.inject.AbstractModule; +import com.google.inject.name.Names; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedService; + +/** + * A Guice Module that provides bindings for key-value pairs in a Configuration. Register + * and instance of this object with the service PID to use, and the object can then + * be registered to a Guice injector as a module. + */ +public class ConfigurationAdminGuiceModule extends AbstractModule implements ManagedService { + private volatile Properties m_properties = new Properties(); + + @Override + protected void configure() { + // We make a copy of the properties, since we don't know what bindProperties does with them. + Names.bindProperties(binder(), new Properties(m_properties)); + } + + public void updated(Dictionary dictionary) throws ConfigurationException { + m_properties = copyFromDictionary(dictionary); + } + + private Properties copyFromDictionary(Dictionary source) { + Properties properties = new Properties(); + Enumeration keys = source.keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + properties.put(key, source.get(key)); + } + return properties; + } +} Modified: trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/osgi/Activator.java ============================================================================== --- trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/osgi/Activator.java (original) +++ trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/osgi/Activator.java Tue Oct 19 16:11:28 2010 @@ -24,6 +24,7 @@ import org.amdatu.platform.shindig.application.GadgetStore; import org.amdatu.platform.shindig.application.OAuthModule; import org.amdatu.platform.shindig.application.SocialApiModule; +import org.amdatu.platform.shindig.application.module.ConfigurationAdminGuiceModule; import org.amdatu.platform.shindig.application.module.OAuthModuleImpl; import org.amdatu.platform.shindig.application.module.SocialApiModuleImpl; import org.amdatu.platform.shindig.application.persistence.CassandraAppDataServiceStore; @@ -37,8 +38,7 @@ import org.apache.shindig.social.opensocial.spi.AppDataService; import org.ops4j.pax.web.service.WebContainer; import org.osgi.framework.BundleContext; -import org.osgi.service.cm.ConfigurationAdmin; -import org.osgi.service.cm.ManagedService; +import org.osgi.framework.Constants; import org.osgi.service.log.LogService; import org.osgi.service.useradmin.UserAdmin; @@ -52,7 +52,7 @@ public final static String RESOURCE_ID = "gadgets"; // The PID for Shindig specific configuration properties - public final static String SHINDIG_CONFIG_PID = ShindigRegistrationServiceImpl.class.getName(); + public final static String SHINDIG_CONFIG_PID = "org.amdatu.platform.shindig.application"; @Override public void init(BundleContext context, DependencyManager manager) throws Exception { @@ -102,16 +102,25 @@ .setInterface(OAuthModule.class.getName(), null) .add(createServiceDependency().setService(LogService.class).setRequired(true)) .add(createServiceDependency().setService(OAuthStore.class).setRequired(true))); + + // Create the configuration module + manager.add( + createComponent() + .setInterface(ConfigurationAdminGuiceModule.class.getName(), null) + .setImplementation(ConfigurationAdminGuiceModule.class) + .add(createConfigurationDependency().setPid(SHINDIG_CONFIG_PID).setPropagate(true))); // Register the Shindig registration service manager.add( createComponent() .setImplementation(ShindigRegistrationServiceImpl.class) - .setInterface(new String[]{ManagedService.class.getName(), ResourceProvider.class.getName()}, null) + .setInterface(ResourceProvider.class.getName(), null) .add(createServiceDependency().setService(LogService.class).setRequired(true)) - .add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true)) .add(createServiceDependency().setService(SocialApiModule.class).setRequired(true)) .add(createServiceDependency().setService(OAuthModule.class).setRequired(true)) + .add(createServiceDependency() + .setService(ConfigurationAdminGuiceModule.class, "("+ Constants.SERVICE_PID + "=" + SHINDIG_CONFIG_PID + ")") + .setRequired(true)) .add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true)) .add(createServiceDependency().setService(WebContainer.class).setRequired(true))); } Modified: trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/service/ShindigRegistrationServiceImpl.java ============================================================================== --- trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/service/ShindigRegistrationServiceImpl.java (original) +++ trunk/platform-bundles/shindig-application/src/main/java/org/amdatu/platform/shindig/application/service/ShindigRegistrationServiceImpl.java Tue Oct 19 16:11:28 2010 @@ -28,7 +28,6 @@ import java.io.InputStream; import java.net.URL; import java.util.ArrayList; -import java.util.Dictionary; import java.util.List; import java.util.Properties; @@ -41,7 +40,7 @@ import org.amdatu.platform.httpcontext.ResourceProvider; import org.amdatu.platform.shindig.application.OAuthModule; import org.amdatu.platform.shindig.application.SocialApiModule; -import org.amdatu.platform.shindig.application.module.PropertiesModule; +import org.amdatu.platform.shindig.application.module.ConfigurationAdminGuiceModule; import org.amdatu.platform.shindig.application.oauth.OAuthServlet; import org.apache.felix.dm.Component; import org.apache.shindig.auth.AuthenticationServletFilter; @@ -51,9 +50,6 @@ import org.apache.shindig.protocol.JsonRpcServlet; import org.ops4j.pax.web.service.WebContainer; import org.osgi.framework.BundleContext; -import org.osgi.service.cm.ConfigurationAdmin; -import org.osgi.service.cm.ConfigurationException; -import org.osgi.service.cm.ManagedService; import org.osgi.service.http.HttpContext; import org.osgi.service.http.HttpService; import org.osgi.service.http.NamespaceException; @@ -64,7 +60,7 @@ * resources. * @author ivol */ -public class ShindigRegistrationServiceImpl implements ManagedService, ResourceProvider { +public class ShindigRegistrationServiceImpl implements ResourceProvider { /** * This a path to a fake servlet used to initialize the Guice context. This servlet is registered *before* all other * servlets and it activates a common HttpContext in its {@link HttpServlet#init(javax.servlet.ServletConfig)} @@ -95,10 +91,10 @@ private volatile WebContainer m_httpService; private volatile Component m_httpContextComponent; private volatile LogService m_logService; - private volatile ConfigurationAdmin m_configurationAdmin; private volatile HttpContextServiceFactory m_httpContextFactoryService; private volatile SocialApiModule m_socialApiModule; private volatile OAuthModule m_oAuthModule; + private volatile ConfigurationAdminGuiceModule m_shindigConfigurationModule; // Other instance variables private boolean m_jmxInitialized; @@ -127,13 +123,11 @@ m_logService.log(LogService.LOG_INFO, "Starting " + getClass().getName() + " service"); try { - // Initialize default configuration if not yet available - initializeConfiguration(); - // Initialize the GUICE context. initGuiceInjector(m_httpContext); int retryCount = 0; while (m_servletContext == null && retryCount < 5) { + // TODO The servlet registration is asynchronous? Really? try { System.out.println("Fake Guice servlet not yet available, sleeping for 1 second... (" + (5-retryCount) + " retries left)"); Thread.sleep(1000); @@ -145,11 +139,11 @@ // Register statics, servlets and filters. This can only be done after initializing // the Guice context, for that reason we do it here. registerResources(); - } catch (IOException e) { - m_logService.log(LogService.LOG_ERROR, "Shindig service could not be started due to error", e); - } catch (ServletException e) { + } + catch (ServletException e) { m_logService.log(LogService.LOG_ERROR, "Shindig service could not be started due to error", e); - } catch (NamespaceException e) { + } + catch (NamespaceException e) { m_logService.log(LogService.LOG_ERROR, "Shindig service could not be started due to error", e); } @@ -217,7 +211,6 @@ /** * This method sets the given {@link HttpService} object and initializes all Shindig-specific servlets. * Since it can only be invoked when the Guice context is available, it is invoked from there - * @param service the service to set */ private void registerResources() { try { @@ -308,7 +301,7 @@ List<Module> modules = new ArrayList<Module>(); if (moduleNames != null) { // First add the properties module - modules.add(new PropertiesModule(m_logService, m_configurationAdmin)); + modules.add(m_shindigConfigurationModule); // Now add all Guice-injected modules for (String moduleName : moduleNames) { @@ -379,21 +372,6 @@ }); } - /** - * Initialize Shindig configuration. - * @throws IOException In case configuration could not be initialized - */ - private void initializeConfiguration() throws IOException { - // Set the defaults, if the configuration properties do not yet exist - new ShindigConfigurator(m_configurationAdmin, m_logService).setDefaultConfiguration(); - } - - @SuppressWarnings("unchecked") - public void updated(Dictionary configuration) throws ConfigurationException { - // TODO: When Shindig configuration is updated it might be a good idea to restart Shindig - // with that new configuration - } - public URL getResource(String name) { return null; }
