You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by sr...@apache.org on 2009/09/14 11:59:16 UTC
svn commit: r814549 [4/4] - in /felix/trunk/http: ./ api/ api/src/
api/src/main/ api/src/main/java/ api/src/main/java/org/
api/src/main/java/org/apache/ api/src/main/java/org/apache/felix/
api/src/main/java/org/apache/felix/http/ api/src/main/java/org/...
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,45 @@
+/*
+ * 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.whiteboard.internal.manager;
+
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.log.LogService;
+import org.osgi.framework.ServiceReference;
+import javax.servlet.Servlet;
+import javax.servlet.Filter;
+
+public interface ExtenderManager
+{
+ public void add(HttpContext service, ServiceReference ref);
+
+ public void remove(HttpContext service);
+
+ public void add(Filter service, ServiceReference ref);
+
+ public void remove(Filter service);
+
+ public void add(Servlet service, ServiceReference ref);
+
+ public void remove(Servlet service);
+
+ public void setHttpService(HttpService service);
+
+ public void unsetHttpService();
+
+ public void unregisterAll();
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,191 @@
+/*
+ * 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.whiteboard.internal.manager;
+
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.apache.felix.http.api.ExtHttpService;
+import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+
+import javax.servlet.Servlet;
+import javax.servlet.Filter;
+import java.util.HashMap;
+
+public final class ExtenderManagerImpl
+ implements ExtenderManager
+{
+ private final static String CONTEXT_ID_KEY = "contextId";
+ private final static String PATTERN_KEY = "pattern";
+ private final static String ALIAS_KEY = "alias";
+ private final static String INIT_KEY_PREFIX = "init.";
+
+ private HttpService httpService;
+ private final HashMap<Object, AbstractMapping> mapping;
+ private final HttpContextManager contextManager;
+
+ public ExtenderManagerImpl()
+ {
+ this.mapping = new HashMap<Object, AbstractMapping>();
+ this.contextManager = new HttpContextManager();
+ }
+
+ private String getStringProperty(ServiceReference ref, String key)
+ {
+ Object value = ref.getProperty(key);
+ return (value instanceof String) ? (String)value : null;
+ }
+
+ private int getIntProperty(ServiceReference ref, String key, int defValue)
+ {
+ Object value = ref.getProperty(key);
+ if (value == null) {
+ return defValue;
+ }
+
+ try {
+ return Integer.parseInt(value.toString());
+ } catch (Exception e) {
+ return defValue;
+ }
+ }
+
+ private void addInitParams(ServiceReference ref, AbstractMapping mapping)
+ {
+ for (String key : ref.getPropertyKeys()) {
+ if (key.startsWith(INIT_KEY_PREFIX)) {
+ String paramKey = key.substring(INIT_KEY_PREFIX.length());
+ String paramValue = getStringProperty(ref, key);
+
+ if (paramValue != null) {
+ mapping.getInitParams().put(paramKey, paramValue);
+ }
+ }
+ }
+ }
+
+ public void add(HttpContext service, ServiceReference ref)
+ {
+ Bundle bundle = ref.getBundle();
+ String contextId = getStringProperty(ref, CONTEXT_ID_KEY);
+ if (contextId != null) {
+ this.contextManager.addHttpContext(bundle, contextId, service);
+ }
+ }
+
+ public void remove(HttpContext service)
+ {
+ this.contextManager.removeHttpContext(service);
+ }
+
+ private HttpContext getHttpContext(ServiceReference ref)
+ {
+ Bundle bundle = ref.getBundle();
+ String contextId = getStringProperty(ref, CONTEXT_ID_KEY);
+ return contextId != null ? this.contextManager.getHttpContext(bundle, contextId) : null;
+ }
+
+ public void add(Filter service, ServiceReference ref)
+ {
+ int ranking = getIntProperty(ref, Constants.SERVICE_RANKING, 0);
+ String pattern = getStringProperty(ref, PATTERN_KEY);
+
+ if (pattern == null) {
+ return;
+ }
+
+ FilterMapping mapping = new FilterMapping(getHttpContext(ref), service, pattern, ranking);
+ addInitParams(ref, mapping);
+ addMapping(service, mapping);
+ }
+
+ public void remove(Filter service)
+ {
+ removeMapping(service);
+ }
+
+ public void add(Servlet service, ServiceReference ref)
+ {
+ String alias = getStringProperty(ref, ALIAS_KEY);
+ if (alias == null) {
+ return;
+ }
+
+ ServletMapping mapping = new ServletMapping(getHttpContext(ref), service, alias);
+ addInitParams(ref, mapping);
+ addMapping(service, mapping);
+ }
+
+ public void remove(Servlet service)
+ {
+ removeMapping(service);
+ }
+
+ public synchronized void setHttpService(HttpService service)
+ {
+ this.httpService = service;
+ if (this.httpService instanceof ExtHttpService) {
+ SystemLogger.get().info("Detected extended HttpService. Filters enabled.");
+ } else {
+ SystemLogger.get().info("Standard HttpService. Filters disabled.");
+ }
+
+ registerAll();
+ }
+
+ public synchronized void unsetHttpService()
+ {
+ unregisterAll();
+ this.httpService = null;
+ }
+
+ public synchronized void unregisterAll()
+ {
+ if (this.httpService != null) {
+ for (AbstractMapping mapping : this.mapping.values()) {
+ mapping.unregister(this.httpService);
+ }
+ }
+ }
+
+ private synchronized void registerAll()
+ {
+ if (this.httpService != null) {
+ for (AbstractMapping mapping : this.mapping.values()) {
+ mapping.register(this.httpService);
+ }
+ }
+ }
+
+ private synchronized void addMapping(Object key, AbstractMapping mapping)
+ {
+ this.mapping.put(key, mapping);
+ if (this.httpService != null) {
+ mapping.register(this.httpService);
+ }
+ }
+
+ private synchronized void removeMapping(Object key)
+ {
+ AbstractMapping mapping = this.mapping.remove(key);
+ if ((mapping != null) && (this.httpService != null)) {
+ mapping.unregister(this.httpService);
+ }
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.whiteboard.internal.manager;
+
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.HttpContext;
+import org.apache.felix.http.api.ExtHttpService;
+import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import javax.servlet.Filter;
+
+public final class FilterMapping
+ extends AbstractMapping
+{
+ private final Filter filter;
+ private final int ranking;
+ private final String pattern;
+
+ public FilterMapping(HttpContext context, Filter filter, String pattern, int ranking)
+ {
+ super(context);
+ this.filter = filter;
+ this.pattern = pattern;
+ this.ranking = ranking;
+ }
+
+ public void register(HttpService httpService)
+ {
+ if (httpService instanceof ExtHttpService) {
+ register((ExtHttpService)httpService);
+ }
+ }
+
+ private void register(ExtHttpService httpService)
+ {
+ try {
+ httpService.registerFilter(this.filter, this.pattern, getInitParams(), ranking, getContext());
+ } catch (Exception e) {
+ SystemLogger.get().error("Failed to register filter", e);
+ }
+ }
+
+ public void unregister(HttpService httpService)
+ {
+ if (httpService instanceof ExtHttpService) {
+ unregister((ExtHttpService)httpService);
+ }
+ }
+
+ private void unregister(ExtHttpService httpService)
+ {
+ httpService.unregisterFilter(this.filter);
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.whiteboard.internal.manager;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import java.util.HashMap;
+
+public final class HttpContextManager
+{
+ private final HashMap<String, HttpContext> idMap;
+ private final HashMap<HttpContext, String> contextMap;
+
+ public HttpContextManager()
+ {
+ this.idMap = new HashMap<String, HttpContext>();
+ this.contextMap = new HashMap<HttpContext, String>();
+ }
+
+ private String createId(Bundle bundle, String contextId)
+ {
+ return bundle.getBundleId() + "-" + contextId;
+ }
+
+ public synchronized HttpContext getHttpContext(Bundle bundle, String contextId)
+ {
+ String id = createId(bundle, contextId);
+ HttpContext context = this.idMap.get(id);
+
+ if (context == null) {
+ context = new DefaultHttpContext(bundle);
+ this.idMap.put(id, context);
+ this.contextMap.put(context, id);
+ SystemLogger.get().debug("Added context with id [" + contextId + "]");
+ } else {
+ SystemLogger.get().debug("Reusing context with id [" + contextId + "]");
+ }
+
+ return context;
+ }
+
+ public synchronized void removeHttpContext(HttpContext context)
+ {
+ String id = this.contextMap.remove(context);
+ if (id != null) {
+ this.idMap.remove(id);
+ }
+ }
+
+ public synchronized void addHttpContext(Bundle bundle, String contextId, HttpContext context)
+ {
+ String id = createId(bundle, contextId);
+ this.idMap.put(id, context);
+ this.contextMap.put(context, id);
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.whiteboard.internal.manager;
+
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.HttpContext;
+import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import javax.servlet.Servlet;
+
+public final class ServletMapping
+ extends AbstractMapping
+{
+ private final Servlet servlet;
+ private final String alias;
+
+ public ServletMapping(HttpContext context, Servlet servlet, String alias)
+ {
+ super(context);
+ this.servlet = servlet;
+ this.alias = alias;
+ }
+
+ public void register(HttpService httpService)
+ {
+ try {
+ httpService.registerServlet(this.alias, this.servlet, getInitParams(), getContext());
+ } catch (Exception e) {
+ SystemLogger.get().error("Failed to register servlet", e);
+ }
+ }
+
+ public void unregister(HttpService httpService)
+ {
+ httpService.unregister(this.alias);
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.whiteboard.internal.tracker;
+
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public abstract class AbstractTracker<T>
+ extends ServiceTracker
+{
+ public AbstractTracker(BundleContext context, Class clz)
+ {
+ super(context, clz.getName(), null);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final Object addingService(ServiceReference ref)
+ {
+ T service = (T)super.addingService(ref);
+ added(service, ref);
+ return service;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final void modifiedService(ServiceReference ref, Object service)
+ {
+ super.modifiedService(ref, service);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final void removedService(ServiceReference ref, Object service)
+ {
+ super.removedService(ref, service);
+ removed((T)service);
+ }
+
+ protected abstract void modified(T service, ServiceReference ref);
+
+ protected abstract void added(T service, ServiceReference ref);
+
+ protected abstract void removed(T service);
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.whiteboard.internal.tracker;
+
+import javax.servlet.Filter;
+import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public final class FilterTracker
+ extends AbstractTracker<Filter>
+{
+ private final ExtenderManager manager;
+
+ public FilterTracker(BundleContext context, ExtenderManager manager)
+ {
+ super(context, Filter.class);
+ this.manager = manager;
+ }
+
+ protected void added(Filter service, ServiceReference ref)
+ {
+ this.manager.add(service, ref);
+ }
+
+ protected void modified(Filter service, ServiceReference ref)
+ {
+ removed(service);
+ added(service, ref);
+ }
+
+ protected void removed(Filter service)
+ {
+ this.manager.remove(service);
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.whiteboard.internal.tracker;
+
+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>
+{
+ private final ExtenderManager manager;
+
+ public HttpContextTracker(BundleContext context, ExtenderManager manager)
+ {
+ super(context, HttpContext.class);
+ this.manager = manager;
+ }
+
+ protected void added(HttpContext service, ServiceReference ref)
+ {
+ this.manager.add(service, ref);
+ }
+
+ protected void modified(HttpContext service, ServiceReference ref)
+ {
+ removed(service);
+ added(service, ref);
+ }
+
+ protected void removed(HttpContext service)
+ {
+ this.manager.remove(service);
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,49 @@
+/*
+ * 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.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.HttpService;
+
+public final class HttpServiceTracker
+ extends AbstractTracker<HttpService>
+{
+ private final ExtenderManager manager;
+
+ public HttpServiceTracker(BundleContext context, ExtenderManager manager)
+ {
+ super(context, HttpService.class);
+ this.manager = manager;
+ }
+
+ protected void added(HttpService service, ServiceReference ref)
+ {
+ this.manager.setHttpService(service);
+ }
+
+ protected void modified(HttpService service, ServiceReference ref)
+ {
+ // Do nothing
+ }
+
+ protected void removed(HttpService service)
+ {
+ this.manager.unsetHttpService();
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,50 @@
+/*
+ * 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.whiteboard.internal.tracker;
+
+import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import javax.servlet.Servlet;
+
+public final class ServletTracker
+ extends AbstractTracker<Servlet>
+{
+ private final ExtenderManager manager;
+
+ public ServletTracker(BundleContext context, ExtenderManager manager)
+ {
+ super(context, Servlet.class);
+ this.manager = manager;
+ }
+
+ protected void added(Servlet service, ServiceReference ref)
+ {
+ this.manager.add(service, ref);
+ }
+
+ protected void modified(Servlet service, ServiceReference ref)
+ {
+ removed(service);
+ added(service, ref);
+ }
+
+ protected void removed(Servlet service)
+ {
+ this.manager.remove(service);
+ }
+}
Added: felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java (added)
+++ felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,82 @@
+/*
+ * 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.whiteboard.internal.util;
+
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+public final class SystemLogger
+{
+ private final static SystemLogger INSTANCE =
+ new SystemLogger();
+
+ private ServiceTracker tracker;
+
+ private SystemLogger()
+ {
+ }
+
+ public void open(BundleContext context)
+ {
+ this.tracker = new ServiceTracker(context, LogService.class.getName(), null);
+ this.tracker.open();
+ }
+
+ public void close()
+ {
+ this.tracker.close();
+ }
+
+ public void debug(String message)
+ {
+ log(LogService.LOG_DEBUG, message, null);
+ }
+
+ public void info(String message)
+ {
+ log(LogService.LOG_INFO, message, null);
+ }
+
+ public void warning(String message, Throwable cause)
+ {
+ log(LogService.LOG_WARNING, message, cause);
+ }
+
+ public void error(String message, Throwable cause)
+ {
+ log(LogService.LOG_ERROR, message, cause);
+ }
+
+ private void log(int level, String message, Throwable cause)
+ {
+ LogService log = (LogService)this.tracker.getService();
+ if (log != null) {
+ log.log(level, message, cause);
+ } else {
+ System.out.println(message);
+ if (cause != null) {
+ cause.printStackTrace(System.out);
+ }
+ }
+ }
+
+ public static SystemLogger get()
+ {
+ return INSTANCE;
+ }
+}
\ No newline at end of file