FELIX-3198 Support generic configuration properties and implement support for basic Session Management configuration through such generic properties.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1196998 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
index 3b67f01..d3ba32e 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
@@ -18,6 +18,9 @@
import org.osgi.framework.BundleContext;
import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import java.util.Hashtable;
@@ -86,6 +89,16 @@
private boolean useHttpsNio;
private boolean registerMBeans;
+ /**
+ * Properties from the configuration not matching any of the
+ * predefined properties. These properties can be accessed from the
+ * getProperty* methods.
+ * <p>
+ * This map is indexed by String objects (the property names) and
+ * the values are just objects as provided by the configuration.
+ */
+ private Map genericProperties = new HashMap();
+
public JettyConfig(BundleContext context)
{
this.context = context;
@@ -197,11 +210,19 @@
this.useHttpNio = getBooleanProperty(props, FELIX_HTTP_NIO, true);
this.useHttpsNio = getBooleanProperty(props, FELIX_HTTPS_NIO, this.useHttpNio);
this.registerMBeans = getBooleanProperty(props, FELIX_HTTP_MBEANS, false);
+
+ // copy rest of the properties
+ Enumeration keys = props.keys();
+ while (keys.hasMoreElements())
+ {
+ Object key = keys.nextElement();
+ this.genericProperties.put(key, props.get(key));
+ }
}
private String getProperty(Dictionary props, String name, String defValue)
{
- Object value = props.get(name);
+ Object value = props.remove(name);
if (value == null)
{
value = this.context.getProperty(name);
@@ -230,6 +251,51 @@
}
}
+ /**
+ * Returns the named generic configuration property from the
+ * configuration or the bundle context. If neither property is defined
+ * return the defValue.
+ */
+ public String getProperty(String name, String defValue) {
+ Object value = this.genericProperties.get(name);
+ if (value == null)
+ {
+ value = this.context.getProperty(name);
+ }
+
+ return value != null ? String.valueOf(value) : defValue;
+ }
+
+ /**
+ * Returns the named generic configuration property from the
+ * configuration or the bundle context. If neither property is defined
+ * return the defValue.
+ */
+ public boolean getBooleanProperty(String name, boolean defValue)
+ {
+ String value = getProperty(name, null);
+ if (value != null)
+ {
+ return (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"));
+ }
+
+ return defValue;
+ }
+
+ /**
+ * Returns the named generic configuration property from the
+ * configuration or the bundle context. If neither property is defined
+ * return the defValue.
+ */
+ public int getIntProperty(String name, int defValue)
+ {
+ try {
+ return Integer.parseInt(getProperty(name, null));
+ } catch (Exception e) {
+ return defValue;
+ }
+ }
+
public void setServiceProperties(Hashtable<String, Object> props)
{
props.put(HTTP_PORT, String.valueOf(this.httpPort));
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index 1dd1c8a..949af3f 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -16,26 +16,28 @@
*/
package org.apache.felix.http.jetty.internal;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.mortbay.jetty.security.HashUserRealm;
-import org.mortbay.jetty.security.SslSelectChannelConnector;
-import org.mortbay.jetty.security.SslSocketConnector;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.Connector;
-import org.mortbay.jetty.bio.SocketConnector;
-import org.mortbay.jetty.handler.StatisticsHandler;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.jetty.servlet.*;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+
import org.apache.felix.http.base.internal.DispatcherServlet;
import org.apache.felix.http.base.internal.EventDispatcher;
import org.apache.felix.http.base.internal.HttpServiceController;
import org.apache.felix.http.base.internal.logger.SystemLogger;
-
-import java.util.Properties;
-import java.util.Dictionary;
-import java.util.Hashtable;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.SessionManager;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.handler.StatisticsHandler;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.HashUserRealm;
+import org.mortbay.jetty.security.SslSelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
public final class JettyService
implements Runnable
@@ -169,10 +171,11 @@
}
Context context = new Context(this.server, "/", Context.SESSIONS);
+ configureSessionManager(context);
context.addEventListener(eventDispatcher);
context.getSessionHandler().addEventListener(eventDispatcher);
context.addServlet(new ServletHolder(this.dispatcher), "/*");
-
+
if (this.config.isRegisterMBeans())
{
this.mbeanServerTracker = new MBeanServerTracker(this.context, this.server);
@@ -300,6 +303,15 @@
this.server.addConnector(connector);
}
+ private void configureSessionManager(final Context context) {
+ final SessionManager manager = context.getSessionHandler().getSessionManager();
+ manager.setSessionCookie(this.config.getProperty(SessionManager.__SessionCookieProperty, SessionManager.__DefaultSessionCookie));
+ manager.setSessionURL(this.config.getProperty(SessionManager.__SessionURLProperty, SessionManager.__DefaultSessionURL));
+ manager.setSessionDomain(this.config.getProperty(SessionManager.__SessionDomainProperty, SessionManager.__DefaultSessionDomain));
+ manager.setSessionPath(this.config.getProperty(SessionManager.__SessionPathProperty, context.getContextPath()));
+ manager.setMaxCookieAge(this.config.getIntProperty(SessionManager.__MaxAgeProperty, -1));
+ }
+
public void run()
{
this.running = true;