incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r906963 - in /sling/trunk: bundles/engine/ bundles/engine/src/main/java/org/apache/sling/engine/impl/ launchpad/base/ launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/ launchpad/base/src/main/java/org/apache/sling/launchpad...
Date Fri, 05 Feb 2010 15:16:04 GMT
Author: cziegeler
Date: Fri Feb  5 15:15:53 2010
New Revision: 906963

URL: http://svn.apache.org/viewvc?rev=906963&view=rev
Log:
SLING-983 : Add sling.properties file to configuration status page

Modified:
    sling/trunk/bundles/engine/pom.xml
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
    sling/trunk/launchpad/base/pom.xml
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
    sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java

Modified: sling/trunk/bundles/engine/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/pom.xml?rev=906963&r1=906962&r2=906963&view=diff
==============================================================================
--- sling/trunk/bundles/engine/pom.xml (original)
+++ sling/trunk/bundles/engine/pom.xml Fri Feb  5 15:15:53 2010
@@ -152,7 +152,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.webconsole</artifactId>
-            <version>1.2.0</version>
+            <version>2.0.7-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=906963&r1=906962&r2=906963&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Fri Feb  5 15:15:53 2010
@@ -75,7 +75,6 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.http.HttpContext;
@@ -181,7 +180,7 @@
 
     private boolean allowTrace = DEFAULT_ALLOW_TRACE;
 
-    private ServiceRegistration printerRegistration;
+    private Object printerRegistration;
 
     // ---------- Servlet API -------------------------------------------------
 
@@ -663,7 +662,7 @@
     protected void deactivate(ComponentContext componentContext) {
         // this reverses the activation setup
         if ( this.printerRegistration != null ) {
-            this.printerRegistration.unregister();
+            WebConsoleConfigPrinter.unregister(this.printerRegistration);
             this.printerRegistration = null;
         }
 

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java?rev=906963&r1=906962&r2=906963&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/WebConsoleConfigPrinter.java
Fri Feb  5 15:15:53 2010
@@ -18,15 +18,26 @@
  */
 package org.apache.sling.engine.impl;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
+import java.net.URL;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import org.apache.felix.webconsole.ConfigurationPrinter;
+import org.apache.felix.webconsole.ModeAwareConfigurationPrinter;
 import org.apache.sling.engine.impl.filter.SlingFilterChainHelper;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This is a configuration printer for the web console which
@@ -35,6 +46,8 @@
  */
 public class WebConsoleConfigPrinter implements ConfigurationPrinter {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(WebConsoleConfigPrinter.class);
+
     private final SlingFilterChainHelper requestFilterChain;
     private final SlingFilterChainHelper innerFilterChain;
 
@@ -44,18 +57,70 @@
         this.innerFilterChain = innerFilterChain;
     }
 
-    public static ServiceRegistration register(final BundleContext bundleContext,
+    private static final class Registration {
+        public ServiceRegistration filterPlugin;
+        public ServiceRegistration propertiesPlugin;
+    }
+
+    public static Object register(final BundleContext bundleContext,
             final SlingFilterChainHelper requestFilterChain,
             final SlingFilterChainHelper innerFilterChain) {
-        final Object service = new WebConsoleConfigPrinter(requestFilterChain, innerFilterChain);
+        final Registration reg = new Registration();
+
+        // first we register the plugin for the filters
+        final WebConsoleConfigPrinter filterPrinter = new WebConsoleConfigPrinter(requestFilterChain,
innerFilterChain);
         final Dictionary<String, String> serviceProps = new Hashtable<String, String>();
         serviceProps.put(Constants.SERVICE_DESCRIPTION,
             "Apache Sling Servlet Filter Configuration Printer");
         serviceProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-        return bundleContext.registerService("org.apache.felix.webconsole.ConfigurationPrinter",
-                                                      service,
-                                                      serviceProps);
+
+        reg.filterPlugin = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                filterPrinter,
+                serviceProps);
+
+        // if the properties are available, we register the second plugin
+        final String propUrl = bundleContext.getProperty("sling.properties.url");
+        if ( propUrl != null ) {
+            // try to read properties
+            Properties props = null;
+            try {
+                final URL url = new URL(propUrl);
+                final InputStream is = url.openStream();
+                final Properties tmp = new Properties();
+                tmp.load(is);
+                props = tmp;
+            } catch (IOException ioe) {
+                LOGGER.warn("Unable to read sling properties from " + propUrl, ioe);
+            }
+            if ( props != null ) {
+                final PropsPlugin propertiesPrinter = new PropsPlugin(props);
+                final Dictionary<String, String> serviceProps2 = new Hashtable<String,
String>();
+                serviceProps2.put(Constants.SERVICE_DESCRIPTION,
+                    "Apache Sling Sling Properties Configuration Printer");
+                serviceProps2.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+
+                reg.propertiesPlugin = bundleContext.registerService(ConfigurationPrinter.class.getName(),
+                        propertiesPrinter,
+                        serviceProps2);
+            }
+        }
+        return reg;
     }
+
+    public static void unregister(final Object reg) {
+        if ( reg instanceof Registration ) {
+            final Registration registration = (Registration)reg;
+            if ( registration.filterPlugin != null) {
+                registration.filterPlugin.unregister();
+                registration.filterPlugin = null;
+            }
+            if ( registration.propertiesPlugin != null) {
+                registration.propertiesPlugin.unregister();
+                registration.propertiesPlugin = null;
+            }
+        }
+    }
+
     /**
      * Return the title for the configuration printer
      * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
@@ -81,6 +146,7 @@
             }
         }
     }
+
     /**
      * Print out the servlet filter chains.
      * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
@@ -94,4 +160,63 @@
         pw.println("Component Filters:");
         printFilterChain(pw, innerFilterChain.getFilterListEntries());
     }
+
+    public static final class PropsPlugin implements ModeAwareConfigurationPrinter {
+
+        private static String HEADLINE = "Apache Sling Launchpad Properties";
+
+        private final Properties props;
+
+        public PropsPlugin(final Properties props) {
+            this.props = props;
+        }
+
+        /**
+         * @see org.apache.felix.webconsole.ConfigurationPrinter#getTitle()
+         */
+        public String getTitle() {
+            return "Sling Properties";
+        }
+
+        /**
+         * Print out the servlet filter chains.
+         * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
+         */
+        public void printConfiguration(PrintWriter pw) {
+            pw.println(HEADLINE);
+            pw.println();
+            SortedSet<Object> keys = new TreeSet<Object>( props.keySet() );
+            for ( Iterator<Object> ki = keys.iterator(); ki.hasNext(); )
+            {
+                final Object key = ki.next();
+                pw.print( key );
+                pw.print(" = ");
+                final Object value = props.get(key);
+                if ( value != null )
+                {
+                    pw.print(value.toString());
+                }
+                pw.println();
+            }
+        }
+
+        public void printConfiguration(PrintWriter printWriter, String mode) {
+            if ( mode != ConfigurationPrinter.MODE_ZIP ) {
+                this.printConfiguration(printWriter);
+            } else {
+                // write into byte array first
+                String contents = null;
+                try {
+                    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                    this.props.store(baos , HEADLINE);
+                    contents = baos.toString("8859_1");
+                } catch (IOException ioe) {
+                    // if something goes wrong here we default to text output
+                    this.printConfiguration(printWriter);
+                    return;
+                }
+                printWriter.write(contents);
+            }
+        }
+    }
 }

Modified: sling/trunk/launchpad/base/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/pom.xml?rev=906963&r1=906962&r2=906963&view=diff
==============================================================================
--- sling/trunk/launchpad/base/pom.xml (original)
+++ sling/trunk/launchpad/base/pom.xml Fri Feb  5 15:15:53 2010
@@ -224,7 +224,7 @@
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.apache.felix.framework</artifactId>
-            <version>2.0.2</version>
+            <version>2.1.0-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java?rev=906963&r1=906962&r2=906963&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
(original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
Fri Feb  5 15:15:53 2010
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -88,19 +89,6 @@
 
     /**
      * The name of the configuration property defining the Sling home directory
-     * (value is "sling.home"). This is a Platform file system directory below
-     * which all runtime data, such as the Felix bundle archives, logfiles, CRX
-     * repository, etc., is located.
-     * <p>
-     * The value of this property, if not set as a system property defaults to
-     * the <i>sling</i> directory in the current working directory.
-     *
-     * @see #SLING_HOME_URL
-     */
-//    public static final String SLING_HOME = "sling.home";
-
-    /**
-     * The name of the configuration property defining the Sling home directory
      * as an URL (value is "sling.home.url").
      * <p>
      * The value of this property is assigned the value of
@@ -446,6 +434,14 @@
         runtimeProps.put(SharedConstants.SLING_HOME, slingHome);
         runtimeProps.put(SLING_HOME_URL, slingHomeFile.toURI().toString());
 
+        // add property file locations
+        runtimeProps.put(SharedConstants.SLING_PROPERTIES, propFile.getAbsolutePath());
+        try {
+            runtimeProps.put(SharedConstants.SLING_PROPERTIES_URL, propFile.toURL().toString());
+        } catch (MalformedURLException e) {
+            // we simple ignore this
+        }
+
         // Perform variable substitution for system properties.
         for (Entry<String, String> entry : runtimeProps.entrySet()) {
             entry.setValue(substVars(entry.getValue(), entry.getKey(), null,

Modified: sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java?rev=906963&r1=906962&r2=906963&view=diff
==============================================================================
--- sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
(original)
+++ sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/SharedConstants.java
Fri Feb  5 15:15:53 2010
@@ -76,4 +76,20 @@
      */
     public static final String DISABLE_PACKAGE_BUNDLE_LOADING = "org.apache.sling.launchpad.disable.package.bundle.loading";
 
+
+    /**
+     * The name of the configuration property defining the Sling properties file
+     * (value is "sling.properties"). This is a Platform file system file
+     * containing the startup configuration of Sling.
+     * @since 2.2
+     */
+    public static final String SLING_PROPERTIES = "sling.properties";
+
+    /**
+     * The name of the configuration property defining the Sling properties url
+     * (value is "sling.properties.url"). This is a url pointing to a resource
+     * containing the startup configuration of Sling.
+     * @since 2.2
+     */
+    public static final String SLING_PROPERTIES_URL = "sling.properties.url";
 }



Mime
View raw message