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 [1/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/...
Author: srs
Date: Mon Sep 14 09:59:12 2009
New Revision: 814549
URL: http://svn.apache.org/viewvc?rev=814549&view=rev
Log:
FELIX-1456: Added improved httpservice implementation
Added:
felix/trunk/http/
felix/trunk/http/LICENSE
felix/trunk/http/README
felix/trunk/http/api/
felix/trunk/http/api/pom.xml
felix/trunk/http/api/src/
felix/trunk/http/api/src/main/
felix/trunk/http/api/src/main/java/
felix/trunk/http/api/src/main/java/org/
felix/trunk/http/api/src/main/java/org/apache/
felix/trunk/http/api/src/main/java/org/apache/felix/
felix/trunk/http/api/src/main/java/org/apache/felix/http/
felix/trunk/http/api/src/main/java/org/apache/felix/http/api/
felix/trunk/http/api/src/main/java/org/apache/felix/http/api/ExtHttpService.java
felix/trunk/http/base/
felix/trunk/http/base/pom.xml
felix/trunk/http/base/src/
felix/trunk/http/base/src/main/
felix/trunk/http/base/src/main/java/
felix/trunk/http/base/src/main/java/org/
felix/trunk/http/base/src/main/java/org/apache/
felix/trunk/http/base/src/main/java/org/apache/felix/
felix/trunk/http/base/src/main/java/org/apache/felix/http/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/FilterPipeline.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/HttpFilterChain.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationFilterChain.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/NotFoundFilterChain.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletPipeline.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/DefaultHttpContext.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/ResourceServlet.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/MimeTypes.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/util/SystemLogger.java
felix/trunk/http/base/src/test/
felix/trunk/http/base/src/test/java/
felix/trunk/http/base/src/test/java/org/
felix/trunk/http/base/src/test/java/org/apache/
felix/trunk/http/base/src/test/java/org/apache/felix/
felix/trunk/http/base/src/test/java/org/apache/felix/http/
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextImplTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/context/ServletContextManagerTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/AbstractHandlerTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterConfigImplTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/FilterHandlerTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletConfigImplTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerTest.java
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/
felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/util/MimeTypesTest.java
felix/trunk/http/base/src/test/resources/
felix/trunk/http/base/src/test/resources/org/
felix/trunk/http/base/src/test/resources/org/apache/
felix/trunk/http/base/src/test/resources/org/apache/felix/
felix/trunk/http/base/src/test/resources/org/apache/felix/http/
felix/trunk/http/base/src/test/resources/org/apache/felix/http/base/
felix/trunk/http/base/src/test/resources/org/apache/felix/http/base/internal/
felix/trunk/http/base/src/test/resources/org/apache/felix/http/base/internal/context/
felix/trunk/http/base/src/test/resources/org/apache/felix/http/base/internal/context/resource.txt
felix/trunk/http/bridge/
felix/trunk/http/bridge/pom.xml
felix/trunk/http/bridge/src/
felix/trunk/http/bridge/src/main/
felix/trunk/http/bridge/src/main/java/
felix/trunk/http/bridge/src/main/java/org/
felix/trunk/http/bridge/src/main/java/org/apache/
felix/trunk/http/bridge/src/main/java/org/apache/felix/
felix/trunk/http/bridge/src/main/java/org/apache/felix/http/
felix/trunk/http/bridge/src/main/java/org/apache/felix/http/bridge/
felix/trunk/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/
felix/trunk/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
felix/trunk/http/bundle/
felix/trunk/http/bundle/pom.xml
felix/trunk/http/bundle/src/
felix/trunk/http/bundle/src/main/
felix/trunk/http/bundle/src/main/java/
felix/trunk/http/bundle/src/main/java/org/
felix/trunk/http/bundle/src/main/java/org/apache/
felix/trunk/http/bundle/src/main/java/org/apache/felix/
felix/trunk/http/bundle/src/main/java/org/apache/felix/http/
felix/trunk/http/bundle/src/main/java/org/apache/felix/http/bundle/
felix/trunk/http/bundle/src/main/java/org/apache/felix/http/bundle/internal/
felix/trunk/http/bundle/src/main/java/org/apache/felix/http/bundle/internal/CombinedActivator.java
felix/trunk/http/jetty/
felix/trunk/http/jetty/pom.xml
felix/trunk/http/jetty/src/
felix/trunk/http/jetty/src/main/
felix/trunk/http/jetty/src/main/java/
felix/trunk/http/jetty/src/main/java/org/
felix/trunk/http/jetty/src/main/java/org/apache/
felix/trunk/http/jetty/src/main/java/org/apache/felix/
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyConfig.java
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyLogger.java
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
felix/trunk/http/pom.xml
felix/trunk/http/proxy/
felix/trunk/http/proxy/pom.xml
felix/trunk/http/proxy/src/
felix/trunk/http/proxy/src/main/
felix/trunk/http/proxy/src/main/java/
felix/trunk/http/proxy/src/main/java/org/
felix/trunk/http/proxy/src/main/java/org/apache/
felix/trunk/http/proxy/src/main/java/org/apache/felix/
felix/trunk/http/proxy/src/main/java/org/apache/felix/http/
felix/trunk/http/proxy/src/main/java/org/apache/felix/http/proxy/
felix/trunk/http/proxy/src/main/java/org/apache/felix/http/proxy/DispatcherTracker.java
felix/trunk/http/proxy/src/main/java/org/apache/felix/http/proxy/ProxyServlet.java
felix/trunk/http/samples/
felix/trunk/http/samples/bridge/
felix/trunk/http/samples/bridge/pom.xml
felix/trunk/http/samples/bridge/src/
felix/trunk/http/samples/bridge/src/main/
felix/trunk/http/samples/bridge/src/main/java/
felix/trunk/http/samples/bridge/src/main/java/org/
felix/trunk/http/samples/bridge/src/main/java/org/apache/
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/http/
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/http/samples/
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/http/samples/bridge/
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/http/samples/bridge/FrameworkService.java
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/http/samples/bridge/ProvisionActivator.java
felix/trunk/http/samples/bridge/src/main/java/org/apache/felix/http/samples/bridge/StartupListener.java
felix/trunk/http/samples/bridge/src/main/webapp/
felix/trunk/http/samples/bridge/src/main/webapp/WEB-INF/
felix/trunk/http/samples/bridge/src/main/webapp/WEB-INF/framework.properties
felix/trunk/http/samples/bridge/src/main/webapp/WEB-INF/web.xml
felix/trunk/http/samples/filter/
felix/trunk/http/samples/filter/pom.xml
felix/trunk/http/samples/filter/src/
felix/trunk/http/samples/filter/src/main/
felix/trunk/http/samples/filter/src/main/java/
felix/trunk/http/samples/filter/src/main/java/org/
felix/trunk/http/samples/filter/src/main/java/org/apache/
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/Activator.java
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestFilter.java
felix/trunk/http/samples/filter/src/main/java/org/apache/felix/http/samples/filter/TestServlet.java
felix/trunk/http/samples/whiteboard/
felix/trunk/http/samples/whiteboard/pom.xml
felix/trunk/http/samples/whiteboard/src/
felix/trunk/http/samples/whiteboard/src/main/
felix/trunk/http/samples/whiteboard/src/main/java/
felix/trunk/http/samples/whiteboard/src/main/java/org/
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/samples/
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/samples/whiteboard/
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/samples/whiteboard/Activator.java
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/samples/whiteboard/TestFilter.java
felix/trunk/http/samples/whiteboard/src/main/java/org/apache/felix/http/samples/whiteboard/TestServlet.java
felix/trunk/http/whiteboard/
felix/trunk/http/whiteboard/pom.xml
felix/trunk/http/whiteboard/src/
felix/trunk/http/whiteboard/src/main/
felix/trunk/http/whiteboard/src/main/java/
felix/trunk/http/whiteboard/src/main/java/org/
felix/trunk/http/whiteboard/src/main/java/org/apache/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/AbstractMapping.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/DefaultHttpContext.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManager.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/AbstractTracker.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/FilterTracker.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpContextTracker.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/HttpServiceTracker.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/tracker/ServletTracker.java
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/
felix/trunk/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java
Added: felix/trunk/http/LICENSE
URL: http://svn.apache.org/viewvc/felix/trunk/http/LICENSE?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/LICENSE (added)
+++ felix/trunk/http/LICENSE Mon Sep 14 09:59:12 2009
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
Added: felix/trunk/http/README
URL: http://svn.apache.org/viewvc/felix/trunk/http/README?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/README (added)
+++ felix/trunk/http/README Mon Sep 14 09:59:12 2009
@@ -0,0 +1,2 @@
+Extended OSGi HttpService
+-------------------------
Added: felix/trunk/http/api/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/http/api/pom.xml?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/api/pom.xml (added)
+++ felix/trunk/http/api/pom.xml Mon Sep 14 09:59:12 2009
@@ -0,0 +1,47 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <name>Apache Felix Http Api</name>
+ <artifactId>org.apache.felix.http.api</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: felix/trunk/http/api/src/main/java/org/apache/felix/http/api/ExtHttpService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/api/src/main/java/org/apache/felix/http/api/ExtHttpService.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/api/src/main/java/org/apache/felix/http/api/ExtHttpService.java (added)
+++ felix/trunk/http/api/src/main/java/org/apache/felix/http/api/ExtHttpService.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,35 @@
+/*
+ * 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.api;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.HttpContext;
+import java.util.Dictionary;
+
+public interface ExtHttpService
+ extends HttpService
+{
+ public void registerFilter(Filter filter, String pattern, Dictionary initParams, int ranking, HttpContext context)
+ throws ServletException;
+
+ public void unregisterFilter(Filter filter);
+
+ public void unregisterServlet(Servlet servlet);
+}
Added: felix/trunk/http/base/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/pom.xml?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/pom.xml (added)
+++ felix/trunk/http/base/pom.xml Mon Sep 14 09:59:12 2009
@@ -0,0 +1,53 @@
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.http</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <name>Apache Felix Http Base</name>
+ <artifactId>org.apache.felix.http.base</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.http.api</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.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.base.internal;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.apache.felix.http.base.internal.util.SystemLogger;
+
+public abstract class AbstractActivator
+ implements BundleActivator
+{
+ private BundleContext context;
+ private DispatcherServlet dispatcher;
+ private HttpServiceController controller;
+
+ protected final BundleContext getBundleContext()
+ {
+ return this.context;
+ }
+
+ protected final DispatcherServlet getDispatcherServlet()
+ {
+ return this.dispatcher;
+ }
+
+ protected final HttpServiceController getHttpServiceController()
+ {
+ return this.controller;
+ }
+
+ public final void start(BundleContext context)
+ throws Exception
+ {
+ this.context = context;
+ this.controller = new HttpServiceController(this.context);
+ this.dispatcher = new DispatcherServlet(this.controller);
+
+ SystemLogger.get().open(context);
+ doStart();
+ }
+
+ public final void stop(BundleContext context)
+ throws Exception
+ {
+ doStop();
+
+ this.controller.unregister();
+ this.dispatcher.destroy();
+ SystemLogger.get().close();
+ }
+
+ protected abstract void doStart()
+ throws Exception;
+
+ protected abstract void doStop()
+ throws Exception;
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/DispatcherServlet.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.base.internal;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import javax.servlet.ServletConfig;
+import java.io.IOException;
+
+public final class DispatcherServlet
+ extends HttpServlet
+{
+ private final HttpServiceController controller;
+
+ public DispatcherServlet(HttpServiceController controller)
+ {
+ this.controller = controller;
+ }
+
+ @Override
+ public void init(ServletConfig config)
+ throws ServletException
+ {
+ super.init(config);
+ this.controller.register(getServletContext());
+ }
+
+ @Override
+ public void destroy()
+ {
+ this.controller.unregister();
+ super.destroy();
+ }
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ this.controller.getDispatcher().dispatch(req, res);
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,80 @@
+/*
+ * 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.base.internal;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.HttpService;
+import org.apache.felix.http.base.internal.handler.HandlerRegistry;
+import org.apache.felix.http.base.internal.dispatch.Dispatcher;
+import org.apache.felix.http.base.internal.service.HttpServiceFactory;
+import org.apache.felix.http.api.ExtHttpService;
+import javax.servlet.ServletContext;
+import java.util.Hashtable;
+
+public final class HttpServiceController
+{
+ private final BundleContext bundleContext;
+ private final HandlerRegistry registry;
+ private final Dispatcher dispatcher;
+ private final Hashtable<String, Object> serviceProps;
+ private ServiceRegistration serviceReg;
+
+ public HttpServiceController(BundleContext bundleContext)
+ {
+ this.bundleContext = bundleContext;
+ this.registry = new HandlerRegistry();
+ this.dispatcher = new Dispatcher(this.registry);
+ this.serviceProps = new Hashtable<String, Object>();
+ }
+
+ public Dispatcher getDispatcher()
+ {
+ return this.dispatcher;
+ }
+
+ public void setProperties(Hashtable<String, Object> props)
+ {
+ this.serviceProps.clear();
+ this.serviceProps.putAll(props);
+
+ if (this.serviceReg != null) {
+ this.serviceReg.setProperties(this.serviceProps);
+ }
+ }
+
+ public void register(ServletContext servletContext)
+ {
+ HttpServiceFactory factory = new HttpServiceFactory(servletContext, this.registry);
+ String[] ifaces = new String[] { HttpService.class.getName(), ExtHttpService.class.getName() };
+ this.serviceReg = this.bundleContext.registerService(ifaces, factory, this.serviceProps);
+ }
+
+ public void unregister()
+ {
+ if (this.serviceReg == null) {
+ return;
+ }
+
+ try {
+ this.serviceReg.unregister();
+ this.registry.removeAll();
+ } finally {
+ this.serviceReg = null;
+ }
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,29 @@
+/*
+ * 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.base.internal.context;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public interface ExtServletContext
+ extends ServletContext
+{
+ public boolean handleSecurity(HttpServletRequest req, HttpServletResponse res)
+ throws IOException;
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,224 @@
+/*
+ * 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.base.internal.context;
+
+import org.osgi.service.http.HttpContext;
+import org.osgi.framework.Bundle;
+import org.apache.felix.http.base.internal.util.MimeTypes;
+import org.apache.felix.http.base.internal.util.SystemLogger;
+
+import javax.servlet.ServletContext;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.net.URL;
+import java.io.InputStream;
+import java.io.IOException;
+
+public final class ServletContextImpl
+ implements ExtServletContext
+{
+ private final Bundle bundle;
+ private final ServletContext context;
+ private final HttpContext httpContext;
+ private final Map<String, Object> attributes;
+
+ public ServletContextImpl(Bundle bundle, ServletContext context, HttpContext httpContext)
+ {
+ this.bundle = bundle;
+ this.context = context;
+ this.httpContext = httpContext;
+ this.attributes = new ConcurrentHashMap<String, Object>();
+ }
+
+ public String getContextPath()
+ {
+ return this.context.getContextPath();
+ }
+
+ public ServletContext getContext(String uri)
+ {
+ return this.context.getContext(uri);
+ }
+
+ public int getMajorVersion()
+ {
+ return this.context.getMajorVersion();
+ }
+
+ public int getMinorVersion()
+ {
+ return this.context.getMinorVersion();
+ }
+
+ public Set getResourcePaths(String path)
+ {
+ Enumeration paths = this.bundle.getEntryPaths(normalizePath(path));
+ if ((paths == null) || !paths.hasMoreElements()) {
+ return null;
+ }
+
+ Set<String> set = new HashSet<String>();
+ while (paths.hasMoreElements()) {
+ set.add((String)paths.nextElement());
+ }
+
+ return set;
+ }
+
+ public URL getResource(String path)
+ {
+ return this.httpContext.getResource(normalizePath(path));
+ }
+
+ public InputStream getResourceAsStream(String path)
+ {
+ URL res = getResource(path);
+ if (res != null) {
+ try {
+ return res.openStream();
+ } catch (IOException e) {
+ // Do nothing
+ }
+ }
+
+ return null;
+ }
+
+ private String normalizePath(String path)
+ {
+ if (path == null) {
+ return null;
+ }
+
+ String normalizedPath = path.trim().replaceAll("/+", "/");
+ if (normalizedPath.startsWith("/") && (normalizedPath.length() > 1)) {
+ normalizedPath = normalizedPath.substring(1);
+ }
+
+ return normalizedPath;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String uri)
+ {
+ return null;
+ }
+
+ public RequestDispatcher getNamedDispatcher(String name)
+ {
+ return null;
+ }
+
+ public String getInitParameter(String name)
+ {
+ return null;
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return Collections.enumeration(Collections.emptyList());
+ }
+
+ public Object getAttribute(String name)
+ {
+ return this.attributes.get(name);
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return Collections.enumeration(this.attributes.keySet());
+ }
+
+ public void setAttribute(String name, Object value)
+ {
+ this.attributes.put(name, value);
+ }
+
+ public void removeAttribute(String name)
+ {
+ this.attributes.remove(name);
+ }
+
+ @SuppressWarnings("deprecation")
+ public Servlet getServlet(String name)
+ throws ServletException
+ {
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ public Enumeration getServlets()
+ {
+ return Collections.enumeration(Collections.emptyList());
+ }
+
+ @SuppressWarnings("deprecation")
+ public Enumeration getServletNames()
+ {
+ return Collections.enumeration(Collections.emptyList());
+ }
+
+ public void log(String message)
+ {
+ SystemLogger.get().info(message);
+ }
+
+ public void log(Exception cause, String message)
+ {
+ SystemLogger.get().error(message, cause);
+ }
+
+ public void log(String message, Throwable cause)
+ {
+ SystemLogger.get().error(message, cause);
+ }
+
+ public String getServletContextName()
+ {
+ return this.context.getServletContextName();
+ }
+
+ public String getRealPath(String name)
+ {
+ return null;
+ }
+
+ public String getServerInfo()
+ {
+ return this.context.getServerInfo();
+ }
+
+ public String getMimeType(String file)
+ {
+ String type = this.httpContext.getMimeType(file);
+ if (type != null) {
+ return type;
+ }
+
+ return MimeTypes.get().getByFile(file);
+ }
+
+ public boolean handleSecurity(HttpServletRequest req, HttpServletResponse res)
+ throws IOException
+ {
+ return this.httpContext.handleSecurity(req, res);
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.base.internal.context;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+
+import javax.servlet.ServletContext;
+import java.util.Map;
+import java.util.HashMap;
+
+public final class ServletContextManager
+{
+ private final Bundle bundle;
+ private final ServletContext context;
+ private final Map<HttpContext, ExtServletContext> contextMap;
+
+ public ServletContextManager(Bundle bundle, ServletContext context)
+ {
+ this.bundle = bundle;
+ this.context = context;
+ this.contextMap = new HashMap<HttpContext, ExtServletContext>();
+ }
+
+ public ExtServletContext getServletContext(HttpContext httpContext)
+ {
+ synchronized (this.contextMap) {
+ ExtServletContext context = this.contextMap.get(httpContext);
+ if (context == null) {
+ context = addServletContext(httpContext);
+ }
+
+ return context;
+ }
+ }
+
+ private ExtServletContext addServletContext(HttpContext httpContext)
+ {
+ ExtServletContext context = new ServletContextImpl(this.bundle, this.context, httpContext);
+ this.contextMap.put(httpContext, context);
+ return context;
+ }
+}
\ No newline at end of file
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,41 @@
+/*
+ * 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.base.internal.dispatch;
+
+import org.apache.felix.http.base.internal.handler.HandlerRegistry;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+public final class Dispatcher
+{
+ private final HandlerRegistry handlerRegistry;
+
+ public Dispatcher(HandlerRegistry handlerRegistry)
+ {
+ this.handlerRegistry = handlerRegistry;
+ }
+
+ public void dispatch(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ ServletPipeline servletPipeline = new ServletPipeline(this.handlerRegistry.getServlets());
+ FilterPipeline filterPipeline = new FilterPipeline(this.handlerRegistry.getFilters(), servletPipeline);
+ filterPipeline.dispatch(req, res, new NotFoundFilterChain());
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/FilterPipeline.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/FilterPipeline.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/FilterPipeline.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/FilterPipeline.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,66 @@
+/*
+ * 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.base.internal.dispatch;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.ServletException;
+import javax.servlet.FilterChain;
+import javax.servlet.RequestDispatcher;
+import java.io.IOException;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
+
+public final class FilterPipeline
+{
+ private final FilterHandler[] handlers;
+ private final ServletPipeline servletPipeline;
+
+ public FilterPipeline(FilterHandler[] handlers, ServletPipeline servletPipeline)
+ {
+ this.handlers = handlers;
+ this.servletPipeline = servletPipeline;
+ }
+
+ public void dispatch(HttpServletRequest req, HttpServletResponse res, FilterChain proceedingChain)
+ throws ServletException, IOException
+ {
+ FilterChain chain = new InvocationFilterChain(this.handlers, this.servletPipeline, proceedingChain);
+
+ if (this.servletPipeline.hasServletsMapped()) {
+ req = new RequestWrapper(req);
+ }
+
+ chain.doFilter(req, res);
+ }
+
+ private final class RequestWrapper
+ extends HttpServletRequestWrapper
+ {
+ public RequestWrapper(HttpServletRequest req)
+ {
+ super(req);
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(String path)
+ {
+ final RequestDispatcher dispatcher = servletPipeline.getRequestDispatcher(path);
+ return (null != dispatcher) ? dispatcher : super.getRequestDispatcher(path);
+ }
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/HttpFilterChain.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/HttpFilterChain.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/HttpFilterChain.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/HttpFilterChain.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,38 @@
+/*
+ * 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.base.internal.dispatch;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public abstract class HttpFilterChain
+ implements FilterChain
+{
+ public final void doFilter(ServletRequest req, ServletResponse res)
+ throws IOException, ServletException
+ {
+ doFilter((HttpServletRequest)req, (HttpServletResponse)res);
+ }
+
+ protected abstract void doFilter(HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException;
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationFilterChain.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationFilterChain.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationFilterChain.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationFilterChain.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.base.internal.dispatch;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import org.apache.felix.http.base.internal.handler.FilterHandler;
+
+public final class InvocationFilterChain
+ extends HttpFilterChain
+{
+ private final FilterHandler[] handlers;
+ private final ServletPipeline servletPipeline;
+ private final FilterChain proceedingChain;
+ private int index = -1;
+
+ public InvocationFilterChain(FilterHandler[] handlers, ServletPipeline servletPipeline, FilterChain proceedingChain)
+ {
+ this.handlers = handlers;
+ this.servletPipeline = servletPipeline;
+ this.proceedingChain = proceedingChain;
+ }
+
+ protected void doFilter(HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException
+ {
+ this.index++;
+
+ if (this.index < this.handlers.length) {
+ this.handlers[this.index].handle(req, res, this);
+ } else {
+ if (!this.servletPipeline.handle(req, res)) {
+ this.proceedingChain.doFilter(req, res);
+ }
+ }
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/NotFoundFilterChain.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/NotFoundFilterChain.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/NotFoundFilterChain.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/NotFoundFilterChain.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.base.internal.dispatch;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public final class NotFoundFilterChain
+ extends HttpFilterChain
+{
+ protected void doFilter(HttpServletRequest req, HttpServletResponse res)
+ throws IOException, ServletException
+ {
+ res.sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletPipeline.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletPipeline.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletPipeline.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletPipeline.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,111 @@
+/*
+ * 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.base.internal.dispatch;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.ServletException;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
+
+public final class ServletPipeline
+{
+ private final ServletHandler[] handlers;
+
+ public ServletPipeline(ServletHandler[] handlers)
+ {
+ this.handlers = handlers;
+ }
+
+ public boolean handle(HttpServletRequest req, HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ for (ServletHandler handler : this.handlers) {
+ if (handler.handle(req, res)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean hasServletsMapped()
+ {
+ return this.handlers.length > 0;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path)
+ {
+ for (ServletHandler handler : this.handlers) {
+ if (handler.matches(path)) {
+ return new Dispatcher(path, handler);
+ }
+ }
+
+ return null;
+ }
+
+ private final class Dispatcher
+ implements RequestDispatcher
+ {
+ private final String path;
+ private final ServletHandler handler;
+
+ public Dispatcher(String path, ServletHandler handler)
+ {
+ this.path = path;
+ this.handler = handler;
+ }
+
+ public void forward(ServletRequest req, ServletResponse res)
+ throws ServletException, IOException
+ {
+ if (res.isCommitted()) {
+ throw new ServletException("Response has been committed");
+ }
+
+ this.handler.handle(new RequestWrapper((HttpServletRequest)req, this.path), (HttpServletResponse)res);
+ }
+
+ public void include(ServletRequest req, ServletResponse res)
+ throws ServletException, IOException
+ {
+ this.handler.handle((HttpServletRequest)req, (HttpServletResponse)res);
+ }
+ }
+
+ private final class RequestWrapper
+ extends HttpServletRequestWrapper
+ {
+ private final String requestUri;
+
+ public RequestWrapper(HttpServletRequest req, String requestUri)
+ {
+ super(req);
+ this.requestUri = requestUri;
+ }
+
+ public String getRequestURI()
+ {
+ return this.requestUri;
+ }
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/AbstractHandler.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,77 @@
+/*
+ * 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.base.internal.handler;
+
+import javax.servlet.ServletException;
+import org.apache.felix.http.base.internal.context.ExtServletContext;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public abstract class AbstractHandler
+{
+ private final static AtomicInteger ID =
+ new AtomicInteger();
+
+ private final String id;
+ private final ExtServletContext context;
+ private final Map<String, String> initParams;
+
+ public AbstractHandler(ExtServletContext context)
+ {
+ this.id = "" + ID.incrementAndGet();
+ this.context = context;
+ this.initParams = new HashMap<String, String>();
+ }
+
+ public final String getId()
+ {
+ return this.id;
+ }
+
+ protected final ExtServletContext getContext()
+ {
+ return this.context;
+ }
+
+ public final Map<String, String> getInitParams()
+ {
+ return this.initParams;
+ }
+
+ public final void setInitParams(Dictionary map)
+ {
+ this.initParams.clear();
+ if (map == null) {
+ return;
+ }
+
+ Enumeration e = map.keys();
+ while (e.hasMoreElements()) {
+ Object key = e.nextElement();
+ Object value = map.get(key);
+
+ if ((key instanceof String) && (value instanceof String)) {
+ this.initParams.put((String)key, (String)value);
+ }
+ }
+ }
+
+ public abstract void init()
+ throws ServletException;
+
+ public abstract void destroy();
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.base.internal.handler;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.util.Map;
+
+public final class FilterConfigImpl
+ implements FilterConfig
+{
+ private final String name;
+ private final ServletContext context;
+ private final Map<String, String> initParams;
+
+ public FilterConfigImpl(String name, ServletContext context, Map<String, String> initParams)
+ {
+ this.name = name;
+ this.context = context;
+ this.initParams = initParams;
+ }
+
+ public String getFilterName()
+ {
+ return this.name;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return this.context;
+ }
+
+ public String getInitParameter(String name)
+ {
+ return this.initParams.get(name);
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return Collections.enumeration(this.initParams.keySet());
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.base.internal.handler;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.felix.http.base.internal.context.ExtServletContext;
+import java.io.IOException;
+
+public final class FilterHandler
+ extends AbstractHandler implements Comparable<FilterHandler>
+{
+ private final Filter filter;
+ private final String pattern;
+ private final int ranking;
+
+ public FilterHandler(ExtServletContext context, Filter filter, String pattern, int ranking)
+ {
+ super(context);
+ this.filter = filter;
+ this.pattern = pattern;
+ this.ranking = ranking;
+ }
+
+ public Filter getFilter()
+ {
+ return this.filter;
+ }
+
+ public void init()
+ throws ServletException
+ {
+ String name = "filter_" + getId();
+ FilterConfig config = new FilterConfigImpl(name, getContext(), getInitParams());
+ this.filter.init(config);
+ }
+
+ public void destroy()
+ {
+ this.filter.destroy();
+ }
+
+ public boolean matches(String uri)
+ {
+ return uri.matches(this.pattern);
+ }
+
+ public void handle(HttpServletRequest req, HttpServletResponse res, FilterChain chain)
+ throws ServletException, IOException
+ {
+ final boolean matches = matches(req.getPathInfo());
+ if (matches) {
+ doHandle(req, res, chain);
+ } else {
+ chain.doFilter(req, res);
+ }
+ }
+
+ private void doHandle(HttpServletRequest req, HttpServletResponse res, FilterChain chain)
+ throws ServletException, IOException
+ {
+ if (!getContext().handleSecurity(req, res)) {
+ res.sendError(HttpServletResponse.SC_FORBIDDEN);
+ } else {
+ this.filter.doFilter(req, res, chain);
+ }
+ }
+
+ public int compareTo(FilterHandler other)
+ {
+ return other.ranking - this.ranking;
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,138 @@
+/*
+ * 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.base.internal.handler;
+
+import org.osgi.service.http.NamespaceException;
+import javax.servlet.ServletException;
+import javax.servlet.Servlet;
+import javax.servlet.Filter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Arrays;
+
+public final class HandlerRegistry
+{
+ private final Map<Servlet, ServletHandler> servletMap;
+ private final Map<Filter, FilterHandler> filterMap;
+ private final Map<String, Servlet> aliasMap;
+ private ServletHandler[] servlets;
+ private FilterHandler[] filters;
+
+ public HandlerRegistry()
+ {
+ this.servletMap = new HashMap<Servlet, ServletHandler>();
+ this.filterMap = new HashMap<Filter, FilterHandler>();
+ this.aliasMap = new HashMap<String, Servlet>();
+ this.servlets = new ServletHandler[0];
+ this.filters = new FilterHandler[0];
+ }
+
+ public ServletHandler[] getServlets()
+ {
+ return this.servlets;
+ }
+
+ public FilterHandler[] getFilters()
+ {
+ return this.filters;
+ }
+
+ public synchronized void addServlet(ServletHandler handler)
+ throws ServletException, NamespaceException
+ {
+ if (this.servletMap.containsKey(handler.getServlet())) {
+ throw new ServletException("Servlet instance already registered");
+ }
+
+ if (this.aliasMap.containsKey(handler.getAlias())) {
+ throw new NamespaceException("Servlet with alias already registered");
+ }
+
+ handler.init();
+ this.servletMap.put(handler.getServlet(), handler);
+ this.aliasMap.put(handler.getAlias(), handler.getServlet());
+ updateServletArray();
+ }
+
+ public synchronized void addFilter(FilterHandler handler)
+ throws ServletException
+ {
+ if (this.filterMap.containsKey(handler.getFilter())) {
+ throw new ServletException("Filter instance already registered");
+ }
+
+ handler.init();
+ this.filterMap.put(handler.getFilter(), handler);
+ updateFilterArray();
+ }
+
+ public synchronized void removeServlet(Servlet servlet)
+ {
+ ServletHandler handler = this.servletMap.remove(servlet);
+ if (handler != null) {
+ updateServletArray();
+ this.aliasMap.remove(handler.getAlias());
+ handler.destroy();
+ }
+ }
+
+ public synchronized void removeFilter(Filter filter)
+ {
+ FilterHandler handler = this.filterMap.remove(filter);
+ if (handler != null) {
+ updateFilterArray();
+ handler.destroy();
+ }
+ }
+
+ public synchronized Servlet getServletByAlias(String alias)
+ {
+ return this.aliasMap.get(alias);
+ }
+
+ public synchronized void removeAll()
+ {
+ for (ServletHandler handler : this.servletMap.values()) {
+ handler.destroy();
+ }
+
+ for (FilterHandler handler : this.filterMap.values()) {
+ handler.destroy();
+ }
+
+ this.servletMap.clear();
+ this.filterMap.clear();
+ this.aliasMap.clear();
+
+ updateServletArray();
+ updateFilterArray();
+ }
+
+ private void updateServletArray()
+ {
+ ServletHandler[] tmp = this.servletMap.values().toArray(new ServletHandler[this.servletMap.size()]);
+ Arrays.sort(tmp);
+ this.servlets = tmp;
+ }
+
+ private void updateFilterArray()
+ {
+ FilterHandler[] tmp = this.filterMap.values().toArray(new FilterHandler[this.filterMap.size()]);
+ Arrays.sort(tmp);
+ this.filters = tmp;
+ }
+}
Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java?rev=814549&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java (added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java Mon Sep 14 09:59:12 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.base.internal.handler;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletConfig;
+import java.util.Enumeration;
+import java.util.Collections;
+import java.util.Map;
+
+public final class ServletConfigImpl
+ implements ServletConfig
+{
+ private final String name;
+ private final ServletContext context;
+ private final Map<String, String> initParams;
+
+ public ServletConfigImpl(String name, ServletContext context, Map<String, String> initParams)
+ {
+ this.name = name;
+ this.context = context;
+ this.initParams = initParams;
+ }
+
+ public String getServletName()
+ {
+ return this.name;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return this.context;
+ }
+
+ public String getInitParameter(String name)
+ {
+ return this.initParams.get(name);
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return Collections.enumeration(this.initParams.keySet());
+ }
+}
\ No newline at end of file