incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r901359 - in /sling/trunk: bundles/engine/src/main/java/org/apache/sling/engine/impl/ launchpad/builder/src/main/bundles/ launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/ launchpad/testing/src/test/java...
Date Wed, 20 Jan 2010 20:05:59 GMT
Author: justin
Date: Wed Jan 20 20:05:58 2010
New Revision: 901359

URL: http://svn.apache.org/viewvc?rev=901359&view=rev
Log:
SLING-1223 - adding whiteboard support and ensuring that Filters aren't double-registered

Added:
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/HttpServiceExtFilter.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/NoPropertyFilter.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/SlingFilter.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/TestFilter.java
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/FiltersTest.java
Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/launchpad/builder/src/main/bundles/list.xml

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=901359&r1=901358&r2=901359&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Wed Jan 20 20:05:58 2010
@@ -125,6 +125,11 @@
      */
     private static String FILTER_NAME = "Filter";
 
+    /**
+     * The service property used by Felix's HttpService whiteboard implementation.
+     */
+    private static String FELIX_WHITEBOARD_PATTERN_PROPERTY = "pattern";
+
     private SlingServletContext slingServletContext;
 
     private ComponentContext osgiComponentContext;
@@ -682,6 +687,11 @@
     }
 
     private void initFilter(ComponentContext osgiContext, ServiceReference ref) {
+        // Check if filter will be registered by Felix HttpService Whiteboard
+        if (ref.getProperty(FELIX_WHITEBOARD_PATTERN_PROPERTY) != null) {
+            return;
+        }
+
         final Filter filter = (Filter) osgiContext.locateService(FILTER_NAME, ref);
         if ( filter == null ) {
             return;
@@ -741,8 +751,12 @@
         Object scope = ref.getProperty("filter.scope");
         if ("component".equals(scope)) {
             return innerFilterChain;
+        } else if ("request".equals(scope)) {
+            return requestFilterChain;
         }
 
+        log.warn(String.format("A Filter (Service ID %s) has been registered without a filter.scope
property.", ref.getProperty(Constants.SERVICE_ID)));
+
         // global filter by default
         return requestFilterChain;
     }

Modified: sling/trunk/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=901359&r1=901358&r2=901359&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Wed Jan 20 20:05:58 2010
@@ -147,6 +147,13 @@
             <artifactId>groovy-all</artifactId>
             <version>1.7.0</version>
         </bundle>
+
+        <!-- felix httpservice whiteboard -->
+        <bundle>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.http.whiteboard</artifactId>
+            <version>2.0.4</version>
+        </bundle>
     </startLevel>
     <startLevel level="1">
         <bundle>

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/HttpServiceExtFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/HttpServiceExtFilter.java?rev=901359&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/HttpServiceExtFilter.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/HttpServiceExtFilter.java
Wed Jan 20 20:05:58 2010
@@ -0,0 +1,37 @@
+package org.apache.sling.launchpad.testservices.filters;
+
+/*
+ * 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.
+ */
+
+/** Example/test Filter.
+ *
+ * @scr.component immediate="true" metatype="no"
+ * @scr.service interface="javax.servlet.Filter"
+ *
+ * @scr.property name="service.description" value="Test HttpService Filter"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ *
+ * Register this filter with the whiteboard-specific registration property
+ * @scr.property name="pattern" value="/.*"
+ */
+public class HttpServiceExtFilter extends TestFilter {
+
+    @Override
+    protected String getHeaderName() {
+        return "FILTER_COUNTER_HTTPSERVICE";
+    }
+}

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/NoPropertyFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/NoPropertyFilter.java?rev=901359&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/NoPropertyFilter.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/NoPropertyFilter.java
Wed Jan 20 20:05:58 2010
@@ -0,0 +1,36 @@
+package org.apache.sling.launchpad.testservices.filters;
+
+/*
+ * 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.
+ */
+
+/** Example/test Sling Servlet registered with two extensions
+ *
+ * @scr.component immediate="true" metatype="no"
+ * @scr.service interface="javax.servlet.Filter"
+ *
+ * @scr.property name="service.description" value="Test Filter"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ *
+ * Register this filter with the no pattern registration properties
+ */
+public class NoPropertyFilter extends TestFilter {
+
+    @Override
+    protected String getHeaderName() {
+        return "FILTER_COUNTER_NOPROP";
+    }
+}

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/SlingFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/SlingFilter.java?rev=901359&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/SlingFilter.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/SlingFilter.java
Wed Jan 20 20:05:58 2010
@@ -0,0 +1,38 @@
+package org.apache.sling.launchpad.testservices.filters;
+
+/*
+ * 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.
+ */
+
+/** Example/test Sling Servlet registered with two extensions
+ *
+ * @scr.component immediate="true" metatype="no"
+ * @scr.service interface="javax.servlet.Filter"
+ *
+ * @scr.property name="service.description" value="Test Filter"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ *
+ * Register this filter with the Sling-specific registration property
+ * @scr.property name="filter.scope" value="request"
+ */
+public class SlingFilter extends TestFilter {
+
+    @Override
+    protected String getHeaderName() {
+        return "FILTER_COUNTER_SLING";
+    }
+
+}

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/TestFilter.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/TestFilter.java?rev=901359&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/TestFilter.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/filters/TestFilter.java
Wed Jan 20 20:05:58 2010
@@ -0,0 +1,57 @@
+package org.apache.sling.launchpad.testservices.filters;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/*
+ * 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.
+ */
+/**
+ * Example/test Filter.
+ */
+abstract class TestFilter implements Filter {
+    
+    private FilterConfig filterConfig;
+    
+    public void init(FilterConfig filterConfig) throws ServletException {
+        this.filterConfig = filterConfig;
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
+        String header = getHeaderName();
+        AtomicInteger current = (AtomicInteger) ((HttpServletRequest)request).getAttribute(header);
+        if (current == null) {
+            current = new AtomicInteger(0);
+            ((HttpServletRequest)request).setAttribute(header, current);
+        }
+
+        ((HttpServletResponse) response).setHeader(header, String.valueOf(current.incrementAndGet()));
+        chain.doFilter(request, response);
+    }
+
+    public void destroy() {
+    }
+
+    protected abstract String getHeaderName();
+}

Added: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/FiltersTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/FiltersTest.java?rev=901359&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/FiltersTest.java
(added)
+++ sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/FiltersTest.java
Wed Jan 20 20:05:58 2010
@@ -0,0 +1,31 @@
+package org.apache.sling.launchpad.webapp.integrationtest;
+
+/* 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.
+ */
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+public class FiltersTest extends HttpTestBase {
+
+    public void testCounters() throws IOException {
+        HttpMethod get = assertHttpStatus(HTTP_BASE_URL + "/index.html", HttpServletResponse.SC_OK);
+        assertEquals("Filter-set header has incorrect value.", "1", get.getResponseHeader("FILTER_COUNTER_HTTPSERVICE").getValue());
+        assertEquals("Filter-set header has incorrect value.", "1", get.getResponseHeader("FILTER_COUNTER_SLING").getValue());
+        assertEquals("Filter-set header has incorrect value.", "1", get.getResponseHeader("FILTER_COUNTER_NOPROP").getValue());
+    }
+}



Mime
View raw message