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/01/29 11:21:04 UTC
svn commit: r1655576 [1/2] - in /felix/sandbox/http-rfc189/whiteboard/src:
main/java/org/apache/felix/http/whiteboard/
main/java/org/apache/felix/http/whiteboard/internal/
main/java/org/apache/felix/http/whiteboard/internal/manager/
main/java/org/apach...
Author: cziegeler
Date: Thu Jan 29 10:21:03 2015
New Revision: 1655576
URL: http://svn.apache.org/r1655576
Log:
Move 189 whiteboard handling to base
Removed:
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextBridge.java
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ResourceMapping.java
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ResourceTracker.java
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletContextHelperTracker.java
Modified:
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/DefaultHttpContext.java (props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/package-info.java
felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerTest.java
felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/FilterMappingTest.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManagerTest.java (contents, props changed)
felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ServletMappingTest.java (contents, props changed)
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java Thu Jan 29 10:21:03 2015
@@ -73,11 +73,7 @@ public class HttpWhiteboardConstants
* <code>Boolean.booleanValue()</code> or by
* <code>Boolean.valueOf(String)</code>) will the <code>HttpContext</code>
* be shared.
- *
- * @deprecated
- * @see org.osgi.service.http.HttpConstants#HTTP_WHITEBOARD_CONTEXT_SHARED
*/
- @Deprecated
public static final String CONTEXT_SHARED = "context.shared";
/**
@@ -94,11 +90,7 @@ public class HttpWhiteboardConstants
* <p>
* The value of this service registration property is a single string
* starting with a slash.
- *
- * @deprecated
- * @see org.osgi.service.http.HttpConstants#HTTP_WHITEBOARD_SERVLET_PATTERN
*/
- @Deprecated
public static final String ALIAS = "alias";
/**
@@ -120,37 +112,15 @@ public class HttpWhiteboardConstants
* <b>Note:</b> <code>Filter</code> services are only supported if the Http
* Service implements the
* <code>org.apache.felix.http.api.ExtHttpService</code> interface.
- *
- * @deprecated
- * @see org.osgi.service.http.HttpConstants#HTTP_WHITEBOARD_SERVLET_PATTERN
- * @see org.osgi.service.http.HttpConstants#HTTP_WHITEBOARD_FILTER_PATTERN
*/
- @Deprecated
public static final String PATTERN = "pattern";
/**
* Prefix for service registration properties being used as init parameters
* for the <code>Servlet</code> and <code>Filter</code> initialization.
- *
- * @deprecated
- * @see #SERVLET_INIT_PREFIX
- * @see #FILTER_INIT_PREFIX
*/
- @Deprecated
public static final String INIT_PREFIX = "init.";
- /**
- * Properties starting with this prefix are passed as servlet init parameters to the
- * {@code init()} method of the servlet.
- */
- public static final String SERVLET_INIT_PREFIX = "servlet.init.";
-
- /**
- * Properties starting with this prefix are passed as filter
- * init parameters to the {@code init()} method of the filter.
- */
- public static final String FILTER_INIT_PREFIX = "filter.init.";
-
// no instances
private HttpWhiteboardConstants()
{
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/HttpWhiteboardConstants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java Thu Jan 29 10:21:03 2015
@@ -16,23 +16,22 @@
*/
package org.apache.felix.http.whiteboard.internal;
-import java.util.ArrayList;
-import java.util.Hashtable;
-
-import org.apache.felix.http.base.internal.AbstractActivator;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
-import org.apache.felix.http.whiteboard.internal.manager.HttpWhiteboardWebConsolePlugin;
-import org.apache.felix.http.whiteboard.internal.tracker.FilterTracker;
-import org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker;
-import org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker;
-import org.apache.felix.http.whiteboard.internal.tracker.ServletContextHelperTracker;
-import org.apache.felix.http.whiteboard.internal.tracker.ServletTracker;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
+import org.apache.felix.http.whiteboard.internal.tracker.FilterTracker;
+import org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker;
+import org.apache.felix.http.whiteboard.internal.tracker.ServletTracker;
+import org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker;
+import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
+import org.apache.felix.http.whiteboard.internal.manager.HttpWhiteboardWebConsolePlugin;
+import org.apache.felix.http.base.internal.AbstractActivator;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+import java.util.ArrayList;
+import java.util.Hashtable;
-public final class WhiteboardActivator extends AbstractActivator
+public final class WhiteboardActivator
+ extends AbstractActivator
{
private final ArrayList<ServiceTracker> trackers;
private ExtenderManager manager;
@@ -43,20 +42,21 @@ public final class WhiteboardActivator e
this.trackers = new ArrayList<ServiceTracker>();
}
- protected void doStart() throws Exception
+ protected void doStart()
+ throws Exception
{
this.manager = new ExtenderManager();
addTracker(new HttpContextTracker(getBundleContext(), this.manager));
addTracker(new FilterTracker(getBundleContext(), this.manager));
addTracker(new ServletTracker(getBundleContext(), this.manager));
addTracker(new HttpServiceTracker(getBundleContext(), this.manager));
- addTracker(new ServletContextHelperTracker(getBundleContext(), this.manager));
HttpWhiteboardWebConsolePlugin plugin = new HttpWhiteboardWebConsolePlugin(this.manager);
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("felix.webconsole.label", plugin.getLabel());
props.put("felix.webconsole.title", plugin.getTitle());
- props.put("felix.webconsole.configprinter.modes", new String[] { "txt", "zip" });
+ props.put("felix.webconsole.configprinter.modes", new String[]
+ { "txt", "zip" });
props.put(Constants.SERVICE_DESCRIPTION, "Felix Http Whiteboard WebConsole Plugin and Configuration Printer");
httpPlugin = getBundleContext().registerService("javax.servlet.Servlet", plugin, props);
@@ -69,12 +69,12 @@ public final class WhiteboardActivator e
tracker.open();
}
- protected void doStop() throws Exception
+ protected void doStop()
+ throws Exception
{
this.httpPlugin.unregister();
- for (ServiceTracker tracker : this.trackers)
- {
+ for (ServiceTracker tracker : this.trackers) {
tracker.close();
}
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java Thu Jan 29 10:21:03 2015
@@ -70,5 +70,4 @@ abstract class AbstractMapping
public abstract void register(HttpService httpService);
public abstract void unregister(HttpService httpService);
-
}
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/DefaultHttpContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java Thu Jan 29 10:21:03 2015
@@ -21,36 +21,28 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.api.FilterInfo;
-import org.apache.felix.http.api.ServletInfo;
import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.whiteboard.HttpWhiteboardConstants;
import org.apache.felix.http.whiteboard.internal.manager.HttpContextManager.HttpContextHolder;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
-import org.osgi.service.http.context.ServletContextHelper;
-import org.osgi.service.http.runtime.dto.ResourceDTO;
-import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
-@SuppressWarnings({ "deprecation" })
public final class ExtenderManager
{
static final String TYPE_FILTER = "f";
static final String TYPE_SERVLET = "s";
- static final String TYPE_RESOURCE = "r";
+ private HttpService httpService;
private final Map<String, AbstractMapping> mapping;
private final HttpContextManager contextManager;
- private volatile HttpService httpService;
-
public ExtenderManager()
{
this.mapping = new HashMap<String, AbstractMapping>();
@@ -62,44 +54,10 @@ public final class ExtenderManager
return value == null || value.length() == 0;
}
- static boolean isEmpty(final String[] value)
- {
- return value == null || value.length == 0;
- }
-
private String getStringProperty(ServiceReference ref, String key)
{
Object value = ref.getProperty(key);
- return (value instanceof String) ? (String) value : null;
- }
-
- private String[] getStringArrayProperty(ServiceReference ref, String key)
- {
- Object value = ref.getProperty(key);
-
- if (value instanceof String)
- {
- return new String[] { (String) value };
- }
- else if (value instanceof String[])
- {
- return (String[]) value;
- }
- else if (value instanceof Collection<?>)
- {
- Collection<?> collectionValues = (Collection<?>) value;
- String[] values = new String[collectionValues.size()];
-
- int i = 0;
- for (Object current : collectionValues)
- {
- values[i++] = current != null ? String.valueOf(current) : null;
- }
-
- return values;
- }
-
- return null;
+ return (value instanceof String) ? (String)value : null;
}
private boolean getBooleanProperty(ServiceReference ref, String key)
@@ -119,48 +77,25 @@ public final class ExtenderManager
private int getIntProperty(ServiceReference ref, String key, int defValue)
{
Object value = ref.getProperty(key);
- if (value == null)
- {
+ if (value == null) {
return defValue;
}
- try
- {
+ try {
return Integer.parseInt(value.toString());
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
return defValue;
}
}
private void addInitParams(ServiceReference ref, AbstractMapping mapping)
{
- for (String key : ref.getPropertyKeys())
- {
- String prefixKey = null;
-
- if (mapping instanceof FilterMapping && key.startsWith(org.apache.felix.http.whiteboard.HttpWhiteboardConstants.FILTER_INIT_PREFIX))
- {
- prefixKey = org.apache.felix.http.whiteboard.HttpWhiteboardConstants.FILTER_INIT_PREFIX;
- }
- else if (mapping instanceof ServletMapping && key.startsWith(org.apache.felix.http.whiteboard.HttpWhiteboardConstants.SERVLET_INIT_PREFIX))
- {
- prefixKey = org.apache.felix.http.whiteboard.HttpWhiteboardConstants.SERVLET_INIT_PREFIX;
- }
- else if (key.startsWith(org.apache.felix.http.whiteboard.HttpWhiteboardConstants.INIT_PREFIX))
- {
- // keep the backward compatibility
- prefixKey = org.apache.felix.http.whiteboard.HttpWhiteboardConstants.INIT_PREFIX;
- }
-
- if (prefixKey != null)
- {
- String paramKey = key.substring(prefixKey.length());
+ for (String key : ref.getPropertyKeys()) {
+ if (key.startsWith(HttpWhiteboardConstants.INIT_PREFIX)) {
+ String paramKey = key.substring(HttpWhiteboardConstants.INIT_PREFIX.length());
String paramValue = getStringProperty(ref, key);
- if (paramValue != null)
- {
+ if (paramValue != null) {
mapping.getInitParams().put(paramKey, paramValue);
}
}
@@ -169,10 +104,10 @@ public final class ExtenderManager
public void add(HttpContext service, ServiceReference ref)
{
- String contextId = getStringProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.CONTEXT_ID);
+ String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
if (!isEmpty(contextId))
{
- boolean shared = getBooleanProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.CONTEXT_SHARED);
+ boolean shared = getBooleanProperty(ref, HttpWhiteboardConstants.CONTEXT_SHARED);
Bundle bundle = shared ? null : ref.getBundle();
Collection<AbstractMapping> mappings = this.contextManager.addHttpContext(bundle, contextId, service);
for (AbstractMapping mapping : mappings)
@@ -182,7 +117,8 @@ public final class ExtenderManager
}
else
{
- SystemLogger.debug("Ignoring HttpContext Service " + ref + ", " + org.apache.felix.http.whiteboard.HttpWhiteboardConstants.CONTEXT_ID + " is missing or empty");
+ SystemLogger.debug("Ignoring HttpContext Service " + ref + ", " + HttpWhiteboardConstants.CONTEXT_ID
+ + " is missing or empty");
}
}
@@ -198,184 +134,49 @@ public final class ExtenderManager
}
}
- public void add(ServletContextHelper service, ServiceReference ref)
- {
- String name = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME);
- String path = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH);
-
- // TODO - check if name and path are valid values
- if (!isEmpty(name) && !isEmpty(path) )
- {
- Collection<AbstractMapping> mappings = this.contextManager.addContextHelper(ref.getBundle(), name, path, service);
- for (AbstractMapping mapping : mappings)
- {
- registerMapping(mapping);
- }
- }
- else
- {
- SystemLogger.debug("Ignoring ServletContextHelper Service " + ref + ", " + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + " is missing or empty");
- }
- }
-
- public void addResource(final ServiceReference ref)
- {
- final String[] pattern = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN);
- final String prefix = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
-
- if (!isEmpty(pattern))
- {
- if ( !isEmpty(prefix))
- {
- for(final String p : pattern)
- {
- // TODO : check if p is empty - and then log?
- final ResourceDTO resourceDTO = new ResourceDTO();
- resourceDTO.patterns = new String[] {p};
- resourceDTO.prefix = prefix;
- final ResourceMapping mapping = new ResourceMapping(ref.getBundle(), resourceDTO);
- this.addMapping(TYPE_RESOURCE, ref, mapping);
- }
- }
- else
- {
- SystemLogger.debug("Ignoring Resource Service " + ref + ", " + HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX + " is missing or empty");
- }
- }
- else
- {
- SystemLogger.debug("Ignoring Resource Service " + ref + ", " + HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN + " is missing or empty");
- }
- }
-
- public void removeResource(final ServiceReference ref)
- {
- this.removeMapping(TYPE_RESOURCE, ref);
- }
-
- public void remove(ServletContextHelper service)
- {
- Collection<AbstractMapping> mappings = this.contextManager.removeContextHelper(service);
- if (mappings != null)
- {
- for (AbstractMapping mapping : mappings)
- {
- unregisterMapping(mapping);
- }
- }
- }
-
- private HttpContext getHttpContext(AbstractMapping mapping, ServiceReference ref)
+ private void getHttpContext(AbstractMapping mapping, ServiceReference ref)
{
Bundle bundle = ref.getBundle();
- String contextName = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
- if (!isEmpty(contextName))
- {
- return this.contextManager.getHttpContext(bundle, contextName, mapping, true);
- }
- String contextId = getStringProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.CONTEXT_ID);
- return this.contextManager.getHttpContext(bundle, contextId, mapping);
+ String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
+ this.contextManager.getHttpContext(bundle, contextId, mapping);
}
private void ungetHttpContext(AbstractMapping mapping, ServiceReference ref)
{
Bundle bundle = ref.getBundle();
- String contextName = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
- if (!isEmpty(contextName))
- {
- this.contextManager.ungetHttpContext(bundle, contextName, mapping, true);
- return;
- }
- String contextId = getStringProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.CONTEXT_ID);
+ String contextId = getStringProperty(ref, HttpWhiteboardConstants.CONTEXT_ID);
this.contextManager.ungetHttpContext(bundle, contextId, mapping);
}
- public void add(final Filter service, final ServiceReference ref)
+ public void add(Filter service, ServiceReference ref)
{
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.name = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_NAME);
- if ( filterInfo.name == null || filterInfo.name.isEmpty() )
- {
- filterInfo.name = service.getClass().getName();
- }
- filterInfo.asyncSupported = getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED);
- filterInfo.servletNames = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_SERVLET);
- filterInfo.patterns = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN);
- filterInfo.ranking = getIntProperty(ref, Constants.SERVICE_RANKING, 0);
+ int ranking = getIntProperty(ref, Constants.SERVICE_RANKING, 0);
+ String pattern = getStringProperty(ref, HttpWhiteboardConstants.PATTERN);
- String[] dispatcherNames = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_DISPATCHER);
- if (dispatcherNames != null && dispatcherNames.length > 0)
- {
- DispatcherType[] dispatchers = new DispatcherType[dispatcherNames.length];
- for (int i = 0; i < dispatchers.length; i++)
- {
- dispatchers[i] = DispatcherType.valueOf(dispatcherNames[i].toUpperCase());
- }
- filterInfo.dispatcher = dispatchers;
- }
-
- if (isEmpty(filterInfo.patterns))
- {
- // fallback to backward compatible property
- String pattern = getStringProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.PATTERN);
-
- if (isEmpty(pattern))
- {
- SystemLogger.debug("Ignoring Filter Service " + ref + ", " + HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN + " (or deprecated "
- + org.apache.felix.http.whiteboard.HttpWhiteboardConstants.PATTERN + ") is missing or empty");
- return;
- }
-
- filterInfo.patterns = new String[] { pattern };
+ if (isEmpty(pattern)) {
+ SystemLogger.debug("Ignoring Filter Service " + ref + ", " + HttpWhiteboardConstants.PATTERN
+ + " is missing or empty");
+ return;
}
- FilterMapping mapping = new FilterMapping(ref.getBundle(), service, filterInfo);
- filterInfo.context = getHttpContext(mapping, ref); // XXX
+ FilterMapping mapping = new FilterMapping(ref.getBundle(), service, pattern, ranking);
+ getHttpContext(mapping, ref);
addInitParams(ref, mapping);
addMapping(TYPE_FILTER, ref, mapping);
}
public void add(Servlet service, ServiceReference ref)
{
- ServletInfo servletInfo = new ServletInfo();
- servletInfo.name = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME);
- if ( servletInfo.name == null || servletInfo.name.isEmpty() )
- {
- servletInfo.name = service.getClass().getName();
- }
- servletInfo.errorPage = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE);
- servletInfo.patterns = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
- servletInfo.asyncSupported = getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED);
-
- if (isEmpty(servletInfo.patterns))
+ String alias = getStringProperty(ref, HttpWhiteboardConstants.ALIAS);
+ if (isEmpty(alias))
{
- // fallback to backward compatible property
- String pattern = getStringProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.PATTERN);
-
- if (isEmpty(pattern))
- {
- String alias = getStringProperty(ref, org.apache.felix.http.whiteboard.HttpWhiteboardConstants.ALIAS);
-
- if (isEmpty(alias))
- {
- SystemLogger.debug("Ignoring Servlet Service " + ref + ", " + HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN + " (or deprecated "
- + org.apache.felix.http.whiteboard.HttpWhiteboardConstants.PATTERN + " or deprecated " + org.apache.felix.http.whiteboard.HttpWhiteboardConstants.ALIAS
- + ") is missing or empty");
- return;
- }
- else
- {
- servletInfo.patterns = new String[] { alias };
- }
- }
- else
- {
- servletInfo.patterns = new String[] { pattern };
- }
+ SystemLogger.debug("Ignoring Servlet Service " + ref + ", " + HttpWhiteboardConstants.ALIAS
+ + " is missing or empty");
+ return;
}
- final ServletMapping mapping = new ServletMapping(ref.getBundle(), service, servletInfo);
- servletInfo.context = getHttpContext(mapping, ref); // XXX
+ ServletMapping mapping = new ServletMapping(ref.getBundle(), service, alias);
+ getHttpContext(mapping, ref);
addInitParams(ref, mapping);
addMapping(TYPE_SERVLET, ref, mapping);
}
@@ -393,14 +194,12 @@ public final class ExtenderManager
public synchronized void setHttpService(HttpService service)
{
this.httpService = service;
- if (this.httpService instanceof ExtHttpService)
- {
+ if (this.httpService instanceof ExtHttpService) {
SystemLogger.info("Detected extended HttpService. Filters enabled.");
- }
- else
- {
+ } else {
SystemLogger.info("Detected standard HttpService. Filters disabled.");
}
+
registerAll();
}
@@ -412,57 +211,49 @@ public final class ExtenderManager
public synchronized void unregisterAll()
{
- AbstractMapping[] mappings = null;
- HttpService service;
- synchronized (this)
- {
- service = this.httpService;
- if (service != null)
- {
- Collection<AbstractMapping> values = this.mapping.values();
- mappings = values.toArray(new AbstractMapping[values.size()]);
- }
- }
- if (mappings != null)
- {
- for (AbstractMapping mapping : mappings)
- {
- mapping.unregister(service);
- }
- }
+ AbstractMapping[] mappings = null;
+ HttpService service;
+ synchronized (this) {
+ service = this.httpService;
+ if (service != null) {
+ Collection<AbstractMapping> values = this.mapping.values();
+ mappings = values.toArray(new AbstractMapping[values.size()]);
+ }
+ }
+ if (mappings != null) {
+ for (AbstractMapping mapping : mappings) {
+ mapping.unregister(service);
+ }
+ }
}
private synchronized void registerAll()
{
- AbstractMapping[] mappings = null;
- HttpService service;
- synchronized (this)
- {
- service = this.httpService;
- if (service != null)
- {
- Collection<AbstractMapping> values = this.mapping.values();
- mappings = values.toArray(new AbstractMapping[values.size()]);
- }
- }
- if (mappings != null)
- {
- for (AbstractMapping mapping : mappings)
- {
- mapping.register(service);
- }
- }
+ AbstractMapping[] mappings = null;
+ HttpService service;
+ synchronized (this) {
+ service = this.httpService;
+ if (service != null) {
+ Collection<AbstractMapping> values = this.mapping.values();
+ mappings = values.toArray(new AbstractMapping[values.size()]);
+ }
+ }
+ if (mappings != null) {
+ for (AbstractMapping mapping : mappings) {
+ mapping.register(service);
+ }
+ }
}
private synchronized void addMapping(final String servType, ServiceReference ref, AbstractMapping mapping)
{
- this.mapping.put(ref.getProperty(Constants.SERVICE_ID).toString().concat(servType), mapping);
+ this.mapping.put(ref.getProperty(Constants.SERVICE_ID).toString() + servType, mapping);
this.registerMapping(mapping);
}
private synchronized void removeMapping(final String servType, ServiceReference ref)
{
- AbstractMapping mapping = this.mapping.remove(ref.getProperty(Constants.SERVICE_ID).toString().concat(servType));
+ AbstractMapping mapping = this.mapping.remove(ref.getProperty(Constants.SERVICE_ID).toString() + servType);
if (mapping != null)
{
ungetHttpContext(mapping, ref);
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java Thu Jan 29 10:21:03 2015
@@ -19,7 +19,6 @@ package org.apache.felix.http.whiteboard
import javax.servlet.Filter;
import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.api.FilterInfo;
import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpService;
@@ -27,40 +26,40 @@ import org.osgi.service.http.HttpService
public final class FilterMapping extends AbstractMapping
{
private final Filter filter;
- private final FilterInfo filterInfo;
+ private final int ranking;
+ private final String pattern;
- public FilterMapping(Bundle bundle, Filter filter, FilterInfo filterInfo)
+ public FilterMapping(Bundle bundle, Filter filter, String pattern, int ranking)
{
super(bundle);
this.filter = filter;
- this.filterInfo = filterInfo;
+ this.pattern = pattern;
+ this.ranking = ranking;
}
- @Override
public void register(HttpService httpService)
{
- if (!isRegistered() && (httpService instanceof ExtHttpService) && getContext() != null)
+ if (httpService instanceof ExtHttpService)
{
register((ExtHttpService) httpService);
}
else
{
// Warn the user that something strange is going on...
- SystemLogger.warning("Unable to register filter for " + this.filterInfo.name + ", as no ExtHttpService seems to be present!", null);
+ SystemLogger.warning("Unable to register filter for " + this.pattern + ", as no ExtHttpService seems to be present!", null);
}
}
- @Override
public void unregister(HttpService httpService)
{
- if (isRegistered() && (httpService instanceof ExtHttpService))
+ if (httpService instanceof ExtHttpService)
{
unregister((ExtHttpService) httpService);
}
else
{
// Warn the user that something strange is going on...
- SystemLogger.warning("Unable to unregister filter for " + this.filterInfo.name + ", as no ExtHttpService seems to be present!", null);
+ SystemLogger.warning("Unable to unregister filter for " + this.pattern + ", as no ExtHttpService seems to be present!", null);
}
}
@@ -69,20 +68,30 @@ public final class FilterMapping extends
return filter;
}
+ String getPattern()
+ {
+ return pattern;
+ }
+
+ int getRanking()
+ {
+ return ranking;
+ }
+
private void register(ExtHttpService httpService)
{
if (!isRegistered() && getContext() != null)
{
try
{
- httpService.registerFilter(this.filter, this.filterInfo);
+ httpService.registerFilter(this.filter, this.pattern, getInitParams(), ranking, getContext());
setRegistered(true);
}
catch (Exception e)
{
// Warn that something might have gone astray...
- SystemLogger.warning("Failed to register filter for " + this.filterInfo.name, null);
- SystemLogger.debug("Failed to register filter for " + this.filterInfo.name + "; details:", e);
+ SystemLogger.warning("Failed to register filter for " + this.pattern, null);
+ SystemLogger.debug("Failed to register filter for " + this.pattern + "; details:", e);
}
}
}
@@ -98,7 +107,7 @@ public final class FilterMapping extends
catch (Exception e)
{
// Warn that something might have gone astray...
- SystemLogger.debug("Failed to unregister filter for " + this.filterInfo.name, e);
+ SystemLogger.debug("Failed to unregister filter for " + this.pattern, e);
}
finally
{
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java Thu Jan 29 10:21:03 2015
@@ -16,6 +16,10 @@
*/
package org.apache.felix.http.whiteboard.internal.manager;
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -23,11 +27,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.osgi.framework.Bundle;
-import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.context.ServletContextHelper;
-
public final class HttpContextManager
{
/**
@@ -42,18 +41,12 @@ public final class HttpContextManager
private final HashMap<String, HttpContextHolder> idMap;
/**
- * Reverse mapping of HttpContext services to the context ID or
- * name with which they are registered.
+ * Reverse mapping of HttpContext services to the context ID with
+ * which they are registered.
*/
private final HashMap<HttpContext, String> contextMap;
/**
- * Mapping of registered ServletContextHelper services to the
- * HttpContext stored in <code>contextMap</code>.
- */
- private final HashMap<ServletContextHelper, HttpContext> helperMap;
-
- /**
* Map of servlets and filters registered referring to unregistered
* contexts as of yet.
*/
@@ -63,16 +56,11 @@ public final class HttpContextManager
{
this.idMap = new HashMap<String, HttpContextHolder>();
this.contextMap = new HashMap<HttpContext, String>();
- this.helperMap = new HashMap<ServletContextHelper, HttpContext>();
this.orphanMappings = new HashMap<String, Set<AbstractMapping>>();
}
- private static String createId(Bundle bundle, String contextId, boolean isContextHelper)
+ private static String createId(Bundle bundle, String contextId)
{
- if (isContextHelper)
- {
- return "servletcontexthelper-" + ((contextId == null) ? "" : contextId);
- }
if (bundle != null)
{
return bundle.getBundleId() + "-" + ((contextId == null) ? "" : contextId);
@@ -94,14 +82,8 @@ public final class HttpContextManager
public synchronized HttpContext getHttpContext(Bundle bundle, String contextId, AbstractMapping mapping)
{
- return getHttpContext(bundle, contextId, mapping, false);
- }
-
- public synchronized HttpContext getHttpContext(Bundle bundle, String contextId, AbstractMapping mapping,
- boolean isContextHelper)
- {
// per-bundle context
- String id = createId(bundle, contextId, isContextHelper);
+ String id = createId(bundle, contextId);
HttpContextHolder holder = this.idMap.get(id);
// shared context
@@ -150,18 +132,12 @@ public final class HttpContextManager
public synchronized void ungetHttpContext(Bundle bundle, String contextId, AbstractMapping mapping)
{
- ungetHttpContext(bundle, contextId, mapping, false);
- }
-
- public synchronized void ungetHttpContext(Bundle bundle, String contextId,
- AbstractMapping mapping, boolean isContextHelper)
- {
// per-bundle context
- String id = createId(bundle, contextId, isContextHelper);
+ String id = createId(bundle, contextId);
HttpContextHolder context = this.idMap.get(id);
// shared context
- if (context == null && !isContextHelper)
+ if (context == null)
{
id = createId(contextId);
context = this.idMap.get(id);
@@ -191,7 +167,7 @@ public final class HttpContextManager
public synchronized Collection<AbstractMapping> addHttpContext(Bundle bundle, String contextId, HttpContext context)
{
- String id = createId(bundle, contextId, false);
+ String id = createId(bundle, contextId);
HttpContextHolder holder = new HttpContextHolder(context);
Set<AbstractMapping> orphans = this.orphanMappings.remove(contextId);
@@ -221,39 +197,6 @@ public final class HttpContextManager
return new HashSet<AbstractMapping>(holder.getMappings());
}
- public synchronized Collection<AbstractMapping> addContextHelper(Bundle bundle, String contextName, String contextPath,
- ServletContextHelper contextHelper)
- {
- String id = createId(bundle, contextName, true);
- HttpContextHolder holder = new HttpContextHolder(contextHelper, contextPath);
-
- Set<AbstractMapping> orphans = this.orphanMappings.remove(contextName);
- if (orphans != null)
- {
- for (Iterator<AbstractMapping> mi = orphans.iterator(); mi.hasNext();)
- {
- AbstractMapping mapping = mi.next();
- if (bundle == null || bundle.equals(mapping.getBundle()))
- {
- holder.addMapping(mapping);
- mi.remove();
- }
- }
-
- // put any remaining orphans back
- if (!orphans.isEmpty())
- {
- this.orphanMappings.put(contextName, orphans);
- }
- }
-
- this.idMap.put(id, holder);
- this.contextMap.put(holder.getContext(), id);
- this.helperMap.put(contextHelper, holder.getContext());
-
- return holder.getMappings();
- }
-
public synchronized Collection<AbstractMapping> removeHttpContext(HttpContext context)
{
String id = this.contextMap.remove(context);
@@ -286,16 +229,6 @@ public final class HttpContextManager
return null;
}
- public synchronized Collection<AbstractMapping> removeContextHelper(ServletContextHelper contextHelper)
- {
- HttpContext context = this.helperMap.remove(contextHelper);
- if (context != null)
- {
- return removeHttpContext(context);
- }
- return null;
- }
-
synchronized Map<String, HttpContextHolder> getHttpContexts()
{
return new HashMap<String, HttpContextHolder>(this.idMap);
@@ -310,21 +243,11 @@ public final class HttpContextManager
{
private final HttpContext context;
private final Set<AbstractMapping> mappings;
- private final String path;
HttpContextHolder(final HttpContext context)
{
this.context = context;
this.mappings = new HashSet<AbstractMapping>();
- this.path = null;
- }
-
- HttpContextHolder(final ServletContextHelper context,
- final String path)
- {
- this.context = new HttpContextBridge(context);
- this.mappings = new HashSet<AbstractMapping>();
- this.path = path;
}
public HttpContext getContext()
@@ -332,15 +255,10 @@ public final class HttpContextManager
return context;
}
- public String getPath()
- {
- return path;
- }
-
void addMapping(AbstractMapping mapping)
{
this.mappings.add(mapping);
- mapping.setContext(getContext());
+ mapping.setContext(this.getContext());
}
void removeMapping(AbstractMapping mapping)
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java Thu Jan 29 10:21:03 2015
@@ -20,9 +20,9 @@ package org.apache.felix.http.whiteboard
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -125,7 +125,7 @@ public class HttpWhiteboardWebConsolePlu
for (ServletMapping sm : mappings.values())
{
pw.println("<tr class='content'>");
- // pw.println("<td class='content'>" + Arrays.toString(sm.getDto().patterns) + "</td>"); XXX
+ pw.println("<td class='content'>" + sm.getAlias() + "</td>");
pw.println("<td class='content'>" + sm.getServlet() + "</td>");
pw.println("<td class='content'>" + sm.getInitParams() + "</td>");
pw.println("<td class='content'>" + sm.getContext() + "</td>");
@@ -148,8 +148,8 @@ public class HttpWhiteboardWebConsolePlu
for (FilterMapping fm : mappings)
{
pw.println("<tr class='content'>");
- // pw.println("<td class='content'>" + Arrays.toString(fm.getDto().patterns) + "</td>"); XXX
- // pw.println("<td class='content'>" + fm.getFilter() + " (" + fm.getRanking() + ")</td>"); XXX
+ pw.println("<td class='content'>" + fm.getPattern() + "</td>");
+ pw.println("<td class='content'>" + fm.getFilter() + " (" + fm.getRanking() + ")</td>");
pw.println("<td class='content'>" + fm.getInitParams() + "</td>");
pw.println("<td class='content'>" + fm.getContext() + "</td>");
pw.println("</tr>");
@@ -184,13 +184,13 @@ public class HttpWhiteboardWebConsolePlu
{
if (mapping instanceof ServletMapping)
{
- ServletMapping servletMapping = (ServletMapping) mapping;
-// pw.printf("Servlet %s (%s)", Arrays.toString(servletMapping.getDto().patterns), servletMapping.getServlet()); XXX
+ pw.printf("Servlet %s (%s)", ((ServletMapping) mapping).getAlias(),
+ ((ServletMapping) mapping).getServlet());
}
else if (mapping instanceof FilterMapping)
{
- FilterMapping filterMapping = (FilterMapping) mapping;
-// pw.printf("Filter %s (%s)", Arrays.toString(filterMapping.getDto().patterns), filterMapping.getFilter()); XXX
+ pw.printf("Filter %s (%s)", ((FilterMapping) mapping).getPattern(),
+ ((FilterMapping) mapping).getFilter());
}
pw.println("<br/>");
}
@@ -224,7 +224,8 @@ public class HttpWhiteboardWebConsolePlu
pw.println("Registered Servlet Services");
for (ServletMapping sm : mappings.values())
{
-// pw.printf(" %s ==> %s (%s, %s, %s)%n", Arrays.toString(sm.getDto().patterns), sm.getServlet(), sm.isRegistered() ? "registered" : "unregistered", sm.getInitParams(), sm.getContext()); XXX
+ pw.printf(" %s ==> %s (%s, %s, %s)%n", sm.getAlias(), sm.getServlet(), sm.isRegistered() ? "registered"
+ : "unregistered", sm.getInitParams(), sm.getContext());
}
pw.println();
}
@@ -234,7 +235,8 @@ public class HttpWhiteboardWebConsolePlu
pw.println("Registered Filter Services");
for (FilterMapping fm : mappings)
{
-// pw.printf(" %s ==> %s (%s, %s, %s, %s)%n", Arrays.toString(fm.getDto().patterns), fm.getFilter(), fm.isRegistered() ? "registered" : "unregistered", fm.getRanking(), fm.getInitParams(), fm.getContext()); XXX
+ pw.printf(" %s ==> %s (%s, %s, %s, %s)%n", fm.getPattern(), fm.getFilter(),
+ fm.isRegistered() ? "registered" : "unregistered", fm.getRanking(), fm.getInitParams(), fm.getContext());
}
pw.println();
}
@@ -266,13 +268,13 @@ public class HttpWhiteboardWebConsolePlu
if (mapping instanceof ServletMapping)
{
- ServletMapping servletMapping = (ServletMapping) mapping;
-// pw.printf("Servlet %s (%s)", Arrays.toString(servletMapping.getDto().patterns), servletMapping.getServlet()); XXX
+ pw.printf("Servlet %s (%s)", ((ServletMapping) mapping).getAlias(),
+ ((ServletMapping) mapping).getServlet());
}
else if (mapping instanceof FilterMapping)
{
- FilterMapping filterMapping = (FilterMapping) mapping;
-// pw.printf("Filter %s (%s)", Arrays.toString(filterMapping.getDto().patterns), filterMapping.getFilter()); XXX
+ pw.printf("Filter %s (%s)", ((FilterMapping) mapping).getPattern(),
+ ((FilterMapping) mapping).getFilter());
}
}
pw.println(" }");
@@ -292,11 +294,7 @@ public class HttpWhiteboardWebConsolePlu
{
if (mapping instanceof ServletMapping)
{
- ServletMapping servletMapping = (ServletMapping) mapping;
-// for (String pattern : servletMapping.getDto().patterns) XXX
-// {
-// mappings.put(pattern, (ServletMapping) mapping);
-// }
+ mappings.put(((ServletMapping) mapping).getAlias(), (ServletMapping) mapping);
}
}
return mappings;
@@ -312,25 +310,23 @@ public class HttpWhiteboardWebConsolePlu
{
return 0;
}
- // TODO improve how to compare string arrays!
-// int res = Arrays.equals(o1.getDto().patterns, o2.getDto().patterns) ? 0 : toIntegerPatternLength(o1).compareTo(toIntegerPatternLength(o2));
-// if (res == 0)
-// {
-// if (o1.getRanking() > o2.getRanking())
-// {
-// res = -1;
-// }
-// else if (o1.getRanking() < o2.getRanking())
-// {
-// res = 1;
-// }
-// else
-// {
-// res = o1.getFilter().toString().compareTo(o2.getFilter().toString());
-// }
-// }
-// return res;
- return 0; // XXX
+ int res = o1.getPattern().compareTo(o2.getPattern());
+ if (res == 0)
+ {
+ if (o1.getRanking() > o2.getRanking())
+ {
+ res = -1;
+ }
+ else if (o1.getRanking() < o2.getRanking())
+ {
+ res = 1;
+ }
+ else
+ {
+ res = o1.getFilter().toString().compareTo(o2.getFilter().toString());
+ }
+ }
+ return res;
}
});
for (AbstractMapping mapping : this.extMgr.getMappings().values())
@@ -343,12 +339,6 @@ public class HttpWhiteboardWebConsolePlu
return mappings;
}
- private static Integer toIntegerPatternLength(FilterMapping filterMapping)
- {
-// return Integer.valueOf(filterMapping.getDto().patterns.length);
- return Integer.valueOf(0); // XXX
- }
-
private Map<String, Set<AbstractMapping>> getOrphanMappings()
{
return new TreeMap<String, Set<AbstractMapping>>(this.extMgr.getOrphanMappings());
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpWhiteboardWebConsolePlugin.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java Thu Jan 29 10:21:03 2015
@@ -18,8 +18,6 @@ package org.apache.felix.http.whiteboard
import javax.servlet.Servlet;
-import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.api.ServletInfo;
import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpService;
@@ -27,48 +25,44 @@ import org.osgi.service.http.HttpService
public final class ServletMapping extends AbstractMapping
{
private final Servlet servlet;
- private final ServletInfo servletInfo;
+ private final String alias;
- public ServletMapping(Bundle bundle, Servlet servlet, ServletInfo servletInfo)
+ public ServletMapping(Bundle bundle, Servlet servlet, String alias)
{
super(bundle);
this.servlet = servlet;
- this.servletInfo = servletInfo;
+ this.alias = alias;
}
- @Override
public void register(HttpService httpService)
{
- if (!isRegistered() && (httpService instanceof ExtHttpService) && getContext() != null)
+ if (!isRegistered() && getContext() != null)
{
- this.servletInfo.context = getContext(); // XXX
try
{
- ((ExtHttpService) httpService).registerServlet(this.servlet, this.servletInfo);
+ httpService.registerServlet(this.alias, this.servlet, getInitParams(), getContext());
setRegistered(true);
}
catch (Exception e)
{
// Warn that something might have gone astray...
- SystemLogger.warning("Failed to register servlet for " + this.servletInfo.name, e);
+ SystemLogger.warning("Failed to register servlet for " + this.alias, e);
}
- setRegistered(true);
}
}
- @Override
public void unregister(HttpService httpService)
{
- if (isRegistered() && (httpService instanceof ExtHttpService))
+ if (isRegistered())
{
try
{
- ((ExtHttpService) httpService).unregisterServlet(this.servlet);
+ httpService.unregister(this.alias);
}
catch (Exception e)
{
// Warn that something might have gone astray...
- SystemLogger.debug("Failed to unregister servlet for " + this.servletInfo.name, e);
+ SystemLogger.debug("Failed to unregister servlet for " + this.alias, e);
}
finally
{
@@ -78,6 +72,11 @@ public final class ServletMapping extend
}
}
+ String getAlias()
+ {
+ return this.alias;
+ }
+
Servlet getServlet()
{
return this.servlet;
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java Thu Jan 29 10:21:03 2015
@@ -17,41 +17,36 @@
package org.apache.felix.http.whiteboard.internal.tracker;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
-public abstract class AbstractTracker<T> extends ServiceTracker
+public abstract class AbstractTracker<T>
+ extends ServiceTracker
{
- public AbstractTracker(final BundleContext context, final Class<T> clz)
+ public AbstractTracker(BundleContext context, Class<T> clz)
{
super(context, clz.getName(), null);
}
- public AbstractTracker(final BundleContext context, final Filter filter)
- {
- super(context, filter, null);
- }
-
@Override
@SuppressWarnings("unchecked")
- public final Object addingService(final ServiceReference ref)
+ public final Object addingService(ServiceReference ref)
{
- T service = (T) super.addingService(ref);
+ T service = (T)super.addingService(ref);
added(service, ref);
return service;
}
@Override
@SuppressWarnings("unchecked")
- public final void modifiedService(final ServiceReference ref, final Object service)
+ public final void modifiedService(ServiceReference ref, Object service)
{
modified( (T)service, ref);
}
@Override
@SuppressWarnings("unchecked")
- public final void removedService(final ServiceReference ref, final Object service)
+ public final void removedService(ServiceReference ref, Object service)
{
super.removedService(ref, service);
removed((T) service, ref);
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java Thu Jan 29 10:21:03 2015
@@ -22,7 +22,8 @@ import org.apache.felix.http.whiteboard.
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-public final class FilterTracker extends AbstractTracker<Filter>
+public final class FilterTracker
+ extends AbstractTracker<Filter>
{
private final ExtenderManager manager;
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java Thu Jan 29 10:21:03 2015
@@ -16,12 +16,13 @@
*/
package org.apache.felix.http.whiteboard.internal.tracker;
-import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
+import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
-public final class HttpContextTracker extends AbstractTracker<HttpContext>
+public final class HttpContextTracker
+ extends AbstractTracker<HttpContext>
{
private final ExtenderManager manager;
@@ -31,20 +32,17 @@ public final class HttpContextTracker ex
this.manager = manager;
}
- @Override
protected void added(HttpContext service, ServiceReference ref)
{
this.manager.add(service, ref);
}
- @Override
protected void modified(HttpContext service, ServiceReference ref)
{
removed(service, ref);
added(service, ref);
}
- @Override
protected void removed(HttpContext service, ServiceReference ref)
{
this.manager.remove(service);
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java Thu Jan 29 10:21:03 2015
@@ -21,7 +21,8 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;
-public final class HttpServiceTracker extends AbstractTracker<HttpService>
+public final class HttpServiceTracker
+ extends AbstractTracker<HttpService>
{
private final ExtenderManager manager;
@@ -31,19 +32,16 @@ public final class HttpServiceTracker ex
this.manager = manager;
}
- @Override
protected void added(HttpService service, ServiceReference ref)
{
this.manager.setHttpService(service);
}
- @Override
protected void modified(HttpService service, ServiceReference ref)
{
// Do nothing
}
- @Override
protected void removed(HttpService service, ServiceReference ref)
{
this.manager.unsetHttpService();
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java Thu Jan 29 10:21:03 2015
@@ -22,7 +22,8 @@ import org.apache.felix.http.whiteboard.
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-public final class ServletTracker extends AbstractTracker<Servlet>
+public final class ServletTracker
+ extends AbstractTracker<Servlet>
{
private final ExtenderManager manager;
Propchange: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/package-info.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/package-info.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/package-info.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/main/java/org/apache/felix/http/whiteboard/package-info.java Thu Jan 29 10:21:03 2015
@@ -20,7 +20,7 @@
/**
* @see: @TODO ref to whiteboard page on felix.apache.org
*/
-@Version("1.1")
+@Version("1.0")
@Export(optional = "provide:=true")
package org.apache.felix.http.whiteboard;
Modified: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerTest.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerTest.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerTest.java Thu Jan 29 10:21:03 2015
@@ -24,16 +24,12 @@ import java.util.Dictionary;
import javax.servlet.Filter;
import javax.servlet.Servlet;
-import javax.servlet.ServletException;
import junit.framework.TestCase;
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.api.ExtHttpServiceRuntime;
-import org.apache.felix.http.api.FilterInfo;
-import org.apache.felix.http.api.ServletInfo;
import org.apache.felix.http.whiteboard.HttpWhiteboardConstants;
import org.junit.After;
import org.junit.Before;
@@ -45,12 +41,6 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.NamespaceException;
-import org.osgi.service.http.context.ServletContextHelper;
-import org.osgi.service.http.runtime.dto.FilterDTO;
-import org.osgi.service.http.runtime.dto.RequestInfoDTO;
-import org.osgi.service.http.runtime.dto.RuntimeDTO;
-import org.osgi.service.http.runtime.dto.ServletDTO;
@RunWith(MockitoJUnitRunner.class)
public class ExtenderManagerTest
@@ -74,9 +64,6 @@ public class ExtenderManagerTest
private HttpContext sampleContext;
@Mock
- private ServletContextHelper sampleContextHelper;
-
- @Mock
private Bundle bundle1;
@Mock
@@ -125,16 +112,12 @@ public class ExtenderManagerTest
@Mock
private ServiceReference httpContextReference;
- @Mock
- private ServiceReference contextHelperReference;
-
@Before
public void setup()
{
when(bundle1.getBundleId()).thenReturn(BUNDLE_1_ID);
when(bundle2.getBundleId()).thenReturn(BUNDLE_2_ID);
when(httpContextReference.getBundle()).thenReturn(bundle1);
- when(contextHelperReference.getBundle()).thenReturn(bundle2);
when(servlet1Reference.getBundle()).thenReturn(bundle1);
when(servlet1Reference.getPropertyKeys()).thenReturn(new String[0]);
@@ -735,7 +718,7 @@ public class ExtenderManagerTest
TestCase.assertEquals(1, this.httpService.getFilters().size());
TestCase.assertSame(filter1, this.httpService.getFilters().get(SERVLET_1_ALIAS));
TestCase.assertTrue(em.getOrphanMappings().isEmpty());
-// TestCase.assertSame(sampleContext, filter1.getHttpContext()); XXX
+ TestCase.assertSame(sampleContext, filter1.getHttpContext());
// unregister context
em.remove(sampleContext);
@@ -795,7 +778,7 @@ public class ExtenderManagerTest
TestCase.assertEquals(1, this.httpService.getFilters().size());
TestCase.assertSame(filter1, this.httpService.getFilters().get(SERVLET_1_ALIAS));
TestCase.assertTrue(em.getOrphanMappings().isEmpty());
-// TestCase.assertSame(sampleContext, filter1.getHttpContext()); XXX
+ TestCase.assertSame(sampleContext, filter1.getHttpContext());
// unregister context
em.remove(sampleContext);
@@ -892,6 +875,7 @@ public class ExtenderManagerTest
return filters;
}
+ @Override
public void registerServlet(String alias, Servlet servlet, @SuppressWarnings("rawtypes") Dictionary initparams,
HttpContext context)
@@ -905,31 +889,13 @@ public class ExtenderManagerTest
when(((ExtServlet) servlet).getHttpContext()).thenReturn(context);
}
+ @Override
public void registerResources(String alias, String name, HttpContext context)
{
// not used here
}
- public void registerFilter(Filter filter, FilterInfo filterInfo) throws ServletException
- {
- for (String pattern : filterInfo.patterns)
- {
- this.filters.put(pattern, filter);
- }
- // make HttpContext available
- when(((ExtFilter) filter).getHttpContext()).thenReturn(filterInfo.context);
- }
-
- public void registerServlet(Servlet servlet, ServletInfo servletInfo) throws ServletException, NamespaceException
- {
- for (String pattern : servletInfo.patterns)
- {
- this.servlets.put(pattern, servlet);
- }
- // make HttpContext available
- when(((ExtServlet) servlet).getHttpContext()).thenReturn(servletInfo.context);
- }
-
+ @Override
public void unregister(String alias)
{
Object servlet = this.servlets.remove(alias);
@@ -939,12 +905,14 @@ public class ExtenderManagerTest
}
}
+ @Override
public HttpContext createDefaultHttpContext()
{
// not used here
return null;
}
+ @Override
public void registerFilter(Filter filter, String pattern, @SuppressWarnings("rawtypes") Dictionary initParams,
int ranking, HttpContext context)
{
@@ -957,44 +925,18 @@ public class ExtenderManagerTest
when(((ExtFilter) filter).getHttpContext()).thenReturn(context);
}
+ @Override
public void unregisterFilter(Filter filter)
{
this.filters.removeValue(filter);
when(((ExtFilter) filter).getHttpContext()).thenReturn(null);
}
+ @Override
public void unregisterServlet(Servlet servlet)
{
this.servlets.removeValue(servlet);
when(((ExtServlet) servlet).getHttpContext()).thenReturn(null);
}
}
-
- static final class MockHttpServiceRuntime implements ExtHttpServiceRuntime
- {
-
- public RuntimeDTO getRuntimeDTO()
- {
- // TODO
- return null;
- }
-
- public void registerServlet(ServletDTO servletDTO)
- {
- // TODO
- }
-
- public void registerFilter(FilterDTO filterDTO)
- {
- // TODO
- }
-
- public RequestInfoDTO calculateRequestInfoDTO(String path)
- {
- // TODO
- return null;
- }
-
- }
-
}
\ No newline at end of file
Modified: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/FilterMappingTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/FilterMappingTest.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/FilterMappingTest.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/FilterMappingTest.java Thu Jan 29 10:21:03 2015
@@ -18,15 +18,10 @@
*/
package org.apache.felix.http.whiteboard.internal.manager;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
-import org.apache.felix.http.api.FilterInfo;
+import junit.framework.TestCase;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -39,16 +34,24 @@ import org.osgi.service.http.HttpContext
@RunWith(MockitoJUnitRunner.class)
public class FilterMappingTest
{
+
+ private static final String SAMPLE_CONTEXT_ID = "some.context.id";
+
private static final long BUNDLE_ID = 1L;
- private static final String[] FILTER_PATTERNS = new String[] { "/sample/*" };
+
+ private static final String FILTER_PATTERN = "/sample/*";
+
private static final int FILTER_RANKING = 1234;
@Mock
private HttpContext sampleContext;
+
@Mock
private Bundle bundle;
+
@Mock
private ExtenderManagerTest.ExtFilter filter;
+
private ExtenderManagerTest.MockExtHttpService httpService;
@Before
@@ -66,112 +69,109 @@ public class FilterMappingTest
}
@Test
- public void test_with_context() throws Exception
+ public void test_with_context()
{
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.context = sampleContext;
- filterInfo.patterns = FILTER_PATTERNS;
- filterInfo.ranking = FILTER_RANKING;
-
- FilterMapping fm = new FilterMapping(bundle, filter, filterInfo);
-
- assertNull(fm.getContext());
- assertNotNull(fm.getInitParams());
- assertTrue(fm.getInitParams().isEmpty());
- assertFalse(fm.isRegistered());
+ FilterMapping fm = new FilterMapping(bundle, filter, FILTER_PATTERN, FILTER_RANKING);
+ TestCase.assertSame(bundle, fm.getBundle());
+ TestCase.assertSame(filter, fm.getFilter());
+ TestCase.assertEquals(FILTER_PATTERN, fm.getPattern());
+ TestCase.assertEquals(FILTER_RANKING, fm.getRanking());
+
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertNotNull(fm.getInitParams());
+ TestCase.assertTrue(fm.getInitParams().isEmpty());
+ TestCase.assertFalse(fm.isRegistered());
fm.setContext(sampleContext);
- assertSame(sampleContext, fm.getContext());
- assertFalse(fm.isRegistered());
- assertTrue(this.httpService.getFilters().isEmpty());
+ TestCase.assertSame(sampleContext, fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertTrue(this.httpService.getFilters().isEmpty());
fm.register(this.httpService);
- assertSame(sampleContext, fm.getContext());
- assertTrue(fm.isRegistered());
- assertEquals(1, this.httpService.getFilters().size());
- assertSame(filter, this.httpService.getFilters().get(FILTER_PATTERNS[0]));
- assertSame(sampleContext, filter.getHttpContext());
+ TestCase.assertSame(sampleContext, fm.getContext());
+ TestCase.assertTrue(fm.isRegistered());
+ TestCase.assertEquals(1, this.httpService.getFilters().size());
+ TestCase.assertSame(filter, this.httpService.getFilters().get(FILTER_PATTERN));
+ TestCase.assertSame(sampleContext, filter.getHttpContext());
fm.unregister(this.httpService);
- assertSame(sampleContext, fm.getContext());
- assertFalse(fm.isRegistered());
- assertEquals(0, this.httpService.getFilters().size());
+ TestCase.assertSame(sampleContext, fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertEquals(0, this.httpService.getFilters().size());
fm.setContext(null);
- assertNull(fm.getContext());
- assertFalse(fm.isRegistered());
- assertEquals(0, this.httpService.getFilters().size());
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertEquals(0, this.httpService.getFilters().size());
}
@Test
- public void test_context_delayed() throws Exception
+ public void test_context_delayed()
{
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.context = sampleContext;
- filterInfo.patterns = FILTER_PATTERNS;
- filterInfo.ranking = FILTER_RANKING;
-
- FilterMapping fm = new FilterMapping(bundle, filter, filterInfo);
-
- assertNull(fm.getContext());
- assertNotNull(fm.getInitParams());
- assertTrue(fm.getInitParams().isEmpty());
- assertFalse(fm.isRegistered());
+ FilterMapping fm = new FilterMapping(bundle, filter, FILTER_PATTERN, FILTER_RANKING);
+ TestCase.assertSame(bundle, fm.getBundle());
+ TestCase.assertSame(filter, fm.getFilter());
+ TestCase.assertEquals(FILTER_PATTERN, fm.getPattern());
+ TestCase.assertEquals(FILTER_RANKING, fm.getRanking());
+
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertNotNull(fm.getInitParams());
+ TestCase.assertTrue(fm.getInitParams().isEmpty());
+ TestCase.assertFalse(fm.isRegistered());
fm.register(this.httpService);
- assertNull(fm.getContext());
- assertFalse(fm.isRegistered());
- assertTrue(this.httpService.getFilters().isEmpty());
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertTrue(this.httpService.getFilters().isEmpty());
fm.unregister(httpService);
- assertNull(fm.getContext());
- assertFalse(fm.isRegistered());
- assertTrue(this.httpService.getFilters().isEmpty());
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertTrue(this.httpService.getFilters().isEmpty());
fm.setContext(sampleContext);
- assertSame(sampleContext, fm.getContext());
- assertFalse(fm.isRegistered());
- assertTrue(this.httpService.getFilters().isEmpty());
+ TestCase.assertSame(sampleContext, fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertTrue(this.httpService.getFilters().isEmpty());
}
@Test
- public void test_unset_context() throws Exception
+ public void test_unset_context()
{
- FilterInfo filterInfo = new FilterInfo();
- filterInfo.context = sampleContext;
- filterInfo.patterns = FILTER_PATTERNS;
- filterInfo.ranking = FILTER_RANKING;
-
- FilterMapping fm = new FilterMapping(bundle, filter, filterInfo);
-
- assertNull(fm.getContext());
- assertNotNull(fm.getInitParams());
- assertTrue(fm.getInitParams().isEmpty());
- assertFalse(fm.isRegistered());
+ FilterMapping fm = new FilterMapping(bundle, filter, FILTER_PATTERN, FILTER_RANKING);
+ TestCase.assertSame(bundle, fm.getBundle());
+ TestCase.assertSame(filter, fm.getFilter());
+ TestCase.assertEquals(FILTER_PATTERN, fm.getPattern());
+ TestCase.assertEquals(FILTER_RANKING, fm.getRanking());
+
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertNotNull(fm.getInitParams());
+ TestCase.assertTrue(fm.getInitParams().isEmpty());
+ TestCase.assertFalse(fm.isRegistered());
fm.setContext(sampleContext);
- assertSame(sampleContext, fm.getContext());
- assertFalse(fm.isRegistered());
- assertTrue(this.httpService.getFilters().isEmpty());
+ TestCase.assertSame(sampleContext, fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertTrue(this.httpService.getFilters().isEmpty());
fm.register(this.httpService);
- assertSame(sampleContext, fm.getContext());
- assertTrue(fm.isRegistered());
- assertEquals(1, this.httpService.getFilters().size());
- assertSame(filter, this.httpService.getFilters().get(FILTER_PATTERNS[0]));
- assertSame(sampleContext, filter.getHttpContext());
+ TestCase.assertSame(sampleContext, fm.getContext());
+ TestCase.assertTrue(fm.isRegistered());
+ TestCase.assertEquals(1, this.httpService.getFilters().size());
+ TestCase.assertSame(filter, this.httpService.getFilters().get(FILTER_PATTERN));
+ TestCase.assertSame(sampleContext, filter.getHttpContext());
// does not unregister yet
fm.setContext(null);
- assertNull(fm.getContext());
- assertTrue(fm.isRegistered());
- assertEquals(1, this.httpService.getFilters().size());
- assertSame(filter, this.httpService.getFilters().get(FILTER_PATTERNS[0]));
- assertSame(sampleContext, filter.getHttpContext());
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertTrue(fm.isRegistered());
+ TestCase.assertEquals(1, this.httpService.getFilters().size());
+ TestCase.assertSame(filter, this.httpService.getFilters().get(FILTER_PATTERN));
+ TestCase.assertSame(sampleContext, filter.getHttpContext());
fm.unregister(this.httpService);
- assertNull(fm.getContext());
- assertFalse(fm.isRegistered());
- assertEquals(0, this.httpService.getFilters().size());
+ TestCase.assertNull(fm.getContext());
+ TestCase.assertFalse(fm.isRegistered());
+ TestCase.assertEquals(0, this.httpService.getFilters().size());
}
}
Propchange: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/FilterMappingTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain