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/04/02 11:38:41 UTC
svn commit: r1670864 - in
/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal:
runtime/ whiteboard/ whiteboard/tracker/
Author: cziegeler
Date: Thu Apr 2 09:38:40 2015
New Revision: 1670864
URL: http://svn.apache.org/r1670864
Log:
FELIX-4841 : Support HttpSessionIdListener. Initial work tracking the listener
Added:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java (with props)
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.java (with props)
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java?rev=1670864&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java Thu Apr 2 09:38:40 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.http.HttpSessionIdListener;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Info object for registered http session id listeners
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public final class HttpSessionIdListenerInfo extends ListenerInfo<HttpSessionIdListener>
+{
+ public HttpSessionIdListenerInfo(final ServiceReference<HttpSessionIdListener> ref)
+ {
+ super(ref);
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/HttpSessionIdListenerInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java?rev=1670864&r1=1670863&r2=1670864&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java Thu Apr 2 09:38:40 2015
@@ -24,6 +24,7 @@ import java.util.TreeMap;
import javax.annotation.Nonnull;
import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionIdListenerInfo;
import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
@@ -95,6 +96,18 @@ public final class ListenerRegistry
final ContextHandler contextHandler)
{
getRegistryForContext(contextHandler).removeListener(info);
+ }
+
+ void addListener(@Nonnull final HttpSessionIdListenerInfo info,
+ final ContextHandler contextHandler)
+ {
+ getRegistryForContext(contextHandler).addListener(info);
+ }
+
+ void removeListener(@Nonnull final HttpSessionIdListenerInfo info,
+ final ContextHandler contextHandler)
+ {
+ getRegistryForContext(contextHandler).removeListener(info);
}
void addListener(@Nonnull final HttpSessionListenerInfo info,
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java?rev=1670864&r1=1670863&r2=1670864&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java Thu Apr 2 09:38:40 2015
@@ -34,9 +34,11 @@ import javax.servlet.ServletRequestListe
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionIdListenerInfo;
import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
@@ -65,6 +67,9 @@ public final class PerContextEventListen
/** Session listeners. */
private final Map<ServiceReference<HttpSessionListener>, HttpSessionListener> sessionListeners = new ConcurrentSkipListMap<ServiceReference<HttpSessionListener>, HttpSessionListener>();
+ /** Session id listeners. */
+ private final Map<ServiceReference<HttpSessionIdListener>, HttpSessionIdListener> sessionIdListeners = new ConcurrentSkipListMap<ServiceReference<HttpSessionIdListener>, HttpSessionIdListener>();
+
/** Request listeners. */
private final Map<ServiceReference<ServletRequestListener>, ServletRequestListener> requestListeners = new ConcurrentSkipListMap<ServiceReference<ServletRequestListener>, ServletRequestListener>();
@@ -200,6 +205,35 @@ public final class PerContextEventListen
if (service != null)
{
info.ungetService(bundle, service);
+ }
+ }
+
+ /**
+ * Add session id listener
+ *
+ * @param info
+ */
+ void addListener(@Nonnull final HttpSessionIdListenerInfo info)
+ {
+ final HttpSessionIdListener service = info.getService(bundle);
+ if (service != null)
+ {
+ this.sessionIdListeners.put(info.getServiceReference(),
+ service);
+ }
+ }
+
+ /**
+ * Remove session id listener
+ *
+ * @param info
+ */
+ void removeListener(@Nonnull final HttpSessionIdListenerInfo info)
+ {
+ final HttpSessionIdListener service = this.sessionIdListeners.remove(info.getServiceReference());
+ if (service != null)
+ {
+ info.ungetService(bundle, service);
}
}
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=1670864&r1=1670863&r2=1670864&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 Thu Apr 2 09:38:40 2015
@@ -43,6 +43,7 @@ import org.apache.felix.http.base.intern
import org.apache.felix.http.base.internal.runtime.AbstractInfo;
import org.apache.felix.http.base.internal.runtime.FilterInfo;
import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionIdListenerInfo;
import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
import org.apache.felix.http.base.internal.runtime.ResourceInfo;
import org.apache.felix.http.base.internal.runtime.ServletContextAttributeListenerInfo;
@@ -372,20 +373,23 @@ public final class ServletContextHelperM
{
final List<ContextHandler> handlerList = this.getMatchingContexts(info);
this.servicesMap.put(info, handlerList);
- for(final ContextHandler h : handlerList)
- {
- this.registerWhiteboardService(h, info);
- }
if (handlerList.isEmpty())
{
this.serviceFailures.put(info, FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING);
}
+ else
+ {
+ for(final ContextHandler h : handlerList)
+ {
+ this.registerWhiteboardService(h, info);
+ }
+ }
}
}
else
{
final String type = info.getClass().getSimpleName().substring(0, info.getClass().getSimpleName().length() - 4);
- SystemLogger.debug("Ignoring " + type + " service " + info.getServiceReference());
+ SystemLogger.debug("Ignoring invalid " + type + " service " + info.getServiceReference());
this.serviceFailures.put(info, FAILURE_REASON_VALIDATION_FAILED);
}
}
@@ -419,7 +423,7 @@ public final class ServletContextHelperM
/**
* Register whiteboard service in the http service
- * @param contextInfo Context info
+ * @param handler Context handler
* @param info Whiteboard service info
*/
private void registerWhiteboardService(final ContextHandler handler, final WhiteboardServiceInfo<?> info)
@@ -451,6 +455,10 @@ public final class ServletContextHelperM
{
this.listenerRegistry.addListener((HttpSessionAttributeListenerInfo) info, handler);
}
+ else if ( info instanceof HttpSessionIdListenerInfo )
+ {
+ this.listenerRegistry.addListener((HttpSessionIdListenerInfo) info, handler);
+ }
else if ( info instanceof ServletRequestListenerInfo )
{
this.listenerRegistry.addListener((ServletRequestListenerInfo) info, handler);
@@ -460,21 +468,21 @@ public final class ServletContextHelperM
this.listenerRegistry.addListener((ServletRequestAttributeListenerInfo) info, handler);
}
}
- catch (RegistrationFailureException e)
+ catch (final RegistrationFailureException e)
{
serviceFailures.put(e.getInfo(), e.getErrorCode());
- SystemLogger.error("Exception while adding servlet", e);
+ SystemLogger.error("Exception while registering whiteboard service " + info.getServiceReference(), e);
}
- catch (RuntimeException e)
+ catch (final RuntimeException e)
{
serviceFailures.put(info, FAILURE_REASON_UNKNOWN);
- throw e;
+ SystemLogger.error("Exception while registering whiteboard service " + info.getServiceReference(), e);
}
}
/**
* Unregister whiteboard service from the http service
- * @param contextInfo Context info
+ * @param handler Context handler
* @param info Whiteboard service info
*/
private void unregisterWhiteboardService(final ContextHandler handler, final WhiteboardServiceInfo<?> info)
@@ -506,6 +514,10 @@ public final class ServletContextHelperM
{
this.listenerRegistry.removeListener((HttpSessionAttributeListenerInfo) info, handler);
}
+ else if ( info instanceof HttpSessionIdListenerInfo )
+ {
+ this.listenerRegistry.removeListener((HttpSessionIdListenerInfo) info, handler);
+ }
else if ( info instanceof ServletRequestListenerInfo )
{
this.listenerRegistry.removeListener((ServletRequestListenerInfo) info, handler);
@@ -515,7 +527,7 @@ public final class ServletContextHelperM
this.listenerRegistry.removeListener((ServletRequestAttributeListenerInfo) info, handler);
}
}
- catch (RegistrationFailureException e)
+ catch (final RegistrationFailureException e)
{
serviceFailures.put(e.getInfo(), e.getErrorCode());
SystemLogger.error("Exception while removing servlet", e);
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.java?rev=1670864&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.java Thu Apr 2 09:38:40 2015
@@ -0,0 +1,57 @@
+/*
+ * 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.http.HttpSessionIdListener;
+
+import org.apache.felix.http.base.internal.runtime.HttpSessionIdListenerInfo;
+import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
+import org.apache.felix.http.base.internal.whiteboard.ServletContextHelperManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+
+public final class HttpSessionIdListenerTracker extends AbstractReferenceTracker<HttpSessionIdListener>
+{
+
+ private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+ {
+ try
+ {
+ return btx.createFilter(String.format("(&(objectClass=%s)(%s=*)(!(%s~=false)))",
+ HttpSessionIdListener.class.getName(),
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER,
+ HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+ }
+ 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 HttpSessionIdListenerTracker(final BundleContext context, final ServletContextHelperManager manager)
+ {
+ super(manager, context, createFilter(context));
+ }
+
+ @Override
+ protected WhiteboardServiceInfo<HttpSessionIdListener> getServiceInfo(final ServiceReference<HttpSessionIdListener> ref) {
+ return new HttpSessionIdListenerInfo(ref);
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/tracker/HttpSessionIdListenerTracker.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/HttpSessionIdListenerTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain