felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1720513 - in /felix/trunk/http/samples/filter: DEPENDENCIES LICENSE NOTICE pom.xml src/main/java/org/apache/felix/http/samples/filter/Activator.java src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
Date Thu, 17 Dec 2015 10:47:04 GMT
Author: cziegeler
Date: Thu Dec 17 10:47:04 2015
New Revision: 1720513

URL: http://svn.apache.org/viewvc?rev=1720513&view=rev
Log:
Update filter example to http whiteboard

Added:
    felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
  (with props)
Removed:
    felix/trunk/http/samples/filter/DEPENDENCIES
    felix/trunk/http/samples/filter/LICENSE
    felix/trunk/http/samples/filter/NOTICE
Modified:
    felix/trunk/http/samples/filter/pom.xml
    felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/Activator.java

Modified: felix/trunk/http/samples/filter/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/http/samples/filter/pom.xml?rev=1720513&r1=1720512&r2=1720513&view=diff
==============================================================================
--- felix/trunk/http/samples/filter/pom.xml (original)
+++ felix/trunk/http/samples/filter/pom.xml Thu Dec 17 10:47:04 2015
@@ -27,9 +27,10 @@
     </parent>
 
     <name>Apache Felix Http Samples - Filter</name>
+    <description>This example shows how to register servlets and filters using the
Http Whiteboard Service.</description>
     <artifactId>org.apache.felix.http.samples.filter</artifactId>
     <version>2.3.3-SNAPSHOT</version>
-    <packaging>jar</packaging>
+    <packaging>bundle</packaging>
 
     <scm>
         <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/http/samples/filter</connection>
@@ -42,32 +43,25 @@
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
+                <version>3.0.1</version>
+                <extensions>true</extensions>
                 <configuration>
                     <instructions>
                         <Bundle-Activator>
                             org.apache.felix.http.samples.filter.Activator
                         </Bundle-Activator>
                         <Private-Package>
-                            org.apache.felix.http.samples.filter.*
+                            org.apache.felix.http.samples.filter
                         </Private-Package>
-                        <Import-Package>
-                            *;resolution:=optional
-                        </Import-Package>
+                        <Export-Package>
+                           !org.apache.felix.http.samples.filter
+                        </Export-Package>
+                        <Require-Capability>
+                            osgi.contract; filter:="(&amp;(osgi.contract=JavaServlet)(version>=3.1))"
+                        </Require-Capability>
                     </instructions>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-source-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>attach-sources</id>
-                        <goals>
-                            <goal>jar</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>            
         </plugins>
     </build>
 
@@ -84,11 +78,5 @@
             <groupId>org.osgi</groupId>
             <artifactId>osgi.cmpn</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.http.api</artifactId>
-            <version>3.0.0</version>
-        </dependency>
     </dependencies>
-
 </project>

Modified: felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/Activator.java?rev=1720513&r1=1720512&r2=1720513&view=diff
==============================================================================
--- felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/Activator.java
(original)
+++ felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/Activator.java
Thu Dec 17 10:47:04 2015
@@ -16,68 +16,69 @@
  */
 package org.apache.felix.http.samples.filter;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.apache.felix.http.api.ExtHttpService;
+import org.osgi.service.http.context.ServletContextHelper;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 public final class Activator
     implements BundleActivator
 {
-    private ServiceTracker tracker;
-    private TestServlet servlet1 = new TestServlet("servlet1");
-    private TestServlet servlet2 = new TestServlet("servlet2");
-    private TestFilter filter1 = new TestFilter("filter1");
-    private TestFilter filter2 = new TestFilter("filter2");
 
+    @Override
     public void start(BundleContext context)
         throws Exception
     {
-        this.tracker = new ServiceTracker(context, ExtHttpService.class.getName(), null)
-        {
-            @Override
-            public Object addingService(ServiceReference ref)
-            {
-                Object service =  super.addingService(ref);
-                serviceAdded((ExtHttpService)service);
-                return service;
-            }
-
-            @Override
-            public void removedService(ServiceReference ref, Object service)
-            {
-                serviceRemoved((ExtHttpService)service);
-                super.removedService(ref, service);
-            }
-        };
+        // create a servlet context
+        final TestServletContext servletContext = new TestServletContext(context.getBundle());
 
-        this.tracker.open();
+        // register the servlet context with name "filtersample" at "/filtersample"
+        final Dictionary<String, Object> servletContextProps = new Hashtable<String,
Object>();
+        servletContextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, "filtersample");
+        servletContextProps.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/filtersample");
+        context.registerService(ServletContextHelper.class, servletContext, servletContextProps);
+
+        // create and register servlets
+        final TestServlet servlet1 = new TestServlet("servlet1");
+        final Dictionary<String, Object> servlet1Props = new Hashtable<String, Object>();
+        servlet1Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/");
+        servlet1Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
+                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=filtersample)");
+        context.registerService(Servlet.class, servlet1, servlet1Props);
+
+        final TestServlet servlet2 = new TestServlet("servlet2");
+        final Dictionary<String, Object> servlet2Props = new Hashtable<String, Object>();
+        servlet2Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/other/*");
+        servlet2Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
+                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=filtersample)");
+        context.registerService(Servlet.class, servlet2, servlet2Props);
+
+        // create and register filters
+        final TestFilter filter1 = new TestFilter("filter1");
+        final Dictionary<String, Object> filter1Props = new Hashtable<String, Object>();
+        filter1Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/");
+        filter1Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
+                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=filtersample)");
+        context.registerService(Filter.class, filter1, filter1Props);
+
+        final TestFilter filter2 = new TestFilter("filter2");
+        final Dictionary<String, Object> filter2Props = new Hashtable<String, Object>();
+        filter2Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN, "/other/*");
+        filter2Props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
+                "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=filtersample)");
+        context.registerService(Filter.class, filter2, filter2Props);
     }
 
+    @Override
     public void stop(BundleContext context)
         throws Exception
     {
-        this.tracker.close();
-    }
-
-    private void serviceAdded(ExtHttpService service)
-    {
-        try {
-            service.registerServlet("/", this.servlet1, null, null);
-            service.registerServlet("/other", this.servlet2, null, null);
-            service.registerFilter(this.filter1, ".*", null, 0, null);
-            service.registerFilter(this.filter2, "/other/.*", null, 100, null);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    private void serviceRemoved(ExtHttpService service)
-    {
-        service.unregisterServlet(this.servlet1);
-        service.unregisterServlet(this.servlet2);
-        service.unregisterFilter(this.filter1);
-        service.unregisterFilter(this.filter2);
+        // nothing to do, services are unregistered automatically
     }
 }

Added: felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java?rev=1720513&view=auto
==============================================================================
--- felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
(added)
+++ felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
Thu Dec 17 10:47:04 2015
@@ -0,0 +1,33 @@
+/*
+ * 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.samples.filter;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.context.ServletContextHelper;
+
+/**
+ * Simple sample servlet context
+ */
+public class TestServletContext
+    extends ServletContextHelper
+{
+
+    public TestServletContext(final Bundle bundle)
+    {
+        super(bundle);
+    }
+}

Propchange: felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServletContext.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url



Mime
View raw message