You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ja...@apache.org on 2015/02/20 14:26:35 UTC
svn commit: r1661116 [2/3] - in /felix/trunk/http:
base/src/main/java/org/apache/felix/http/base/internal/
base/src/main/java/org/apache/felix/http/base/internal/dispatch/
base/src/main/java/org/apache/felix/http/base/internal/handler/
base/src/main/ja...
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=1661116&r1=1661115&r2=1661116&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 Fri Feb 20 13:26:34 2015
@@ -18,37 +18,19 @@ package org.apache.felix.http.base.inter
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentSkipListMap;
-import java.util.concurrent.ConcurrentSkipListSet;
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 javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
-import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionBindingEvent;
-import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
-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;
-import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
-import org.apache.felix.http.base.internal.runtime.ServletRequestAttributeListenerInfo;
-import org.apache.felix.http.base.internal.runtime.ServletRequestListenerInfo;
-import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceObjects;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.http.context.ServletContextHelper;
public final class ContextHandler implements Comparable<ContextHandler>
@@ -65,53 +47,41 @@ public final class ContextHandler implem
/** A map of all created servlet contexts. Each bundle gets it's own instance. */
private final Map<Long, ContextHolder> perBundleContextMap = new HashMap<Long, ContextHolder>();
- /** Servlet context listeners. */
- private final Map<Long, ServletContextListener> listeners = new HashMap<Long, ServletContextListener>();
-
- /** Servlet context attribute listeners. */
- private final Map<ServiceReference<ServletContextAttributeListener>, ServletContextAttributeListener> contextAttributeListeners =
- new ConcurrentSkipListMap<ServiceReference<ServletContextAttributeListener>, ServletContextAttributeListener>();
-
- /** Session attribute listeners. */
- private final Map<ServiceReference<HttpSessionAttributeListener>, HttpSessionAttributeListener> sessionAttributeListeners =
- new ConcurrentSkipListMap<ServiceReference<HttpSessionAttributeListener>, HttpSessionAttributeListener>();
-
- /** Session listeners. */
- private final Map<ServiceReference<HttpSessionListener>, HttpSessionListener> sessionListeners =
- new ConcurrentSkipListMap<ServiceReference<HttpSessionListener>, HttpSessionListener>();
-
- /** Request listeners. */
- private final Map<ServiceReference<ServletRequestListener>, ServletRequestListener> requestListeners =
- new ConcurrentSkipListMap<ServiceReference<ServletRequestListener>, ServletRequestListener>();
-
- /** Request attribute listeners. */
- private final Map<ServiceReference<ServletRequestAttributeListener>, ServletRequestAttributeListener> requestAttributeListeners =
- new ConcurrentSkipListMap<ServiceReference<ServletRequestAttributeListener>, ServletRequestAttributeListener>();
-
- /** All whiteboard services - servlets, filters, resources. */
- private final Set<WhiteboardServiceInfo<?>> whiteboardServices = new ConcurrentSkipListSet<WhiteboardServiceInfo<?>>();
-
- /**
- * Create new handler.
- * @param info
- * @param webContext
- */
- public ContextHandler(final ServletContextHelperInfo info,
- final ServletContext webContext,
- final Bundle bundle)
+ private final HttpSessionListener sessionListener;
+ private final HttpSessionAttributeListener sessionAttributeListener;
+ private final ServletRequestListener requestListener;
+ private final ServletRequestAttributeListener requestAttributeListener;
+
+ public ContextHandler(ServletContextHelperInfo info,
+ ServletContext webContext,
+ PerContextEventListener eventListener,
+ Bundle bundle)
+ {
+ this(info, webContext, eventListener, eventListener, eventListener, eventListener, eventListener, bundle);
+ }
+
+ public ContextHandler(ServletContextHelperInfo info,
+ ServletContext webContext,
+ ServletContextAttributeListener servletContextAttributeListener,
+ HttpSessionListener sessionListener,
+ HttpSessionAttributeListener sessionAttributeListener,
+ ServletRequestListener requestListener,
+ ServletRequestAttributeListener requestAttributeListener,
+ Bundle bundle)
{
this.info = info;
+ this.sessionListener = sessionListener;
+ this.sessionAttributeListener = sessionAttributeListener;
+ this.requestListener = requestListener;
+ this.requestAttributeListener = requestAttributeListener;
this.bundle = bundle;
this.sharedContext = new SharedServletContextImpl(webContext,
info.getName(),
info.getPath(),
info.getInitParameters(),
- getContextAttributeListener());
+ servletContextAttributeListener);
}
- /**
- * Get the context info
- */
public ServletContextHelperInfo getContextInfo()
{
return this.info;
@@ -131,36 +101,11 @@ public final class ContextHandler implem
public void deactivate()
{
this.ungetServletContext(bundle);
- this.whiteboardServices.clear();
}
- public void initialized(@Nonnull final ServletContextListenerInfo listenerInfo)
+ public ServletContext getSharedContext()
{
- final ServletContextListener listener = listenerInfo.getService(bundle);
- if ( listener != null)
- {
- // no need to sync map - initialized is called in sync
- this.listeners.put(listenerInfo.getServiceId(), listener);
-
- final ServletContext context = this.getServletContext(listenerInfo.getServiceReference().getBundle());
-
- listener.contextInitialized(new ServletContextEvent(context));
- }
- }
-
- public void destroyed(@Nonnull final ServletContextListenerInfo listenerInfo)
- {
- // no need to sync map - destroyed is called in sync
- final ServletContextListener listener = this.listeners.remove(listenerInfo.getServiceId());
- if ( listener != null )
- {
- final ServletContext context = this.getServletContext(listenerInfo.getServiceReference().getBundle());
- listener.contextDestroyed(new ServletContextEvent(context));
- // call unget twice, once for the call in initialized and once for the call in this method(!)
- this.ungetServletContext(listenerInfo.getServiceReference().getBundle());
- this.ungetServletContext(listenerInfo.getServiceReference().getBundle());
- listenerInfo.ungetService(bundle, listener);
- }
+ return sharedContext;
}
public ExtServletContext getServletContext(@Nonnull final Bundle bundle)
@@ -180,10 +125,10 @@ public final class ContextHandler implem
holder.servletContext = new PerBundleServletContextImpl(bundle,
this.sharedContext,
holder.servletContextHelper,
- this.getSessionListener(),
- this.getSessionAttributeListener(),
- this.getServletRequestListener(),
- this.getServletRequestAttributeListener());
+ this.sessionListener,
+ this.sessionAttributeListener,
+ this.requestListener,
+ this.requestAttributeListener);
this.perBundleContextMap.put(key, holder);
}
// TODO - check null for so
@@ -226,289 +171,10 @@ public final class ContextHandler implem
}
}
- /**
- * Add servlet context attribute listener
- * @param info
- */
- public void addListener(@Nonnull final ServletContextAttributeListenerInfo info)
- {
- final ServletContextAttributeListener service = info.getService(bundle);
- if ( service != null )
- {
- this.contextAttributeListeners.put(info.getServiceReference(), service);
- }
- }
-
- /**
- * Remove servlet context attribute listener
- * @param info
- */
- public void removeListener(@Nonnull final ServletContextAttributeListenerInfo info)
- {
- final ServletContextAttributeListener service = this.contextAttributeListeners.remove(info.getServiceReference());
- if ( service != null )
- {
- info.ungetService(bundle, service);
- }
- }
-
- /**
- * Add session attribute listener
- * @param info
- */
- public void addListener(@Nonnull final HttpSessionAttributeListenerInfo info)
- {
- final HttpSessionAttributeListener service = info.getService(bundle);
- if ( service != null )
- {
- this.sessionAttributeListeners.put(info.getServiceReference(), service);
- }
- }
-
- /**
- * Remove session attribute listener
- * @param info
- */
- public void removeListener(@Nonnull final HttpSessionAttributeListenerInfo info)
- {
- final HttpSessionAttributeListener service = this.sessionAttributeListeners.remove(info.getServiceReference());
- if ( service != null )
- {
- info.ungetService(bundle, service);
- }
- }
-
- /**
- * Add session listener
- * @param info
- */
- public void addListener(@Nonnull final HttpSessionListenerInfo info)
- {
- final HttpSessionListener service = info.getService(bundle);
- if ( service != null )
- {
- this.sessionListeners.put(info.getServiceReference(), service);
- }
- }
-
- /**
- * Remove session listener
- * @param info
- */
- public void removeListener(@Nonnull final HttpSessionListenerInfo info)
- {
- final HttpSessionListener service = this.sessionListeners.remove(info.getServiceReference());
- if ( service != null )
- {
- info.ungetService(bundle, service);
- }
- }
-
- /**
- * Add request listener
- * @param info
- */
- public void addListener(@Nonnull final ServletRequestListenerInfo info)
- {
- final ServletRequestListener service = info.getService(bundle);
- if ( service != null )
- {
- this.requestListeners.put(info.getServiceReference(), service);
- }
- }
-
- /**
- * Remove request listener
- * @param info
- */
- public void removeListener(@Nonnull final ServletRequestListenerInfo info)
- {
- final ServletRequestListener service = this.requestListeners.remove(info.getServiceReference());
- if ( service != null )
- {
- info.ungetService(bundle, service);
- }
- }
-
- /**
- * Add request attribute listener
- * @param info
- */
- public void addListener(@Nonnull final ServletRequestAttributeListenerInfo info)
- {
- final ServletRequestAttributeListener service = info.getService(bundle);
- if ( service != null )
- {
- this.requestAttributeListeners.put(info.getServiceReference(), service);
- }
- }
-
- /**
- * Remove request attribute listener
- * @param info
- */
- public void removeListener(@Nonnull final ServletRequestAttributeListenerInfo info)
- {
- final ServletRequestAttributeListener service = this.requestAttributeListeners.remove(info.getServiceReference());
- if ( service != null )
- {
- info.ungetService(bundle, service);
- }
- }
-
private static final class ContextHolder
{
public long counter;
public ExtServletContext servletContext;
public ServletContextHelper servletContextHelper;
}
-
- public HttpSessionAttributeListener getSessionAttributeListener()
- {
- return new HttpSessionAttributeListener() {
-
- @Override
- public void attributeReplaced(final HttpSessionBindingEvent event) {
- for(final HttpSessionAttributeListener l : sessionAttributeListeners.values())
- {
- l.attributeReplaced(event);
- }
- }
-
- @Override
- public void attributeRemoved(final HttpSessionBindingEvent event) {
- for(final HttpSessionAttributeListener l : sessionAttributeListeners.values())
- {
- l.attributeReplaced(event);
- }
- }
-
- @Override
- public void attributeAdded(final HttpSessionBindingEvent event) {
- for(final HttpSessionAttributeListener l : sessionAttributeListeners.values())
- {
- l.attributeReplaced(event);
- }
- }
- };
- }
-
- private ServletContextAttributeListener getContextAttributeListener()
- {
- return 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);
- }
- }
- };
- }
-
- public HttpSessionListener getSessionListener()
- {
- return new HttpSessionListener() {
-
- @Override
- public void sessionCreated(final HttpSessionEvent se) {
- for(final HttpSessionListener l : sessionListeners.values())
- {
- l.sessionCreated(se);
- }
- }
-
- @Override
- public void sessionDestroyed(final HttpSessionEvent se) {
- for(final HttpSessionListener l : sessionListeners.values())
- {
- l.sessionDestroyed(se);
- }
- }
- };
- }
-
- private ServletRequestListener getServletRequestListener()
- {
- return new ServletRequestListener() {
-
- @Override
- public void requestDestroyed(final ServletRequestEvent sre) {
- for(final ServletRequestListener l : requestListeners.values())
- {
- l.requestDestroyed(sre);
- }
- }
-
- @Override
- public void requestInitialized(final ServletRequestEvent sre) {
- for(final ServletRequestListener l : requestListeners.values())
- {
- l.requestInitialized(sre);
- }
- }
- };
- }
-
- private ServletRequestAttributeListener getServletRequestAttributeListener()
- {
- return new ServletRequestAttributeListener() {
-
- @Override
- public void attributeAdded(final ServletRequestAttributeEvent srae) {
- for(final ServletRequestAttributeListener l : requestAttributeListeners.values())
- {
- l.attributeAdded(srae);
- }
- }
-
- @Override
- public void attributeRemoved(final ServletRequestAttributeEvent srae) {
- for(final ServletRequestAttributeListener l : requestAttributeListeners.values())
- {
- l.attributeRemoved(srae);
- }
- }
-
- @Override
- public void attributeReplaced(final ServletRequestAttributeEvent srae) {
- for(final ServletRequestAttributeListener l : requestAttributeListeners.values())
- {
- l.attributeReplaced(srae);
- }
- }
- };
- }
-
- public void addWhiteboardService(final WhiteboardServiceInfo<?> info)
- {
- this.whiteboardServices.add(info);
- }
-
- public void removeWhiteboardService(final WhiteboardServiceInfo<?> info)
- {
- this.whiteboardServices.remove(info);
- }
-
- public Set<WhiteboardServiceInfo<?>> getWhiteboardServices()
- {
- return this.whiteboardServices;
- }
}
Added: 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=1661116&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java Fri Feb 20 13:26:34 2015
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.annotation.Nonnull;
+
+import org.apache.felix.http.base.internal.runtime.ListenerInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
+import org.apache.felix.http.base.internal.runtime.ServletContextListenerInfo;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+public final class ListenerRegistry
+{
+ private final Map<ServletContextHelperInfo, PerContextEventListener> registriesByContext = new TreeMap<ServletContextHelperInfo, PerContextEventListener>();
+
+ private final Bundle bundle;
+
+ public ListenerRegistry(final Bundle bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ public void initialized(@Nonnull final ServletContextListenerInfo listenerInfo,
+ ContextHandler contextHandler)
+ {
+ registriesByContext.get(contextHandler.getContextInfo()).initialized(listenerInfo, contextHandler);
+ }
+
+ public void destroyed(@Nonnull final ServletContextListenerInfo listenerInfo,
+ ContextHandler contextHandler)
+ {
+ registriesByContext.get(contextHandler.getContextInfo()).destroyed(listenerInfo, contextHandler);
+ }
+
+ public <T extends ListenerInfo<?>> void addListener(@Nonnull final T info,
+ final ContextHandler contextHandler)
+ {
+ getRegistryForContext(contextHandler).addListener(info);
+ }
+
+ public <T extends ListenerInfo<?>> void removeListener(@Nonnull final T info,
+ final ContextHandler contextHandler)
+ {
+ getRegistryForContext(contextHandler).removeListener(info);
+ }
+
+ private PerContextEventListener getRegistryForContext(ContextHandler contextHandler)
+ {
+ PerContextEventListener contextRegistry = registriesByContext.get(contextHandler.getContextInfo());
+ if (contextRegistry == null)
+ {
+ throw new IllegalArgumentException("ContextHandler " + contextHandler.getContextInfo().getName() + " is not registered");
+ }
+ return contextRegistry;
+ }
+
+ public PerContextEventListener addContext(ServletContextHelperInfo info)
+ {
+ if (registriesByContext.containsKey(info))
+ {
+ throw new IllegalArgumentException("Context with id " + info.getServiceId() + "is already registered");
+ }
+
+ PerContextEventListener contextRegistry = new PerContextEventListener(bundle);
+ registriesByContext.put(info, contextRegistry);
+ return contextRegistry;
+ }
+
+ public void removeContext(ServletContextHelperInfo info)
+ {
+ registriesByContext.remove(info);
+ }
+
+ public Map<Long, Collection<ServiceReference<?>>> getContextRuntimes()
+ {
+ Map<Long, Collection<ServiceReference<?>>> listenersByContext = new HashMap<Long, Collection<ServiceReference<?>>>();
+ for (ServletContextHelperInfo contextInfo : registriesByContext.keySet())
+ {
+ listenersByContext.put(contextInfo.getServiceId(), registriesByContext.get(contextInfo).getRuntime());
+ }
+ return listenersByContext;
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ListenerRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1661116&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java Fri Feb 20 13:26:34 2015
@@ -0,0 +1,416 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+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 javax.servlet.ServletRequestAttributeEvent;
+import javax.servlet.ServletRequestAttributeListener;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.felix.http.base.internal.runtime.HttpSessionAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HttpSessionListenerInfo;
+import org.apache.felix.http.base.internal.runtime.ListenerInfo;
+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.ServletRequestAttributeListenerInfo;
+import org.apache.felix.http.base.internal.runtime.ServletRequestListenerInfo;
+import org.apache.felix.http.base.internal.util.CollectionUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+public final class PerContextEventListener implements
+ HttpSessionListener,
+ HttpSessionAttributeListener,
+ ServletContextAttributeListener,
+ ServletRequestListener,
+ ServletRequestAttributeListener
+{
+ /** Servlet context listeners. */
+ private final Map<ServiceReference<ServletContextListener>, ServletContextListener> listeners = new HashMap<ServiceReference<ServletContextListener>, ServletContextListener>();
+
+ /** Servlet context attribute listeners. */
+ private final Map<ServiceReference<ServletContextAttributeListener>, ServletContextAttributeListener> contextAttributeListeners = new ConcurrentSkipListMap<ServiceReference<ServletContextAttributeListener>, ServletContextAttributeListener>();
+
+ /** Session attribute listeners. */
+ private final Map<ServiceReference<HttpSessionAttributeListener>, HttpSessionAttributeListener> sessionAttributeListeners = new ConcurrentSkipListMap<ServiceReference<HttpSessionAttributeListener>, HttpSessionAttributeListener>();
+
+ /** Session listeners. */
+ private final Map<ServiceReference<HttpSessionListener>, HttpSessionListener> sessionListeners = new ConcurrentSkipListMap<ServiceReference<HttpSessionListener>, HttpSessionListener>();
+
+ /** Request listeners. */
+ private final Map<ServiceReference<ServletRequestListener>, ServletRequestListener> requestListeners = new ConcurrentSkipListMap<ServiceReference<ServletRequestListener>, ServletRequestListener>();
+
+ /** Request attribute listeners. */
+ private final Map<ServiceReference<ServletRequestAttributeListener>, ServletRequestAttributeListener> requestAttributeListeners = new ConcurrentSkipListMap<ServiceReference<ServletRequestAttributeListener>, ServletRequestAttributeListener>();
+
+ private final Bundle bundle;
+
+ PerContextEventListener(final Bundle bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ void initialized(@Nonnull final ServletContextListenerInfo listenerInfo,
+ ContextHandler contextHandler)
+ {
+ final ServletContextListener listener = listenerInfo.getService(bundle);
+ if (listener != null)
+ {
+ // no need to sync map - initialized is called in sync
+ this.listeners.put(listenerInfo.getServiceReference(), listener);
+
+ final ServletContext context = contextHandler
+ .getServletContext(listenerInfo.getServiceReference()
+ .getBundle());
+
+ listener.contextInitialized(new ServletContextEvent(context));
+ }
+ }
+
+ void destroyed(@Nonnull final ServletContextListenerInfo listenerInfo,
+ ContextHandler contextHandler)
+ {
+ final ServiceReference<ServletContextListener> listenerRef = listenerInfo
+ .getServiceReference();
+ final ServletContextListener listener = this.listeners
+ .remove(listenerRef);
+ if (listener != null)
+ {
+ final ServletContext context = contextHandler
+ .getServletContext(listenerRef.getBundle());
+ listener.contextDestroyed(new ServletContextEvent(context));
+ // call unget twice, once for the call in initialized and once for
+ // the call in this method(!)
+ contextHandler.ungetServletContext(listenerRef.getBundle());
+ contextHandler.ungetServletContext(listenerRef.getBundle());
+ listenerInfo.ungetService(bundle, listener);
+ }
+ }
+
+ /**
+ * Add servlet context attribute listener
+ *
+ * @param info
+ */
+ void addListener(@Nonnull final ServletContextAttributeListenerInfo info)
+ {
+ final ServletContextAttributeListener service = info.getService(bundle);
+ if (service != null)
+ {
+ this.contextAttributeListeners.put(info.getServiceReference(),
+ service);
+ }
+ }
+
+ /**
+ * Remove servlet context attribute listener
+ *
+ * @param info
+ */
+ void removeListener(@Nonnull final ServletContextAttributeListenerInfo info)
+ {
+ final ServletContextAttributeListener service = this.contextAttributeListeners
+ .remove(info.getServiceReference());
+ if (service != null)
+ {
+ info.ungetService(bundle, service);
+ }
+ }
+
+ /**
+ * Add session attribute listener
+ *
+ * @param info
+ */
+ void addListener(@Nonnull final HttpSessionAttributeListenerInfo info)
+ {
+ final HttpSessionAttributeListener service = info.getService(bundle);
+ if (service != null)
+ {
+ this.sessionAttributeListeners.put(info.getServiceReference(),
+ service);
+ }
+ }
+
+ /**
+ * Remove session attribute listener
+ *
+ * @param info
+ */
+ void removeListener(@Nonnull final HttpSessionAttributeListenerInfo info)
+ {
+ final HttpSessionAttributeListener service = this.sessionAttributeListeners
+ .remove(info.getServiceReference());
+ if (service != null)
+ {
+ info.ungetService(bundle, service);
+ }
+ }
+
+ /**
+ * Add session listener
+ *
+ * @param info
+ */
+ void addListener(@Nonnull final HttpSessionListenerInfo info)
+ {
+ final HttpSessionListener service = info.getService(bundle);
+ if (service != null)
+ {
+ this.sessionListeners.put(info.getServiceReference(), service);
+ }
+ }
+
+ /**
+ * Remove session listener
+ *
+ * @param info
+ */
+ void removeListener(@Nonnull final HttpSessionListenerInfo info)
+ {
+ final HttpSessionListener service = this.sessionListeners.remove(info
+ .getServiceReference());
+ if (service != null)
+ {
+ info.ungetService(bundle, service);
+ }
+ }
+
+ /**
+ * Add request listener
+ *
+ * @param info
+ */
+ void addListener(@Nonnull final ServletRequestListenerInfo info)
+ {
+ final ServletRequestListener service = info.getService(bundle);
+ if (service != null)
+ {
+ this.requestListeners.put(info.getServiceReference(), service);
+ }
+ }
+
+ /**
+ * Remove request listener
+ *
+ * @param info
+ */
+ void removeListener(@Nonnull final ServletRequestListenerInfo info)
+ {
+ final ServletRequestListener service = this.requestListeners
+ .remove(info.getServiceReference());
+ if (service != null)
+ {
+ info.ungetService(bundle, service);
+ }
+ }
+
+ /**
+ * Add request attribute listener
+ *
+ * @param info
+ */
+ void addListener(@Nonnull final ServletRequestAttributeListenerInfo info)
+ {
+ final ServletRequestAttributeListener service = info.getService(bundle);
+ if (service != null)
+ {
+ this.requestAttributeListeners.put(info.getServiceReference(),
+ service);
+ }
+ }
+
+ /**
+ * Remove request attribute listener
+ *
+ * @param info
+ */
+ void removeListener(@Nonnull final ServletRequestAttributeListenerInfo info)
+ {
+ final ServletRequestAttributeListener service = this.requestAttributeListeners
+ .remove(info.getServiceReference());
+ if (service != null)
+ {
+ info.ungetService(bundle, service);
+ }
+ }
+
+ // Make calling from ListenerRegistry easier
+ <T extends ListenerInfo<?>> void addListener(@Nonnull T info)
+ {
+ throw new UnsupportedOperationException("Listeners of type "
+ + info.getClass() + "are not supported");
+ }
+
+ <T extends ListenerInfo<?>> void removeListener(@Nonnull T info)
+ {
+ throw new UnsupportedOperationException("Listeners of type "
+ + info.getClass() + "are not supported");
+ }
+
+ @Override
+ public void attributeReplaced(final HttpSessionBindingEvent event)
+ {
+ for (final HttpSessionAttributeListener l : sessionAttributeListeners
+ .values())
+ {
+ l.attributeReplaced(event);
+ }
+ }
+
+ @Override
+ public void attributeRemoved(final HttpSessionBindingEvent event)
+ {
+ for (final HttpSessionAttributeListener l : sessionAttributeListeners
+ .values())
+ {
+ l.attributeReplaced(event);
+ }
+ }
+
+ @Override
+ public void attributeAdded(final HttpSessionBindingEvent event)
+ {
+ for (final HttpSessionAttributeListener l : sessionAttributeListeners
+ .values())
+ {
+ l.attributeReplaced(event);
+ }
+ }
+
+ @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);
+ }
+ }
+
+ @Override
+ public void sessionCreated(final HttpSessionEvent se)
+ {
+ for (final HttpSessionListener l : sessionListeners.values())
+ {
+ l.sessionCreated(se);
+ }
+ }
+
+ @Override
+ public void sessionDestroyed(final HttpSessionEvent se)
+ {
+ for (final HttpSessionListener l : sessionListeners.values())
+ {
+ l.sessionDestroyed(se);
+ }
+ }
+
+ @Override
+ public void requestDestroyed(final ServletRequestEvent sre)
+ {
+ for (final ServletRequestListener l : requestListeners.values())
+ {
+ l.requestDestroyed(sre);
+ }
+ }
+
+ @Override
+ public void requestInitialized(final ServletRequestEvent sre)
+ {
+ for (final ServletRequestListener l : requestListeners.values())
+ {
+ l.requestInitialized(sre);
+ }
+ }
+
+ @Override
+ public void attributeAdded(final ServletRequestAttributeEvent srae)
+ {
+ for (final ServletRequestAttributeListener l : requestAttributeListeners
+ .values())
+ {
+ l.attributeAdded(srae);
+ }
+ }
+
+ @Override
+ public void attributeRemoved(final ServletRequestAttributeEvent srae)
+ {
+ for (final ServletRequestAttributeListener l : requestAttributeListeners
+ .values())
+ {
+ l.attributeRemoved(srae);
+ }
+ }
+
+ @Override
+ public void attributeReplaced(final ServletRequestAttributeEvent srae)
+ {
+ for (final ServletRequestAttributeListener l : requestAttributeListeners
+ .values())
+ {
+ l.attributeReplaced(srae);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ Collection<ServiceReference<?>> getRuntime()
+ {
+ return CollectionUtils.<ServiceReference<?>> union(
+ contextAttributeListeners.keySet(),
+ sessionAttributeListeners.keySet(),
+ sessionListeners.keySet(),
+ requestAttributeListeners.keySet(),
+ requestListeners.keySet());
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1661116&r1=1661115&r2=1661116&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 Fri Feb 20 13:26:34 2015
@@ -27,24 +27,24 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.concurrent.ConcurrentSkipListSet;
import javax.annotation.Nonnull;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
+import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.logger.SystemLogger;
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.HttpSessionListenerInfo;
+import org.apache.felix.http.base.internal.runtime.HandlerRuntime;
+import org.apache.felix.http.base.internal.runtime.ListenerInfo;
+import org.apache.felix.http.base.internal.runtime.RegistryRuntime;
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.ServletContextHelperInfo;
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.ServletRequestAttributeListenerInfo;
-import org.apache.felix.http.base.internal.runtime.ServletRequestListenerInfo;
import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
import org.apache.felix.http.base.internal.util.MimeTypes;
import org.osgi.framework.Bundle;
@@ -56,6 +56,7 @@ import org.osgi.framework.ServiceFactory
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
public final class ServletContextHelperManager
@@ -68,42 +69,57 @@ public final class ServletContextHelperM
private final WhiteboardHttpService httpService;
- private final ServiceRegistration<ServletContextHelper> defaultContextRegistration;
+ private final ListenerRegistry listenerRegistry;
- private final ServletContext webContext;
-
- private final Bundle bundle;
+ private final BundleContext bundleContext;
private final Set<AbstractInfo<?>> invalidRegistrations = new ConcurrentSkipListSet<AbstractInfo<?>>();
+ private volatile ServletContext webContext;
+
+ private volatile ServiceReference<HttpServiceRuntime> httpServiceRuntime;
+
+ private volatile ServiceRegistration<ServletContextHelper> defaultContextRegistration;
+
/**
* Create a new servlet context helper manager
* and the default context
*/
public ServletContextHelperManager(final BundleContext bundleContext,
- final ServletContext webContext,
- final WhiteboardHttpService httpService)
+ final WhiteboardHttpService httpService,
+ final ListenerRegistry listenerRegistry)
{
+ this.bundleContext = bundleContext;
this.httpService = httpService;
+ this.listenerRegistry = listenerRegistry;
+ }
+
+ public void start(ServletContext webContext, ServiceReference<HttpServiceRuntime> httpServiceRuntime)
+ {
this.webContext = webContext;
- this.bundle = bundleContext.getBundle();
+ this.httpServiceRuntime = httpServiceRuntime;
final Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME);
props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/");
props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
- this.defaultContextRegistration = bundleContext.registerService(ServletContextHelper.class,
- new ServiceFactory<ServletContextHelper>() {
+ this.defaultContextRegistration = bundleContext.registerService(
+ ServletContextHelper.class,
+ new ServiceFactory<ServletContextHelper>()
+ {
@Override
public ServletContextHelper getService(
final Bundle bundle,
- final ServiceRegistration<ServletContextHelper> registration) {
- return new ServletContextHelper(bundle) {
+ final ServiceRegistration<ServletContextHelper> registration)
+ {
+ return new ServletContextHelper(bundle)
+ {
@Override
- public String getMimeType(final String file) {
+ public String getMimeType(final String file)
+ {
return MimeTypes.get().getByFile(file);
}
};
@@ -113,11 +129,11 @@ public final class ServletContextHelperM
public void ungetService(
final Bundle bundle,
final ServiceRegistration<ServletContextHelper> registration,
- final ServletContextHelper service) {
+ final ServletContextHelper service)
+ {
// nothing to do
}
- },
- props);
+ }, props);
}
/**
@@ -126,8 +142,11 @@ public final class ServletContextHelperM
public void close()
{
// TODO cleanup
-
- this.defaultContextRegistration.unregister();
+ if (this.defaultContextRegistration != null)
+ {
+ this.defaultContextRegistration.unregister();
+ this.defaultContextRegistration = null;
+ }
}
/**
@@ -162,7 +181,7 @@ public final class ServletContextHelperM
// context listeners first
for(final ServletContextListenerInfo info : listeners.values())
{
- handler.initialized(info);
+ this.listenerRegistry.initialized(info, handler);
}
// now register services
for(final WhiteboardServiceInfo<?> info : services)
@@ -198,7 +217,7 @@ public final class ServletContextHelperM
}
for(final ServletContextListenerInfo info : listeners.values())
{
- handler.destroyed(info);
+ this.listenerRegistry.destroyed(info, handler);
}
handler.deactivate();
@@ -216,9 +235,14 @@ public final class ServletContextHelperM
{
if ( info.isValid() )
{
- final ContextHandler handler = new ContextHandler(info, this.webContext, this.bundle);
synchronized ( this.contextMap )
{
+ PerContextEventListener contextEventListener = listenerRegistry.addContext(info);
+ ContextHandler handler = new ContextHandler(info,
+ this.webContext,
+ contextEventListener,
+ this.bundleContext.getBundle());
+
List<ContextHandler> handlerList = this.contextMap.get(info.getName());
if ( handlerList == null )
{
@@ -290,6 +314,7 @@ public final class ServletContextHelperM
{
this.activate(handlerList.get(0));
}
+ listenerRegistry.removeContext(info);
}
}
}
@@ -394,28 +419,9 @@ public final class ServletContextHelperM
{
this.httpService.registerResource(handler, (ResourceInfo)info);
}
-
- else if ( info instanceof ServletContextAttributeListenerInfo )
- {
- handler.addListener((ServletContextAttributeListenerInfo)info );
- }
-
- else if ( info instanceof HttpSessionListenerInfo )
- {
- handler.addListener((HttpSessionListenerInfo)info );
- }
- else if ( info instanceof HttpSessionAttributeListenerInfo )
- {
- handler.addListener((HttpSessionAttributeListenerInfo)info );
- }
-
- else if ( info instanceof ServletRequestListenerInfo )
- {
- handler.addListener((ServletRequestListenerInfo)info );
- }
- else if ( info instanceof ServletRequestAttributeListenerInfo )
+ else if ( info instanceof ListenerInfo )
{
- handler.addListener((ServletRequestAttributeListenerInfo)info );
+ this.listenerRegistry.addListener((ListenerInfo<?>)info, handler);
}
}
@@ -438,28 +444,9 @@ public final class ServletContextHelperM
{
this.httpService.unregisterResource(handler, (ResourceInfo)info);
}
-
- else if ( info instanceof ServletContextAttributeListenerInfo )
- {
- handler.removeListener((ServletContextAttributeListenerInfo)info );
- }
-
- else if ( info instanceof HttpSessionListenerInfo )
- {
- handler.removeListener((HttpSessionListenerInfo)info );
- }
- else if ( info instanceof HttpSessionAttributeListenerInfo )
+ else if ( info instanceof ListenerInfo )
{
- handler.removeListener((HttpSessionAttributeListenerInfo)info );
- }
-
- else if ( info instanceof ServletRequestListenerInfo )
- {
- handler.removeListener((ServletRequestListenerInfo)info );
- }
- else if ( info instanceof ServletRequestAttributeListenerInfo )
- {
- handler.removeListener((ServletRequestAttributeListenerInfo)info );
+ this.listenerRegistry.removeListener((ListenerInfo<?>)info, handler);
}
}
@@ -474,8 +461,8 @@ public final class ServletContextHelperM
{
try
{
- final Filter f = this.bundle.getBundleContext().createFilter(target);
- return f.match(this.httpService.getServiceReference());
+ final Filter f = this.bundleContext.createFilter(target);
+ return f.match(this.httpServiceRuntime);
}
catch ( final InvalidSyntaxException ise)
{
@@ -516,4 +503,21 @@ public final class ServletContextHelperM
}
return handlers;
}
+
+ public RegistryRuntime getRuntime(HandlerRegistry registry)
+ {
+ List<HandlerRuntime> handlerRuntimes;
+ Map<Long, Collection<ServiceReference<?>>> listenerRuntimes;
+ Set<ContextHandler> contextHandlers = new TreeSet<ContextHandler>();
+ synchronized ( this.contextMap )
+ {
+ for (List<ContextHandler> contextHandlerList : this.contextMap.values())
+ {
+ contextHandlers.addAll(contextHandlerList);
+ }
+ handlerRuntimes = registry.getRuntime();
+ listenerRuntimes = listenerRegistry.getContextRuntimes();
+ }
+ return new RegistryRuntime(contextHandlers, handlerRuntimes, listenerRuntimes);
+ }
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java?rev=1661116&r1=1661115&r2=1661116&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java Fri Feb 20 13:26:34 2015
@@ -16,154 +16,37 @@
*/
package org.apache.felix.http.base.internal.whiteboard;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import javax.annotation.Nonnull;
-import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
-import javax.servlet.http.HttpSession;
-import org.apache.felix.http.base.internal.context.ExtServletContext;
import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
-import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
import org.apache.felix.http.base.internal.handler.PerContextHandlerRegistry;
import org.apache.felix.http.base.internal.handler.ServletHandler;
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.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.WhiteboardServiceInfo;
-import org.apache.felix.http.base.internal.service.HttpServiceFactory;
-import org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionAttributeListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ResourceTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextAttributeListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestAttributeListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceObjects;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.http.runtime.HttpServiceRuntime;
-import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
-import org.osgi.service.http.runtime.dto.ErrorPageDTO;
-import org.osgi.service.http.runtime.dto.FilterDTO;
-import org.osgi.service.http.runtime.dto.ListenerDTO;
-import org.osgi.service.http.runtime.dto.RequestInfoDTO;
-import org.osgi.service.http.runtime.dto.ResourceDTO;
-import org.osgi.service.http.runtime.dto.RuntimeDTO;
-import org.osgi.service.http.runtime.dto.ServletContextDTO;
-import org.osgi.service.http.runtime.dto.ServletDTO;
-import org.osgi.util.tracker.ServiceTracker;
-public final class WhiteboardHttpService implements HttpServiceRuntime
+public final class WhiteboardHttpService
{
-
private final HandlerRegistry handlerRegistry;
private final BundleContext bundleContext;
- private volatile ServletContextHelperManager contextManager;
-
- private final List<ServiceTracker<?, ?>> trackers = new ArrayList<ServiceTracker<?, ?>>();
-
- private final Hashtable<String, Object> runtimeServiceProps = new Hashtable<String, Object>();;
-
- private final HttpServiceFactory httpServiceFactory;
-
- private volatile ServiceRegistration<HttpServiceRuntime> runtimeServiceReg;
-
/**
* Create a new whiteboard http service
* @param bundleContext
- * @param context
* @param handlerRegistry
*/
public WhiteboardHttpService(final BundleContext bundleContext,
- final HandlerRegistry handlerRegistry,
- final HttpServiceFactory httpServiceFactory)
+ final HandlerRegistry handlerRegistry)
{
this.handlerRegistry = handlerRegistry;
this.bundleContext = bundleContext;
- this.httpServiceFactory = httpServiceFactory;
- }
-
- public void start(final ServletContext context)
- {
- this.contextManager = new ServletContextHelperManager(bundleContext, context, this);
-
- addTracker(new FilterTracker(bundleContext, contextManager));
- addTracker(new ServletTracker(bundleContext, this.contextManager));
- addTracker(new ResourceTracker(bundleContext, this.contextManager));
-
- addTracker(new HttpSessionListenerTracker(bundleContext, this.contextManager));
- addTracker(new HttpSessionAttributeListenerTracker(bundleContext, this.contextManager));
-
- addTracker(new ServletContextHelperTracker(bundleContext, this.contextManager));
- addTracker(new ServletContextListenerTracker(bundleContext, this.contextManager));
- addTracker(new ServletContextAttributeListenerTracker(bundleContext, this.contextManager));
-
- addTracker(new ServletRequestListenerTracker(bundleContext, this.contextManager));
- addTracker(new ServletRequestAttributeListenerTracker(bundleContext, this.contextManager));
-
- this.runtimeServiceProps.put(HttpServiceRuntimeConstants.HTTP_SERVICE_ID_ATTRIBUTE,
- this.httpServiceFactory.getHttpServiceServiceId());
- this.runtimeServiceReg = this.bundleContext.registerService(HttpServiceRuntime.class,
- this,
- this.runtimeServiceProps);
- }
-
- public void stop()
- {
- if ( this.runtimeServiceReg != null )
- {
- this.runtimeServiceReg.unregister();
- this.runtimeServiceReg = null;
- }
-
- for(final ServiceTracker<?, ?> t : this.trackers)
- {
- t.close();
- }
- this.trackers.clear();
- if ( this.contextManager != null )
- {
- this.contextManager.close();
- this.contextManager = null;
- }
- }
-
- private void addTracker(ServiceTracker<?, ?> tracker)
- {
- this.trackers.add(tracker);
- tracker.open();
- }
-
- public void setProperties(final Hashtable<String, Object> props)
- {
- // runtime service gets the same props for now
- this.runtimeServiceProps.clear();
- this.runtimeServiceProps.putAll(props);
-
- if (this.runtimeServiceReg != null)
- {
- this.runtimeServiceProps.put(HttpServiceRuntimeConstants.HTTP_SERVICE_ID_ATTRIBUTE,
- this.httpServiceFactory.getHttpServiceServiceId());
- this.runtimeServiceReg.setProperties(this.runtimeServiceProps);
- }
}
/**
@@ -190,7 +73,6 @@ public final class WhiteboardHttpService
if (registry != null )
{
registry.addServlet(handler);
- contextHandler.addWhiteboardService(servletInfo);
}
} catch (final ServletException e) {
so.ungetService(servlet);
@@ -217,7 +99,6 @@ public final class WhiteboardHttpService
}
}
contextHandler.ungetServletContext(servletInfo.getServiceReference().getBundle());
- contextHandler.removeWhiteboardService(servletInfo);
}
/**
@@ -241,7 +122,6 @@ public final class WhiteboardHttpService
if (registry != null )
{
registry.addFilter(handler);
- contextHandler.addWhiteboardService(filterInfo);
}
} catch (final ServletException e) {
// TODO create failure DTO
@@ -266,7 +146,6 @@ public final class WhiteboardHttpService
}
}
contextHandler.ungetServletContext(filterInfo.getServiceReference().getBundle());
- contextHandler.removeWhiteboardService(filterInfo);
}
/**
@@ -289,7 +168,6 @@ public final class WhiteboardHttpService
if (registry != null )
{
registry.addServlet(handler);
- contextHandler.addWhiteboardService(resourceInfo);
}
} catch (ServletException e) {
// TODO create failure DTO
@@ -310,7 +188,6 @@ public final class WhiteboardHttpService
registry.removeServlet(servletInfo, true);
}
contextHandler.ungetServletContext(servletInfo.getServiceReference().getBundle());
- contextHandler.removeWhiteboardService(servletInfo);
}
public void registerContext(@Nonnull final ContextHandler contextHandler)
@@ -322,173 +199,4 @@ public final class WhiteboardHttpService
{
this.handlerRegistry.remove(contextHandler.getContextInfo());
}
-
- public void sessionDestroyed(@Nonnull final HttpSession session, final Set<Long> contextIds)
- {
- for(final Long contextId : contextIds)
- {
- // TODO - on shutdown context manager is already NULL which shouldn't be the case
- if ( this.contextManager != null )
- {
- final ContextHandler handler = this.contextManager.getContextHandler(contextId);
- if ( handler != null )
- {
- final ExtServletContext context = handler.getServletContext(this.bundleContext.getBundle());
- new HttpSessionWrapper(contextId, session, context, true).invalidate();
- handler.ungetServletContext(this.bundleContext.getBundle());
- }
- }
- }
- }
-
- public ServiceReference<HttpServiceRuntime> getServiceReference()
- {
- return this.runtimeServiceReg.getReference();
- }
-
- @Override
- public RuntimeDTO getRuntimeDTO()
- {
- // create new DTO on every call
- final RuntimeDTO runtime = new RuntimeDTO();
-
- // attributes
- runtime.attributes = new HashMap<String, String>();
- for(final Map.Entry<String, Object> entry : this.runtimeServiceProps.entrySet())
- {
- runtime.attributes.put(entry.getKey(), entry.getValue().toString());
- }
-
- // servlet context DTOs
- final List<ServletContextDTO> contextDTOs = new ArrayList<ServletContextDTO>();
- for(final ContextHandler handler : this.contextManager.getContextHandlers())
- {
- final ServletContextDTO dto = new ServletContextDTO();
-
- final ServletContext ctx = handler.getServletContext(this.bundleContext.getBundle());
- try
- {
- dto.name = handler.getContextInfo().getName();
- dto.contextPath = handler.getContextInfo().getPath();
- dto.initParams = new HashMap<String, String>(handler.getContextInfo().getInitParameters());
- dto.serviceId = handler.getContextInfo().getServiceId();
-
- dto.contextName = ctx.getServletContextName();
- dto.attributes = new HashMap<String, Object>();
- final Enumeration<String> e = ctx.getAttributeNames();
- while ( e.hasMoreElements() )
- {
- final String name = e.nextElement();
- final Object value = ctx.getAttribute(name);
- if ( value != null )
- {
- // TODO - check for appropriate value types
- }
- }
-
- final List<ErrorPageDTO> errorPages = new ArrayList<ErrorPageDTO>();
- final List<FilterDTO> filters = new ArrayList<FilterDTO>();
- final List<ServletDTO> servlets = new ArrayList<ServletDTO>();
- final List<ResourceDTO> resources = new ArrayList<ResourceDTO>();
- for(final WhiteboardServiceInfo<?> info : handler.getWhiteboardServices())
- {
- if ( info instanceof ServletInfo )
- {
- final ServletInfo si = (ServletInfo)info;
- if ( si.getErrorPage() != null )
- {
- final ErrorPageDTO page = new ErrorPageDTO();
- errorPages.add(page);
- page.asyncSupported = si.isAsyncSupported();
- page.errorCodes = new long[0]; // TODO
- page.exceptions = toStringArray(si.getErrorPage()); // TODO
- page.initParams = new HashMap<String, String>(si.getInitParameters());
- page.name = si.getName();
- page.serviceId = si.getServiceId();
- page.servletContextId = handler.getContextInfo().getServiceId();
- page.servletInfo = null; // TODO
- }
- if ( si.getPatterns() != null )
- {
- final ServletDTO servlet = new ServletDTO();
- servlets.add(servlet);
- servlet.asyncSupported = si.isAsyncSupported();
- servlet.initParams = new HashMap<String, String>(si.getInitParameters());
- servlet.name = si.getName();
- servlet.patterns = toStringArray(si.getPatterns());
- servlet.serviceId = si.getServiceId();
- servlet.servletContextId = handler.getContextInfo().getServiceId();
- servlet.servletInfo = null; // TODO
- }
- }
- else if ( info instanceof ResourceInfo )
- {
- final ResourceDTO rsrc = new ResourceDTO();
- resources.add(rsrc);
- rsrc.patterns = ((ResourceInfo)info).getPatterns();
- rsrc.prefix = ((ResourceInfo)info).getPrefix();
- rsrc.serviceId = info.getServiceId();
- rsrc.servletContextId = handler.getContextInfo().getServiceId();
- }
- else if ( info instanceof FilterInfo )
- {
- final FilterDTO filter = new FilterDTO();
- filters.add(filter);
- filter.asyncSupported = ((FilterInfo)info).isAsyncSupported();
- final DispatcherType[] dTypes = ((FilterInfo)info).getDispatcher();
- filter.dispatcher = new String[dTypes.length];
- int index = 0;
- for(final DispatcherType dt : dTypes)
- {
- filter.dispatcher[index++] = dt.name();
- }
- filter.initParams = new HashMap<String, String>(((FilterInfo)info).getInitParameters());
- filter.name = ((FilterInfo)info).getName();
- filter.patterns = toStringArray(((FilterInfo)info).getPatterns());
- filter.regexs = toStringArray(((FilterInfo)info).getRegexs());
- filter.serviceId = info.getServiceId();
- filter.servletContextId = handler.getContextInfo().getServiceId();
- filter.servletNames = toStringArray(((FilterInfo)info).getServletNames());
- }
- }
- dto.errorPageDTOs = errorPages.toArray(new ErrorPageDTO[errorPages.size()]);
- dto.filterDTOs = filters.toArray(new FilterDTO[filters.size()]);
- dto.resourceDTOs = resources.toArray(new ResourceDTO[resources.size()]);
- dto.servletDTOs = servlets.toArray(new ServletDTO[servlets.size()]);
-
- dto.listenerDTOs = new ListenerDTO[0]; // TODO
- }
- finally
- {
- handler.ungetServletContext(this.bundleContext.getBundle());
- }
- contextDTOs.add(dto);
- }
- runtime.servletContextDTOs = contextDTOs.toArray(new ServletContextDTO[contextDTOs.size()]);
-
- runtime.failedErrorPageDTOs = null; // TODO
- runtime.failedFilterDTOs = null; // TODO
- runtime.failedListenerDTOs = null; // TODO
- runtime.failedResourceDTOs = null; // TODO
- runtime.failedServletContextDTOs = null; // TODO
- runtime.failedServletDTOs = null; // TODO
-
- return runtime;
- }
-
- @Override
- public RequestInfoDTO calculateRequestInfoDTO(final String path) {
- // TODO
- return null;
- }
-
- private static final String[] EMPTY_ARRAY = new String[0];
- private String[] toStringArray(final String[] array)
- {
- if ( array == null )
- {
- return EMPTY_ARRAY;
- }
- return array;
- }
}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java?rev=1661116&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java Fri Feb 20 13:26:34 2015
@@ -0,0 +1,163 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+
+import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.handler.HandlerRegistry;
+import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
+import org.apache.felix.http.base.internal.service.HttpServiceRuntimeImpl;
+import org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionAttributeListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ResourceTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextAttributeListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestAttributeListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.runtime.HttpServiceRuntime;
+import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
+import org.osgi.util.tracker.ServiceTracker;
+
+public final class WhiteboardManager
+{
+ private final BundleContext bundleContext;
+
+ private final List<ServiceTracker<?, ?>> trackers = new ArrayList<ServiceTracker<?, ?>>();
+
+ private final HttpServiceFactory httpServiceFactory;
+
+ private final HttpServiceRuntimeImpl serviceRuntime;
+
+ private final ServletContextHelperManager contextManager;
+
+ private volatile ServiceRegistration<HttpServiceRuntime> runtimeServiceReg;
+
+ /**
+ * Create a new whiteboard http manager
+ * @param bundleContext
+ * @param httpServiceFactory
+ * @param registry
+ */
+ public WhiteboardManager(final BundleContext bundleContext,
+ final HttpServiceFactory httpServiceFactory,
+ final HandlerRegistry registry)
+ {
+ this.bundleContext = bundleContext;
+ this.httpServiceFactory = httpServiceFactory;
+ WhiteboardHttpService whiteboardHttpService = new WhiteboardHttpService(this.bundleContext, registry);
+ ListenerRegistry listenerRegistry = new ListenerRegistry(bundleContext.getBundle());
+ this.contextManager = new ServletContextHelperManager(bundleContext, whiteboardHttpService, listenerRegistry);
+ this.serviceRuntime = new HttpServiceRuntimeImpl(registry, this.contextManager);
+ }
+
+ public void start(final ServletContext context)
+ {
+ // TODO set Endpoint
+ this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID_ATTRIBUTE,
+ this.httpServiceFactory.getHttpServiceServiceId());
+ this.runtimeServiceReg = this.bundleContext.registerService(HttpServiceRuntime.class,
+ serviceRuntime,
+ this.serviceRuntime.getAttributes());
+
+ this.contextManager.start(context, this.runtimeServiceReg.getReference());
+
+ addTracker(new FilterTracker(this.bundleContext, contextManager));
+ addTracker(new ServletTracker(this.bundleContext, this.contextManager));
+ addTracker(new ResourceTracker(this.bundleContext, this.contextManager));
+
+ addTracker(new HttpSessionListenerTracker(this.bundleContext, this.contextManager));
+ addTracker(new HttpSessionAttributeListenerTracker(this.bundleContext, this.contextManager));
+
+ addTracker(new ServletContextHelperTracker(this.bundleContext, this.contextManager));
+ addTracker(new ServletContextListenerTracker(this.bundleContext, this.contextManager));
+ addTracker(new ServletContextAttributeListenerTracker(this.bundleContext, this.contextManager));
+
+ addTracker(new ServletRequestListenerTracker(this.bundleContext, this.contextManager));
+ addTracker(new ServletRequestAttributeListenerTracker(this.bundleContext, this.contextManager));
+ }
+
+ public void stop()
+ {
+ for(final ServiceTracker<?, ?> t : this.trackers)
+ {
+ t.close();
+ }
+ this.trackers.clear();
+
+ if ( this.contextManager != null )
+ {
+ this.contextManager.close();
+ }
+
+ if ( this.runtimeServiceReg != null )
+ {
+ this.runtimeServiceReg.unregister();
+ this.runtimeServiceReg = null;
+ }
+ }
+
+ private void addTracker(ServiceTracker<?, ?> tracker)
+ {
+ this.trackers.add(tracker);
+ tracker.open();
+ }
+
+ public void setProperties(final Hashtable<String, Object> props)
+ {
+ // runtime service gets the same props for now
+ this.serviceRuntime.setAllAttributes(props);
+
+ if (this.runtimeServiceReg != null)
+ {
+ this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID_ATTRIBUTE,
+ this.httpServiceFactory.getHttpServiceServiceId());
+ this.runtimeServiceReg.setProperties(this.serviceRuntime.getAttributes());
+ }
+ }
+
+ public void sessionDestroyed(@Nonnull final HttpSession session, final Set<Long> contextIds)
+ {
+ for(final Long contextId : contextIds)
+ {
+ // TODO - on shutdown context manager is already NULL which shouldn't be the case
+ if ( this.contextManager != null )
+ {
+ final ContextHandler handler = this.contextManager.getContextHandler(contextId);
+ if ( handler != null )
+ {
+ final ExtServletContext context = handler.getServletContext(this.bundleContext.getBundle());
+ new HttpSessionWrapper(contextId, session, context, true).invalidate();
+ handler.ungetServletContext(this.bundleContext.getBundle());
+ }
+ }
+ }
+ }
+}
Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java?rev=1661116&view=auto
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java (added)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java Fri Feb 20 13:26:34 2015
@@ -0,0 +1,189 @@
+/*
+ * 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 static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.servlet.DispatcherType;
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+
+import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.runtime.HandlerRuntime.ErrorPage;
+
+public final class WhiteboardServiceHelper
+{
+ public static final AtomicLong ID_COUNTER = new AtomicLong();
+
+ public static FilterHandler createTestFilterWithServiceId(String identifier,
+ ExtServletContext context)
+ {
+ return createTestFilter(identifier, context, ID_COUNTER.incrementAndGet());
+ }
+
+ public static FilterHandler createTestFilter(String identifier,
+ ExtServletContext context)
+ {
+ return createTestFilter(identifier, context, -ID_COUNTER.incrementAndGet());
+ }
+
+ private static FilterHandler createTestFilter(String identifier,
+ ExtServletContext context,
+ Long serviceId)
+ {
+ FilterInfo filterInfo = createFilterInfo(identifier, serviceId);
+ return new FilterHandler(null, context, mock(Filter.class), filterInfo);
+ }
+
+ private static FilterInfo createFilterInfo(String identifier,
+ Long serviceId)
+ {
+ boolean asyncSupported = true;
+ String name = identifier;
+ Map<String, String> initParams = createInitParameterMap(identifier);
+ String[] patterns = new String[]{ "/" + identifier };
+ String[] regexs = new String[]{ "." + identifier };
+ DispatcherType[] dispatcher = new DispatcherType[] { DispatcherType.ASYNC, DispatcherType.REQUEST };
+ return createFilterInfo(0, serviceId, name, patterns, null, regexs, asyncSupported, dispatcher, initParams);
+ }
+
+ public static FilterInfo createFilterInfo(int serviceRanking,
+ Long serviceId,
+ String name,
+ String[] patterns,
+ String[] servletNames,
+ String[] regexs,
+ boolean asyncSupported,
+ DispatcherType[] dispatcher,
+ Map<String, String> initParams)
+ {
+ FilterInfo info = new FilterInfo(0,
+ serviceId,
+ name,
+ patterns,
+ servletNames,
+ regexs,
+ asyncSupported,
+ dispatcher,
+ initParams);
+ return info;
+ }
+
+ public static ServletHandler createTestServletWithServiceId(String identifier,
+ ExtServletContext context)
+ {
+ return createTestServlet(identifier, context, ID_COUNTER.incrementAndGet());
+ }
+
+ public static ServletHandler createTestServlet(String identifier, ExtServletContext context)
+ {
+ return createTestServlet(identifier, context, -ID_COUNTER.incrementAndGet());
+ }
+
+ private static ServletHandler createTestServlet(String identifier,
+ ExtServletContext context,
+ Long serviceId)
+ {
+ ServletInfo servletInfo = createServletInfo(identifier, serviceId);
+ Servlet servlet = mock(Servlet.class);
+ when(servlet.getServletInfo()).thenReturn("info_" + identifier);
+ return new ServletHandler(null, context, servletInfo, servlet);
+ }
+
+ private static ServletInfo createServletInfo(String identifier, Long serviceId)
+ {
+ boolean asyncSupported = true;
+ String name = identifier;
+ Map<String, String> initParams = createInitParameterMap(identifier);
+ String[] patterns = new String[]{ "/" + identifier };
+ return createServletInfo(0, serviceId, name, patterns, null, asyncSupported, initParams);
+ }
+
+ public static ServletInfo createServletInfo(int serviceRanking,
+ Long serviceId,
+ String name,
+ String[] patterns,
+ String[] errorPages,
+ boolean asyncSupported,
+ Map<String, String> initParams)
+ {
+ return new ServletInfo(0,
+ serviceId,
+ name,
+ patterns,
+ null,
+ asyncSupported,
+ initParams);
+ }
+
+ @SuppressWarnings("serial")
+ private static HashMap<String, String> createInitParameterMap(final String identifier)
+ {
+ return new HashMap<String, String>()
+ {
+ {
+ put("paramOne_" + identifier, "valOne_" + identifier);
+ put("paramTwo_" + identifier, "valTwo_" + identifier);
+ }
+ };
+ }
+
+ public static ErrorPage createErrorPageWithServiceId(String identifier, ExtServletContext context)
+ {
+ return createErrorPage(identifier, context, ID_COUNTER.incrementAndGet());
+ }
+
+ public static ErrorPage createErrorPage(String identifier, ExtServletContext context)
+ {
+ return createErrorPage(identifier, context, -ID_COUNTER.incrementAndGet());
+ }
+
+ private static ErrorPage createErrorPage(String identifier,
+ ExtServletContext context,
+ Long serviceId)
+ {
+ ServletHandler servletHandler = createTestServlet(identifier, context, serviceId);
+ Collection<Integer> errorCodes = Arrays.asList(400, 500);
+ Collection<String> exceptions = Arrays.asList("Bad request", "Error");
+
+ return new ErrorPage(servletHandler, errorCodes, exceptions);
+ }
+
+ public static ServletContextHelperInfo createContextInfo(int serviceRanking,
+ long serviceId,
+ String name,
+ String path,
+ Map<String, String> initParams)
+ {
+ return new ServletContextHelperInfo(serviceRanking,
+ serviceId,
+ name,
+ path,
+ initParams);
+ }
+}
Propchange: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
------------------------------------------------------------------------------
svn:eol-style = native