You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2015/02/01 18:38:35 UTC
svn commit: r1656336 - in
/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal:
runtime/ whiteboard/ whiteboard/tracker/
Author: cziegeler
Date: Sun Feb 1 17:38:35 2015
New Revision: 1656336
URL: http://svn.apache.org/r1656336
Log:
FELIX-4060 : Implement HTTP Service Update (RFC-189)
Added:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java (with props)
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java (with props)
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextListenerTracker.java
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java?rev=1656336&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java Sun Feb 1 17:38:35 2015
@@ -0,0 +1,36 @@
+/*
+ * 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.felix.http.base.internal.runtime;
+
+import javax.servlet.ServletContextAttributeListener;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Info object for registered servlet context attribute listeners
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public final class ServletContextAttributeListenerInfo extends WhiteboardServiceInfo<ServletContextAttributeListener>
+{
+ public ServletContextAttributeListenerInfo(final ServiceReference<ServletContextAttributeListener> ref)
+ {
+ super(ref);
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextAttributeListenerInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java?rev=1656336&r1=1656335&r2=1656336&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java Sun Feb 1 17:38:35 2015
@@ -18,14 +18,18 @@ package org.apache.felix.http.base.inter
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nonnull;
import javax.servlet.ServletContext;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.apache.felix.http.base.internal.runtime.ContextInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
import org.osgi.framework.Bundle;
import org.osgi.service.http.context.ServletContextHelper;
@@ -41,8 +45,12 @@ public final class ContextHandler implem
/** The shared part of the servlet context. */
private final ServletContext sharedContext;
+ /** Servlet context listeners. */
private final Map<Long, ServletContextListener> listeners = new HashMap<Long, ServletContextListener>();
+ /** Servlet context attribute listeners. */
+ private final Map<Long, ServletContextAttributeListener> contextAttributeListeners = new ConcurrentHashMap<Long, ServletContextAttributeListener>();
+
/**
* Create new handler.
* @param info
@@ -51,7 +59,35 @@ public final class ContextHandler implem
public ContextHandler(final ContextInfo info, final ServletContext webContext)
{
this.info = info;
- this.sharedContext = new SharedServletContextImpl(webContext, info.getPrefix(), info.getName());
+ this.sharedContext = new SharedServletContextImpl(webContext,
+ info.getPrefix(),
+ info.getName(),
+ new ServletContextAttributeListener() {
+
+ @Override
+ public void attributeReplaced(final ServletContextAttributeEvent event) {
+ for(final ServletContextAttributeListener l : contextAttributeListeners.values())
+ {
+ l.attributeReplaced(event);
+ }
+ }
+
+ @Override
+ public void attributeRemoved(final ServletContextAttributeEvent event) {
+ for(final ServletContextAttributeListener l : contextAttributeListeners.values())
+ {
+ l.attributeReplaced(event);
+ }
+ }
+
+ @Override
+ public void attributeAdded(final ServletContextAttributeEvent event) {
+ for(final ServletContextAttributeListener l : contextAttributeListeners.values())
+ {
+ l.attributeReplaced(event);
+ }
+ }
+ });
}
/**
@@ -143,6 +179,24 @@ public final class ContextHandler implem
}
}
+ public void addListener(@Nonnull final Bundle bundle, @Nonnull final ServletContextAttributeListenerInfo info)
+ {
+ final ServletContextAttributeListener service = bundle.getBundleContext().getServiceObjects(info.getServiceReference()).getService();
+ if ( service != null )
+ {
+ this.contextAttributeListeners.put(info.getServiceId(), service);
+ }
+ }
+
+ public void removeListener(@Nonnull final Bundle bundle, @Nonnull final ServletContextAttributeListenerInfo info)
+ {
+ final ServletContextAttributeListener service = this.contextAttributeListeners.remove(info.getServiceId());
+ if ( service != null )
+ {
+ bundle.getBundleContext().getServiceObjects(info.getServiceReference()).ungetService(service);
+ }
+ }
+
private static final class ContextHolder
{
public long counter;
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java?rev=1656336&r1=1656335&r2=1656336&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java Sun Feb 1 17:38:35 2015
@@ -30,6 +30,7 @@ import javax.servlet.ServletContext;
import org.apache.felix.http.base.internal.runtime.ContextInfo;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.ResourceInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
@@ -316,6 +317,10 @@ public final class ServletContextHelperM
{
this.httpService.registerResource(handler, (ResourceInfo)info);
}
+ else if ( info instanceof ServletContextAttributeListenerInfo )
+ {
+ handler.addListener(this.bundle, (ServletContextAttributeListenerInfo)info );
+ }
}
/**
@@ -337,5 +342,9 @@ public final class ServletContextHelperM
{
this.httpService.unregisterResource(handler, (ResourceInfo)info);
}
+ else if ( info instanceof ServletContextAttributeListenerInfo )
+ {
+ handler.removeListener(this.bundle, (ServletContextAttributeListenerInfo)info );
+ }
}
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java?rev=1656336&r1=1656335&r2=1656336&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/SharedServletContextImpl.java Sun Feb 1 17:38:35 2015
@@ -31,6 +31,8 @@ import javax.servlet.FilterRegistration;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
+import javax.servlet.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.SessionCookieConfig;
@@ -52,10 +54,12 @@ public class SharedServletContextImpl im
private final Map<String, Object> attributes = new ConcurrentHashMap<String, Object>();
private final String contextPath;
private final String name;
+ private final ServletContextAttributeListener attributeListener;
public SharedServletContextImpl(final ServletContext webContext,
final String name,
- final String prefix)
+ final String prefix,
+ final ServletContextAttributeListener servletContextAttributeListener)
{
this.context = webContext;
if ( prefix == null )
@@ -67,6 +71,7 @@ public class SharedServletContextImpl im
this.contextPath = webContext.getContextPath() + prefix;
}
this.name = name;
+ this.attributeListener = servletContextAttributeListener;
}
@Override
@@ -384,11 +389,11 @@ public class SharedServletContextImpl im
@Override
public void removeAttribute(final String name)
{
- Object oldValue = this.attributes.remove(name);
+ final Object oldValue = this.attributes.remove(name);
if (oldValue != null)
{
- //this.attributeListener.attributeRemoved(new ServletContextAttributeEvent(this, name, oldValue));
+ this.attributeListener.attributeRemoved(new ServletContextAttributeEvent(this, name, oldValue));
}
}
@@ -405,11 +410,11 @@ public class SharedServletContextImpl im
if (oldValue == null)
{
- //this.attributeListener.attributeAdded(new ServletContextAttributeEvent(this, name, value));
+ this.attributeListener.attributeAdded(new ServletContextAttributeEvent(this, name, value));
}
else
{
- //this.attributeListener.attributeReplaced(new ServletContextAttributeEvent(this, name, oldValue));
+ this.attributeListener.attributeReplaced(new ServletContextAttributeEvent(this, name, oldValue));
}
}
}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java?rev=1656336&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java Sun Feb 1 17:38:35 2015
@@ -0,0 +1,81 @@
+/*
+ * 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.felix.http.base.internal.whiteboard.tracker;
+
+import javax.servlet.ServletContextAttributeListener;
+
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
+import org.apache.felix.http.base.internal.whiteboard.ServletContextHelperManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public final class ServletContextAttributeListenerTracker extends AbstractReferenceTracker<ServletContextAttributeListener>
+{
+ private final ServletContextHelperManager contextManager;
+
+ /** TODO Currently under discussion. */
+ private static final String OPT_IN_PROP = "osgi.http.whiteboard.listener";
+
+ private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+ {
+ try
+ {
+ return btx.createFilter(String.format("(&(objectClass=%s)(%s=*))",
+ ServletContextAttributeListener.class.getName(),
+ OPT_IN_PROP));
+ }
+ catch ( final InvalidSyntaxException ise)
+ {
+ // we can safely ignore it as the above filter is a constant
+ }
+ return null; // we never get here - and if we get an NPE which is fine
+ }
+
+ public ServletContextAttributeListenerTracker(final BundleContext context, final ServletContextHelperManager manager)
+ {
+ super(context, createFilter(context));
+ this.contextManager = manager;
+ }
+
+ @Override
+ protected void added(final ServiceReference<ServletContextAttributeListener> ref)
+ {
+ final ServletContextAttributeListenerInfo info = new ServletContextAttributeListenerInfo(ref);
+
+ if ( info.isValid() )
+ {
+ this.contextManager.addWhiteboardService(info);
+ }
+ else
+ {
+ SystemLogger.debug("Ignoring ServletContextAttributeListenerInfo service " + ref);
+ }
+ }
+
+ @Override
+ protected void removed(final ServiceReference<ServletContextAttributeListener> ref)
+ {
+ final ServletContextAttributeListenerInfo info = new ServletContextAttributeListenerInfo(ref);
+
+ if ( info.isValid() )
+ {
+ this.contextManager.removeWhiteboardService(info);
+ }
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextAttributeListenerTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextListenerTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextListenerTracker.java?rev=1656336&r1=1656335&r2=1656336&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextListenerTracker.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/ServletContextListenerTracker.java Sun Feb 1 17:38:35 2015
@@ -64,7 +64,7 @@ public final class ServletContextListene
}
else
{
- SystemLogger.debug("Ignoring Filter service " + ref);
+ SystemLogger.debug("Ignoring ServletContextListenerInfo service " + ref);
}
}