Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Kaegi2007-03-17 06:31:39 +0000
committerSimon Kaegi2007-03-17 06:31:39 +0000
commit567c94b7801450cf29627926d85979f950d5a80e (patch)
tree5c17becf2f33901d1e3487502f73dac11f1c368d /bundles/org.eclipse.equinox.http.registry
parent2aa48b810da17c2635e988d8f5f410b0e7047506 (diff)
downloadrt.equinox.bundles-567c94b7801450cf29627926d85979f950d5a80e.tar.gz
rt.equinox.bundles-567c94b7801450cf29627926d85979f950d5a80e.tar.xz
rt.equinox.bundles-567c94b7801450cf29627926d85979f950d5a80e.zip
bug 158168 - [server] Design a filtering mechanism to decide against which service instance a servlet is registered
Diffstat (limited to 'bundles/org.eclipse.equinox.http.registry')
-rw-r--r--bundles/org.eclipse.equinox.http.registry/schema/resources.exsd28
-rw-r--r--bundles/org.eclipse.equinox.http.registry/schema/servlets.exsd23
-rw-r--r--bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpContextManager.java1
-rw-r--r--bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java4
-rw-r--r--bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java48
-rw-r--r--bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java47
6 files changed, 147 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.http.registry/schema/resources.exsd b/bundles/org.eclipse.equinox.http.registry/schema/resources.exsd
index c2fff4f78..2e981a830 100644
--- a/bundles/org.eclipse.equinox.http.registry/schema/resources.exsd
+++ b/bundles/org.eclipse.equinox.http.registry/schema/resources.exsd
@@ -13,6 +13,7 @@
<element name="extension">
<complexType>
<sequence>
+ <element ref="serviceSelector"/>
<element ref="resource" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
@@ -73,6 +74,33 @@
</complexType>
</element>
+ <element name="serviceSelector">
+ <annotation>
+ <documentation>
+ The serviceSelector allow filtering of the HttpService instances with which to register resources
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="filter" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.osgi.framework.Filter"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
diff --git a/bundles/org.eclipse.equinox.http.registry/schema/servlets.exsd b/bundles/org.eclipse.equinox.http.registry/schema/servlets.exsd
index dcf01f236..90cc9d7ac 100644
--- a/bundles/org.eclipse.equinox.http.registry/schema/servlets.exsd
+++ b/bundles/org.eclipse.equinox.http.registry/schema/servlets.exsd
@@ -50,6 +50,7 @@
</annotation>
<complexType>
<sequence>
+ <element ref="serviceSelector"/>
<element ref="init-param" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute name="class" type="string" use="required">
@@ -113,6 +114,28 @@
</complexType>
</element>
+ <element name="serviceSelector">
+ <complexType>
+ <attribute name="filter" type="string">
+ <annotation>
+ <documentation>
+ The serviceSelector allow filtering of the HttpService instances with which to register servlets.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.osgi.framework.Filter"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpContextManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpContextManager.java
index 4ee9587f6..135627abe 100644
--- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpContextManager.java
+++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpContextManager.java
@@ -75,6 +75,7 @@ public class HttpContextManager implements Listener {
} catch (CoreException e) {
// log it.
e.printStackTrace();
+ continue;
}
} else {
Bundle contributingBundle = httpRegistryManager.getBundle(extension.getContributor());
diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java
index b1479a7e8..543959538 100644
--- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java
+++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/HttpRegistryManager.java
@@ -76,8 +76,8 @@ public class HttpRegistryManager {
this.packageAdmin = packageAdmin;
httpContextManager = new HttpContextManager(this, registry);
- servletManager = new ServletManager(this, registry);
- resourceManager = new ResourceManager(this, registry);
+ servletManager = new ServletManager(this, reference, registry);
+ resourceManager = new ResourceManager(this, reference, registry);
}
public void start() {
diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java
index beadad68d..64160c578 100644
--- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java
+++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ResourceManager.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.http.registry.internal;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.*;
+import org.osgi.framework.*;
public class ResourceManager implements ExtensionPointTracker.Listener {
@@ -26,6 +27,12 @@ public class ResourceManager implements ExtensionPointTracker.Listener {
private static final String RESOURCE = "resource"; //$NON-NLS-1$
private static final String HTTPCONTEXT_ID = "httpcontextId"; //$NON-NLS-1$
+
+ private static final String SERVICESELECTOR = "serviceSelector"; //$NON-NLS-1$
+
+ private static final String CLASS = "class"; //$NON-NLS-1$
+
+ private static final String FILTER = "filter"; //$NON-NLS-1$
private ExtensionPointTracker tracker;
@@ -33,8 +40,11 @@ public class ResourceManager implements ExtensionPointTracker.Listener {
private HttpRegistryManager httpRegistryManager;
- public ResourceManager(HttpRegistryManager httpRegistryManager, IExtensionRegistry registry) {
+ private ServiceReference reference;
+
+ public ResourceManager(HttpRegistryManager httpRegistryManager, ServiceReference reference, IExtensionRegistry registry) {
this.httpRegistryManager = httpRegistryManager;
+ this.reference = reference;
tracker = new ExtensionPointTracker(registry, RESOURCES_EXTENSION_POINT, this);
}
@@ -49,6 +59,42 @@ public class ResourceManager implements ExtensionPointTracker.Listener {
public void added(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement serviceSelectorElement = elements[i];
+ if (!SERVICESELECTOR.equals(serviceSelectorElement.getName()))
+ continue;
+
+ org.osgi.framework.Filter serviceSelector = null;
+ String clazz = serviceSelectorElement.getAttribute(CLASS);
+ if (clazz != null) {
+ try {
+ serviceSelector = (org.osgi.framework.Filter) serviceSelectorElement.createExecutableExtension(CLASS);
+ } catch (CoreException e) {
+ // log it.
+ e.printStackTrace();
+ return;
+ }
+ } else {
+ String filter = serviceSelectorElement.getAttribute(FILTER);
+ if (filter == null)
+ return;
+
+ try {
+ serviceSelector = FrameworkUtil.createFilter(filter);
+ } catch (InvalidSyntaxException e) {
+ // log it.
+ e.printStackTrace();
+ return;
+ }
+ }
+
+ if (! serviceSelector.match(reference))
+ return;
+
+ break;
+ }
+
+
+ for (int i = 0; i < elements.length; i++) {
IConfigurationElement resourceElement = elements[i];
if (!RESOURCE.equals(resourceElement.getName()))
continue;
diff --git a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java
index 591aaec89..3d0213134 100644
--- a/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java
+++ b/bundles/org.eclipse.equinox.http.registry/src/org/eclipse/equinox/http/registry/internal/ServletManager.java
@@ -13,6 +13,7 @@ import java.io.IOException;
import java.util.*;
import javax.servlet.*;
import org.eclipse.core.runtime.*;
+import org.osgi.framework.*;
public class ServletManager implements ExtensionPointTracker.Listener {
@@ -34,14 +35,23 @@ public class ServletManager implements ExtensionPointTracker.Listener {
private static final String HTTPCONTEXT_ID = "httpcontextId"; //$NON-NLS-1$
+ private static final String SERVICESELECTOR = "serviceSelector"; //$NON-NLS-1$
+
+ private static final String CLASS = "class"; //$NON-NLS-1$
+
+ private static final String FILTER = "filter"; //$NON-NLS-1$
+
private ExtensionPointTracker tracker;
private HttpRegistryManager httpRegistryManager;
private List registered = new ArrayList();
- public ServletManager(HttpRegistryManager httpRegistryManager, IExtensionRegistry registry) {
+ private ServiceReference reference;
+
+ public ServletManager(HttpRegistryManager httpRegistryManager, ServiceReference reference, IExtensionRegistry registry) {
this.httpRegistryManager = httpRegistryManager;
+ this.reference = reference;
tracker = new ExtensionPointTracker(registry, SERVLETS_EXTENSION_POINT, this);
}
@@ -56,6 +66,41 @@ public class ServletManager implements ExtensionPointTracker.Listener {
public void added(IExtension extension) {
IConfigurationElement[] elements = extension.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement serviceSelectorElement = elements[i];
+ if (!SERVICESELECTOR.equals(serviceSelectorElement.getName()))
+ continue;
+
+ org.osgi.framework.Filter serviceSelector = null;
+ String clazz = serviceSelectorElement.getAttribute(CLASS);
+ if (clazz != null) {
+ try {
+ serviceSelector = (org.osgi.framework.Filter) serviceSelectorElement.createExecutableExtension(CLASS);
+ } catch (CoreException e) {
+ // log it.
+ e.printStackTrace();
+ return;
+ }
+ } else {
+ String filter = serviceSelectorElement.getAttribute(FILTER);
+ if (filter == null)
+ return;
+
+ try {
+ serviceSelector = FrameworkUtil.createFilter(filter);
+ } catch (InvalidSyntaxException e) {
+ // log it.
+ e.printStackTrace();
+ return;
+ }
+ }
+
+ if (! serviceSelector.match(reference))
+ return;
+
+ break;
+ }
+
+ for (int i = 0; i < elements.length; i++) {
IConfigurationElement servletElement = elements[i];
if (!SERVLET.equals(servletElement.getName()))
continue;

Back to the top