You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by kg...@apache.org on 2011/10/13 07:01:43 UTC
svn commit: r1182650 [1/3] - in /felix/trunk/httplite: ./ META-INF/ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/http/
src/main/java/org/apache/felix/http/ligh...
Author: kgilmer
Date: Thu Oct 13 05:01:42 2011
New Revision: 1182650
URL: http://svn.apache.org/viewvc?rev=1182650&view=rev
Log:
httplite: commit source archive from FELIX-3084. Also see FELIX-538.
Added:
felix/trunk/httplite/LICENSE-2.0.txt
felix/trunk/httplite/META-INF/
felix/trunk/httplite/META-INF/LICENSE
felix/trunk/httplite/META-INF/MANIFEST.MF
felix/trunk/httplite/META-INF/NOTICE
felix/trunk/httplite/build.xml
felix/trunk/httplite/pom.xml
felix/trunk/httplite/src/
felix/trunk/httplite/src/main/
felix/trunk/httplite/src/main/java/
felix/trunk/httplite/src/main/java/org/
felix/trunk/httplite/src/main/java/org/apache/
felix/trunk/httplite/src/main/java/org/apache/felix/
felix/trunk/httplite/src/main/java/org/apache/felix/http/
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Activator.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/DefaultContextImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceFactoryImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Logger.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistration.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationHandler.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationResolver.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/Connection.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/ResourceHandler.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/Server.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/ServletHandler.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/ThreadGate.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/server/ThreadPool.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/ConcreteServletInputStream.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/HttpConstants.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/HttpServletRequestImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/HttpServletResponseImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/ServletConfigImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/ServletContextImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/ServletOutputStreamImpl.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/ServletPrintWriter.java
felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/servlet/UnimplementedAPIException.java
Added: felix/trunk/httplite/LICENSE-2.0.txt
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/LICENSE-2.0.txt?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/LICENSE-2.0.txt (added)
+++ felix/trunk/httplite/LICENSE-2.0.txt Thu Oct 13 05:01:42 2011
@@ -0,0 +1,202 @@
+
+ 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 2011 Ken Gilmer
+
+ 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/httplite/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/META-INF/LICENSE?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/META-INF/LICENSE (added)
+++ felix/trunk/httplite/META-INF/LICENSE Thu Oct 13 05:01:42 2011
@@ -0,0 +1,202 @@
+
+ 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/httplite/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/META-INF/MANIFEST.MF?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/META-INF/MANIFEST.MF (added)
+++ felix/trunk/httplite/META-INF/MANIFEST.MF Thu Oct 13 05:01:42 2011
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Apache Felix Lightweight Http Service Bundle
+Bundle-SymbolicName: org.apache.felix.http.lightweight
+Bundle-Activator: org.apache.felix.http.lightweight.osgi.Activator
+Bundle-Version: 0.2.0
+Import-Package:
+ org.osgi.framework,
+ org.osgi.service.http;version="1.2.1",
+ javax.servlet;version="2.4",
+ javax.servlet.http;version="2.4",
+ javax.servlet.resources;version="2.4"
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+
Added: felix/trunk/httplite/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/META-INF/NOTICE?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/META-INF/NOTICE (added)
+++ felix/trunk/httplite/META-INF/NOTICE Thu Oct 13 05:01:42 2011
@@ -0,0 +1,5 @@
+Apache Felix HTTP Server
+Copyright 2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
Added: felix/trunk/httplite/build.xml
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/build.xml?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/build.xml (added)
+++ felix/trunk/httplite/build.xml Thu Oct 13 05:01:42 2011
@@ -0,0 +1,138 @@
+<?xml version="1.0"?>
+<project name="org.apache.felix.http.lightweight" default="jar">
+ <property name="src.dir" location="src/" />
+ <property name="project.description" value="Lightweight HTTP Service for Apache Felix" />
+ <property name="external.dir" location="external" />
+ <property name="doc.dir" location="${basedir}/docs" />
+ <property name="build.dir" location="${basedir}/classes" />
+
+ <property name="wget.bin" location="/usr/bin/wget" />
+ <property name="svn.bin" location="/usr/bin/svn" />
+ <property name="git.bin" location="/usr/bin/git" />
+ <property name="rm.bin" location="/bin/rm" />
+
+ <property name="framework.fqpn" value="org.apache.felix.framework" />
+ <property name="compendium.fqpn" value="org.osgi.compendium" />
+
+ <tstamp>
+ <format property="TS_NOW" pattern="yyyy-MM-dd HH:mm:ss" />
+ </tstamp>
+
+ <target name="clean-external" unless="${skip.fetch}">
+ <delete dir="${external.dir}" />
+ </target>
+
+ <target name="clean" depends="clean-external" description="remove intermediate files">
+ <delete dir="${build.dir}" />
+ <delete dir="${build.dir}-debug" />
+ <delete dir="${doc.dir}" />
+ <delete dir="org/apache" />
+ <delete dir="org/osgi" />
+ <delete dir="bin" />
+ <delete file="${ant.project.name}-min.jar" />
+ <delete file="${ant.project.name}-all.jar" />
+ </target>
+
+ <target name="fetch" depends="clean" unless="${skip.fetch}">
+ <mkdir dir="${external.dir}" />
+ <exec executable="${wget.bin}" dir="${external.dir}">
+ <arg value="http://www.meisei-u.ac.jp/mirror/apache/dist//felix/org.apache.felix.framework-3.2.2.jar" />
+ </exec>
+
+ <exec executable="${svn.bin}">
+ <arg value="export" />
+ <arg value="http://svn.apache.org/repos/asf/felix/releases/org.osgi.compendium-1.4.0" />
+ <arg value="${external.dir}/org.osgi.compendium" />
+ </exec>
+
+ <exec executable="${svn.bin}">
+ <arg value="export" />
+ <arg value="http://svn.apache.org/repos/asf/tomcat/archive/servletapi/branches/other/servlet2.4-jsp2.0-tc5.x/ASF/jsr154" />
+ <arg value="${external.dir}/servletapi" />
+ </exec>
+ </target>
+
+ <target name="stage-dependencies" depends="fetch">
+ <copy toDir="${src.dir}">
+ <fileset dir="${external.dir}/org.osgi.compendium/src" includes="main/java/org/osgi/service/http/**/*.java" />
+ </copy>
+
+ <copy toDir="${src.dir}">
+ <fileset dir="${external.dir}/servletapi/src" />
+ </copy>
+ <copy toDir="${src.dir}/share/javax/servlet/http">
+ <fileset dir="${external.dir}/servletapi/examples/WEB-INF/classes" includes="*.properties" />
+ </copy>
+ <copy toDir="${src.dir}/share/javax/servlet/resources">
+ <fileset dir="${src.dir}/share/dtd" />
+ </copy>
+
+ <delete dir="${src.dir}/etc" />
+ <delete dir="examples" />
+ </target>
+
+ <target name="compile" depends="stage-dependencies" description="compile the Java source code to class files">
+ <mkdir dir="${build.dir}" />
+ <mkdir dir="${build.dir}-debug" />
+
+ <javac destdir="${build.dir}" source="1.4" target="1.4" encoding="utf-8" fork="true" includeantruntime="false" debug="false">
+ <src path="${src.dir}/main/java" />
+ <src path="${src.dir}/share" />
+ <classpath path="${external.dir}/org.apache.felix.framework-3.2.2.jar" />
+ </javac>
+ <javac destdir="${build.dir}-debug" source="1.4" target="1.4" encoding="utf-8" fork="true" includeantruntime="false" debug="true" debuglevel="lines,vars,source">
+ <src path="${src.dir}/main/java" />
+ <src path="${src.dir}/share" />
+ <classpath path="${external.dir}/org.apache.felix.framework-3.2.2.jar" />
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile" description="create a Jar file for the application">
+ <mkdir dir="${build.dir}/META-INF" />
+ <copy toDir="${build.dir}/META-INF-MIN">
+ <fileset dir="META-INF" />
+ </copy>
+
+ <copy toDir="${build.dir}/META-INF-ALL">
+ <fileset dir="META-INF" />
+ </copy>
+
+ <manifest file="${build.dir}/META-INF-ALL/MANIFEST.MF" mode="update">
+ <attribute name="Import-Package" value="org.osgi.framework" />
+ <attribute name="Export-Package" value='org.osgi.service.http;version="1.2.1", javax.servlet;version="2.4",javax.servlet.http;version="2.4",javax.servlet.resources;version="2.4"' />
+ <attribute name="Built-By" value="${user.name}" />
+ <attribute name="Built-Date" value="${TS_NOW}" />
+ </manifest>
+
+ <manifest file="${build.dir}/META-INF-MIN/MANIFEST.MF" mode="update">
+ <attribute name="Import-Package" value="org.osgi.framework,org.osgi.service.http,javax.servlet,javax.servlet.http,javax.servlet.resources" />
+ <attribute name="Export-Package" value="" />
+ <attribute name="Built-By" value="${user.name}" />
+ <attribute name="Built-Date" value="${TS_NOW}" />
+ </manifest>
+
+ <jar destfile="${ant.project.name}-debug-all.jar" manifest="${build.dir}/META-INF-ALL/MANIFEST.MF">
+ <fileset dir="${build.dir}-debug" includes="**/*.class,**/*.properties,**/*.dtd,**/*.xsd" />
+ <fileset dir="${src.dir}/share" includes="javax/servlet/**/*.properties,javax/servlet/**/*.dtd,javax/servlet/**/*.xsd" />
+ <fileset dir="." includes="LICENSE-2.0.txt" />
+ </jar>
+
+ <jar destfile="${ant.project.name}-all.jar" manifest="${build.dir}/META-INF-ALL/MANIFEST.MF">
+ <fileset dir="${build.dir}" includes="**/*.class,**/*.properties,**/*.dtd,**/*.xsd" />
+ <fileset dir="${src.dir}/share" includes="javax/servlet/**/*.properties,javax/servlet/**/*.dtd,javax/servlet/**/*.xsd" />
+ <fileset dir="." includes="LICENSE-2.0.txt" />
+ </jar>
+
+ <jar destfile="${ant.project.name}-min.jar" manifest="${build.dir}/META-INF-MIN/MANIFEST.MF">
+ <fileset dir="${build.dir}" includes="org/apache/felix/http/lightweight/**/*.class" />
+ <fileset dir="." includes="LICENSE-2.0.txt" />
+ </jar>
+ </target>
+
+ <target name="javadoc" depends="jar">
+ <javadoc sourcepath="${src.dir}/main/java" defaultexcludes="no" destdir="${doc.dir}" version="true" use="true" windowtitle="${project.description}">
+ <classpath path="${external.dir}/org.apache.felix.framework-3.2.2.jar" />
+ <classpath path="${external.dir}/osgi.cmpn.jar" />
+ </javadoc>
+ </target>
+</project>
\ No newline at end of file
Added: felix/trunk/httplite/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/pom.xml?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/pom.xml (added)
+++ felix/trunk/httplite/pom.xml Thu Oct 13 05:01:42 2011
@@ -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.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>1.0.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>bundle</packaging>
+ <name>Apache Felix HTTP Server</name>
+ <description>A simple HTTP server.</description>
+ <artifactId>org.apache.felix.sandbox.httpserver</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.0.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Private-Package>org.apache.felix.sandbox.httpserver.*</Private-Package>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Activator>org.apache.felix.sandbox.httpserver.Activator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Activator.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Activator.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Activator.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Activator.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,181 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.felix.http.lightweight.server.Server;
+import org.apache.felix.http.lightweight.servlet.HttpConstants;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.http.HttpService;
+
+/**
+ * Activator for org.apache.felix.http.lightweight HTTP Service implementation.
+ *
+ * The activator will read in system properties that are relevant to the service
+ * and register the HttpService in the service registry.
+ *
+**/
+public class Activator implements BundleActivator
+{
+ /**
+ * Felix-specific log level setting as system property.
+ */
+ private static final String FELIX_LOG_LEVEL = "felix.log.level";
+ /**
+ * HTTP Service registration.
+ */
+ private ServiceRegistration m_httpServiceReg;
+ /**
+ * Reference to socket server.
+ */
+ private Server m_server;
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception
+ {
+ Logger logger = createLogger(context);
+
+ //Set the internal logger's log level if specified.
+ if (context.getProperty(FELIX_LOG_LEVEL) != null)
+ {
+ logger.setLogLevel(Integer.parseInt(context.getProperty(FELIX_LOG_LEVEL)));
+ }
+
+ //Only enable the HTTPService if the HTTP_ENABLE property is set or undefined.
+ if (isPropertyTrue(context, Server.CONFIG_PROPERTY_HTTP_ENABLE, true))
+ {
+ Map config = createConfigMap(context);
+ m_server = new Server(config, logger);
+ m_httpServiceReg = context.registerService(HttpService.class.getName(),
+ new HttpServiceFactoryImpl(logger, m_server),
+ createHttpServiceProperties(Server.getConfiguredPort(config)));
+ }
+
+ //Warn user that HTTPS is not supported if it is specifically enabled.
+ if (isPropertyTrue(context, Server.CONFIG_PROPERTY_HTTPS_ENABLE, false))
+ {
+ logger.log(Logger.LOG_WARNING, Server.CONFIG_PROPERTY_HTTPS_ENABLE
+ + " is not implemented in this http service.");
+ }
+ }
+
+ /**
+ * Create a Dictionary intended to be used with Http Service registration.
+ *
+ * @param port Port number to add to the properties.
+ * @return A dictionary of OSGi service properties associate with the HTTP service.
+ */
+ private Dictionary createHttpServiceProperties(final int port)
+ {
+ Dictionary props = new Properties();
+
+ props.put(HttpConstants.SERVICE_PROPERTY_KEY_HTTP_ENABLE, Boolean.toString(true));
+ props.put(HttpConstants.SERVICE_PROPERTY_KEY_HTTPS_ENABLE,
+ Boolean.toString(false));
+ props.put(HttpConstants.SERVICE_PROPERTY_KEY_HTTP_PORT, Integer.toString(port));
+
+ return props;
+ }
+
+ /**
+ * Create a Map of configuration name/value pairs that the socket server requires to start.
+ *
+ * @param context BundleContext
+ * @return Map of configuration name/value pairs that the socket server requires to start.
+ */
+ private Map createConfigMap(final BundleContext context)
+ {
+ Map config = new HashMap();
+
+ config.put(Server.CONFIG_PROPERTY_HTTP_PORT,
+ context.getProperty(Server.CONFIG_PROPERTY_HTTP_PORT));
+ config.put(Server.CONFIG_PROPERTY_HTTP_ENABLE,
+ context.getProperty(Server.CONFIG_PROPERTY_HTTP_ENABLE));
+ config.put(Server.CONFIG_PROPERTY_HTTPS_ENABLE,
+ context.getProperty(Server.CONFIG_PROPERTY_HTTPS_ENABLE));
+ config.put(Server.CONFIG_PROPERTY_HTTP_DEBUG,
+ context.getProperty(Server.CONFIG_PROPERTY_HTTP_DEBUG));
+ config.put(Server.CONFIG_PROPERTY_THREADPOOL_LIMIT_PROP,
+ context.getProperty(Server.CONFIG_PROPERTY_THREADPOOL_LIMIT_PROP));
+ config.put(Server.CONFIG_PROPERTY_THREADPOOL_TIMEOUT_PROP,
+ context.getProperty(Server.CONFIG_PROPERTY_THREADPOOL_TIMEOUT_PROP));
+ config.put(Server.CONFIG_PROPERTY_CONNECTION_REQUESTLIMIT_PROP,
+ context.getProperty(Server.CONFIG_PROPERTY_CONNECTION_REQUESTLIMIT_PROP));
+ config.put(Server.CONFIG_PROPERTY_CONNECTION_TIMEOUT_PROP,
+ context.getProperty(Server.CONFIG_PROPERTY_CONNECTION_TIMEOUT_PROP));
+
+ return config;
+ }
+
+ /**
+ * @param context BundleContext
+ * @return Logger instance
+ */
+ private Logger createLogger(final BundleContext context)
+ {
+ Logger logger = new Logger();
+ logger.setSystemBundleContext(context);
+
+ return logger;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(final BundleContext context) throws Exception
+ {
+ if (m_httpServiceReg != null)
+ {
+ m_httpServiceReg.unregister();
+ }
+
+ if (m_server.getState() == Server.ACTIVE_STATE)
+ {
+ m_server.stop();
+ }
+ }
+
+ /**
+ * Convenience method that returns true if Bundle property exists and is true, false if false, and defaultValue otherwise.
+ * @param context BundleContext
+ * @param name Property name
+ * @param defaultValue default value for case that the key does not exist.
+ * @return true if Bundle property exists and is true, false if false, and defaultValue otherwise.
+ */
+ private static boolean isPropertyTrue(final BundleContext context, final String name,
+ final boolean defaultValue)
+ {
+ String value = context.getProperty(name);
+
+ if (value == null)
+ {
+ return defaultValue;
+ }
+
+ return Boolean.valueOf(value).booleanValue();
+ }
+}
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/DefaultContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/DefaultContextImpl.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/DefaultContextImpl.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/DefaultContextImpl.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,98 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.net.URL;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+
+/**
+ * This class was adapted from the Jetty HTTP Service: http://felix.apache.org/site/apache-felix-http-service.html.
+ *
+ * Implementation of default HttpContext as per OSGi specification.
+ *
+ * Notes
+ *
+ * - no current inclusion/support for permissions
+ * - security allows all request. Spec leaves security handling to be
+ * implementation specific, but does outline some suggested handling.
+ * Deeper than my understanding of HTTP at this stage, so left for now.
+ */
+public class DefaultContextImpl implements HttpContext
+{
+ /**
+ * Reference to bundle that registered with the Http Service.
+ */
+ private Bundle m_bundle;
+
+ /**
+ * @param bundle bundle that registered with the Http Service.
+ */
+ public DefaultContextImpl(final Bundle bundle)
+ {
+ m_bundle = bundle;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.http.HttpContext#getMimeType(java.lang.String)
+ */
+ public String getMimeType(final String name)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.http.HttpContext#getResource(java.lang.String)
+ */
+ public URL getResource(final String name)
+ {
+ //TODO: temp measure for name. Bundle classloading doesn't seem to find
+ // resources which have a leading "/". This code should be removed
+ // if the bundle classloader is changed to allow a leading "/"
+ String resource = name;
+
+ if (name.startsWith("/"))
+ {
+ resource = name.substring(1);
+ }
+
+ URL url = m_bundle.getResource(resource);
+
+ if (url == null)
+ {
+ url = this.getClass().getResource(resource);
+ }
+
+ return url;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.service.http.HttpContext#handleSecurity(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+ */
+ public boolean handleSecurity(final HttpServletRequest request,
+ final HttpServletResponse response)
+ {
+ //By default all security is "handled".
+ return true;
+ }
+}
\ No newline at end of file
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceFactoryImpl.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceFactoryImpl.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceFactoryImpl.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,139 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.http.lightweight.server.Server;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * HttpServiceFactory creates a separate HttpService instance for every requester, so that
+ * the requester (client) bundle has access to it's own class loader for getting resources.
+ *
+ */
+public class HttpServiceFactoryImpl implements ServiceFactory
+{
+ /**
+ * Logger instance
+ */
+ private final Logger m_logger;
+ /**
+ * Socket server reference
+ */
+ private final Server m_server;
+ /**
+ * List of service registrations, both Resource and Servlet.
+ */
+ private List m_registrations;
+
+ /**
+ * @param logger
+ * @param m_server
+ */
+ public HttpServiceFactoryImpl(final Logger logger, final Server m_server)
+ {
+ this.m_logger = logger;
+ this.m_server = m_server;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
+ */
+ public Object getService(final Bundle bundle, final ServiceRegistration registration)
+ {
+ HttpServiceImpl httpService = null;
+ try
+ {
+ httpService = new HttpServiceImpl(bundle, m_server, m_logger);
+
+ if (m_server.getState() != Server.ACTIVE_STATE)
+ {
+ m_logger.log(Logger.LOG_INFO, "Starting http server.");
+ httpService.start();
+ }
+
+ if (m_registrations == null)
+ {
+ m_registrations = new ArrayList();
+ }
+
+ m_registrations.add(serializeRegistration(bundle, registration));
+ }
+ catch (IOException e)
+ {
+ m_logger.log(Logger.LOG_ERROR, "Unable to create Http Service.", e);
+ return null;
+ }
+
+ return httpService;
+ }
+
+ /**
+ * Provide a unique string to represent a given registration.
+ *
+ * @param bundle
+ * @param registration
+ * @return
+ */
+ private String serializeRegistration(final Bundle bundle,
+ final ServiceRegistration registration)
+ {
+ return registration.toString() + bundle.getBundleId();
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
+ */
+ public void ungetService(final Bundle bundle, final ServiceRegistration registration,
+ final Object service)
+ {
+ if (m_registrations == null)
+ {
+ throw new IllegalStateException("m_registrations has not been initialized.");
+ }
+
+ String key = serializeRegistration(bundle, registration);
+
+ if (!m_registrations.contains(key))
+ {
+ throw new IllegalStateException("Untracked service registration.");
+ }
+
+ m_registrations.remove(key);
+
+ if (m_registrations.size() == 0 && m_server.getState() == Server.ACTIVE_STATE)
+ {
+ try
+ {
+ m_logger.log(Logger.LOG_INFO,
+ "Stopping http server since no clients are registered.");
+ m_server.stop();
+ }
+ catch (InterruptedException e)
+ {
+ return;
+ }
+ }
+ }
+}
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceImpl.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceImpl.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/HttpServiceImpl.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,319 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.felix.http.lightweight.server.ResourceHandler;
+import org.apache.felix.http.lightweight.server.Server;
+import org.apache.felix.http.lightweight.server.ServletHandler;
+import org.apache.felix.http.lightweight.servlet.HttpServletRequestImpl;
+import org.apache.felix.http.lightweight.servlet.HttpServletResponseImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+/**
+ * The HTTP Service implementation that also implements RegistrationResolver to
+ * provide internal server classes with OSGi service registration data.
+ */
+public class HttpServiceImpl implements HttpService, ServiceRegistrationResolver
+{
+
+ /**
+ * Socket server reference.
+ */
+ private final Server m_server;
+ /**
+ * Map of registered servlets.
+ */
+ private final Map m_servletMap;
+ /**
+ * Logger reference.
+ */
+ private final Logger m_logger;
+ /**
+ * Client bundle reference.
+ */
+ private final Bundle m_bundle;
+
+ /**
+ * @param server
+ * Map of <String, String> of configuration properties for the
+ * HTTP server.
+ * @param bundle
+ * Bundle that registered with the service
+ * @param logger
+ * instance of Logger
+ * @throws IOException
+ */
+ public HttpServiceImpl(final Bundle bundle, final Server server, final Logger logger) throws IOException
+ {
+ this.m_bundle = bundle;
+ this.m_logger = logger;
+ this.m_server = server;
+ this.m_servletMap = new HashMap();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.osgi.service.http.HttpService#registerResources(java.lang.String,
+ * java.lang.String, org.osgi.service.http.HttpContext)
+ */
+ public void registerResources(final String alias, final String name,
+ final HttpContext context) throws NamespaceException
+ {
+ synchronized (m_servletMap)
+ {
+ if (m_servletMap.containsKey(alias))
+ {
+ throw new NamespaceException("Alias " + alias
+ + " has already been registered.");
+ }
+ }
+
+ if (context == null)
+ {
+ m_servletMap.put(alias, new ServiceRegistration(alias, name,
+ createDefaultHttpContext(), m_logger));
+ }
+ else
+ {
+ m_servletMap.put(alias, new ServiceRegistration(alias, name, context,
+ m_logger));
+ }
+
+ m_logger.log(Logger.LOG_DEBUG, "Registered resource for alias: " + alias);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.http.HttpService#unregister(java.lang.String)
+ */
+ public void unregister(String alias)
+ {
+ ServiceRegistration reg = null;
+ synchronized (m_servletMap)
+ {
+ reg = (ServiceRegistration) m_servletMap.get(alias);
+ if (reg != null)
+ {
+ m_servletMap.remove(alias);
+ m_logger.log(Logger.LOG_DEBUG, "Unregistered resource for alias: "
+ + alias);
+ }
+ }
+
+ if (reg != null && reg.isServlet() && reg.hasBeenInitialized())
+ {
+ reg.getServlet().destroy();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.http.HttpService#createDefaultHttpContext()
+ */
+ public HttpContext createDefaultHttpContext()
+ {
+ return new DefaultContextImpl(m_bundle);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.service.http.HttpService#registerServlet(java.lang.String,
+ * javax.servlet.Servlet, java.util.Dictionary,
+ * org.osgi.service.http.HttpContext)
+ */
+ public void registerServlet(final String alias, final Servlet servlet,
+ final Dictionary initparams, final HttpContext context) throws ServletException,
+ NamespaceException
+ {
+ if (m_servletMap.containsKey(alias))
+ {
+ throw new NamespaceException("Alias " + alias
+ + " has already been registered.");
+ }
+
+ if (context == null)
+ {
+ m_servletMap.put(alias, new ServiceRegistration(alias, servlet, initparams,
+ new DefaultContextImpl(m_bundle), m_logger));
+ }
+ else
+ {
+ m_servletMap.put(alias, new ServiceRegistration(alias, servlet, initparams,
+ context, m_logger));
+ }
+
+ m_logger.log(Logger.LOG_DEBUG, "Registered servlet for alias: " + alias);
+ }
+
+ /**
+ * Start the HTTP server.
+ *
+ * @throws IOException on I/O error
+ */
+ protected final void start() throws IOException
+ {
+ if (m_server.getState() != Server.INACTIVE_STATE)
+ {
+ throw new IllegalStateException("Attempted to start already-running server.");
+ }
+
+ m_server.start(this);
+ }
+
+ /**
+ * Stop the HTTP server
+ *
+ * @throws InterruptedException on thread interruption.
+ */
+ protected final void stop() throws InterruptedException
+ {
+ if (m_server.getState() != Server.ACTIVE_STATE)
+ {
+ throw new IllegalStateException("Attempted to stop an inactive server.");
+ }
+
+ for (Iterator i = m_servletMap.values().iterator(); i.hasNext();)
+ {
+ ServiceRegistration sr = (ServiceRegistration) i.next();
+
+ try
+ {
+ m_logger.log(Logger.LOG_DEBUG, "Cleaning up servlet " + sr.getAlias());
+ sr.getServlet().destroy();
+ }
+ catch (Exception e)
+ {
+ m_logger.log(Logger.LOG_ERROR,
+ "Servlet threw exception during destroy(): " + sr.getAlias());
+ }
+ }
+
+ m_server.stop();
+ }
+
+ /**
+ * Iterate through all service registrations and return the registration
+ * which matches the longest alias, or null if no matches are found.
+ *
+ * TODO: consider caching if a lot of time is spent resolving registrations.
+ *
+ * @param requestPath the URI of the request
+ * @return the service registration with the deepest match to the request
+ * path.
+ */
+ public final ServiceRegistration getServiceRegistration(final String requestPath)
+ {
+ ServiceRegistration sr = null;
+ int maxLength = 0;
+ synchronized (m_servletMap)
+ {
+ for (Iterator i = m_servletMap.keySet().iterator(); i.hasNext();)
+ {
+ String alias = (String) i.next();
+
+ if (requestPath.startsWith(alias))
+ {
+ if (sr == null)
+ {
+ sr = (ServiceRegistration) m_servletMap.get(alias);
+ maxLength = alias.length();
+ }
+ else if (alias.length() > maxLength)
+ {
+ sr = (ServiceRegistration) m_servletMap.get(alias);
+ maxLength = alias.length();
+ }
+ }
+ }
+ }
+
+ return sr;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.felix.http.lightweight.osgi.RegistrationResolver#getProcessor
+ * (org.apache.felix.http.lightweight.http.HttpRequest,
+ * org.apache.felix.http.lightweight.http.HttpResponse, java.lang.String)
+ */
+ public ServiceRegistrationHandler getProcessor(final HttpServletRequestImpl request,
+ final HttpServletResponseImpl response, final String requestPath)
+ {
+ ServiceRegistration element = getServiceRegistration(requestPath);
+
+ if (element != null)
+ {
+ if (element.isServlet())
+ {
+ return new ServletHandler(request, response, element, m_logger);
+ }
+ else
+ {
+ return new ResourceHandler(request, response, element);
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.felix.http.lightweight.osgi.ServiceRegistrationResolver#
+ * getServletRequest(java.net.Socket)
+ */
+ public HttpServletRequestImpl getServletRequest(final Socket socket)
+ {
+ return new HttpServletRequestImpl(socket, this, m_logger);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.felix.http.lightweight.osgi.ServiceRegistrationResolver#
+ * getServletResponse(org.apache.felix.http.lightweight.servlet.HttpRequest,
+ * java.io.OutputStream)
+ */
+ public HttpServletResponseImpl getServletResponse(final OutputStream output)
+ {
+ return new HttpServletResponseImpl(output);
+ }
+
+}
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Logger.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Logger.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/Logger.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,315 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * <p>
+ * This class mimics the standard OSGi <tt>LogService</tt> interface. An
+ * instance of this class is used by the framework for all logging. By default
+ * this class logs messages to standard out. The log level can be set to
+ * control the amount of logging performed, where a higher number results in
+ * more logging. A log level of zero turns off logging completely.
+ * </p>
+ * <p>
+ * The log levels match those specified in the OSGi Log Service (i.e., 1 = error,
+ * 2 = warning, 3 = information, and 4 = debug). The default value is 1.
+ * </p>
+ * <p>
+ * This class also uses the System Bundle's context to track log services
+ * and will use the highest ranking log service, if present, as a back end
+ * instead of printing to standard out. The class uses reflection to invoking
+ * the log service's method to avoid a dependency on the log interface.
+ * </p>
+**/
+public class Logger implements ServiceListener
+{
+ public static final int LOG_ERROR = 1;
+ public static final int LOG_WARNING = 2;
+ public static final int LOG_INFO = 3;
+ public static final int LOG_DEBUG = 4;
+
+ private int m_logLevel = 1;
+ private BundleContext m_context = null;
+
+ private final static int LOGGER_OBJECT_IDX = 0;
+ private final static int LOGGER_METHOD_IDX = 1;
+ private ServiceReference m_logRef = null;
+ private Object[] m_logger = null;
+
+ public Logger()
+ {
+ }
+
+ public final synchronized void setLogLevel(int i)
+ {
+ m_logLevel = i;
+ }
+
+ public final synchronized int getLogLevel()
+ {
+ return m_logLevel;
+ }
+
+ protected void setSystemBundleContext(BundleContext context)
+ {
+ m_context = context;
+ startListeningForLogService();
+ }
+
+ public final void log(int level, String msg)
+ {
+ _log(null, null, level, msg, null);
+ }
+
+ public final void log(int level, String msg, Throwable throwable)
+ {
+ _log(null, null, level, msg, throwable);
+ }
+
+ public final void log(ServiceReference sr, int level, String msg)
+ {
+ _log(null, sr, level, msg, null);
+ }
+
+ public final void log(ServiceReference sr, int level, String msg, Throwable throwable)
+ {
+ _log(null, sr, level, msg, throwable);
+ }
+
+ public final void log(Bundle bundle, int level, String msg)
+ {
+ _log(bundle, null, level, msg, null);
+ }
+
+ public final void log(Bundle bundle, int level, String msg, Throwable throwable)
+ {
+ _log(bundle, null, level, msg, throwable);
+ }
+
+ protected void doLog(Bundle bundle, ServiceReference sr, int level, String msg,
+ Throwable throwable)
+ {
+ String s = "";
+ if (sr != null)
+ {
+ s = s + "SvcRef " + sr + " ";
+ }
+ else if (bundle != null)
+ {
+ s = s + "Bundle " + bundle.toString() + " ";
+ }
+ s = s + msg;
+ if (throwable != null)
+ {
+ s = s + " (" + throwable + ")";
+ }
+ switch (level)
+ {
+ case LOG_DEBUG:
+ System.out.println("DEBUG: " + s);
+ break;
+ case LOG_ERROR:
+ System.out.println("ERROR: " + s);
+ if (throwable != null)
+ {
+ if ((throwable instanceof BundleException)
+ && (((BundleException) throwable).getNestedException() != null))
+ {
+ throwable = ((BundleException) throwable).getNestedException();
+ }
+ throwable.printStackTrace();
+ }
+ break;
+ case LOG_INFO:
+ System.out.println("INFO: " + s);
+ break;
+ case LOG_WARNING:
+ System.out.println("WARNING: " + s);
+ break;
+ default:
+ System.out.println(s);
+ }
+ }
+
+ private void _log(Bundle bundle, ServiceReference sr, int level, String msg,
+ Throwable throwable)
+ {
+ // Save our own copy just in case it changes. We could try to do
+ // more conservative locking here, but let's be optimistic.
+ Object[] logger = m_logger;
+
+ if (m_logLevel >= level)
+ {
+ // Use the log service if available.
+ if (logger != null)
+ {
+ _logReflectively(logger, sr, level, msg, throwable);
+ }
+ // Otherwise, default logging action.
+ else
+ {
+ doLog(bundle, sr, level, msg, throwable);
+ }
+ }
+ }
+
+ private void _logReflectively(Object[] logger, ServiceReference sr, int level,
+ String msg, Throwable throwable)
+ {
+ if (logger != null)
+ {
+ Object[] params = { sr, new Integer(level), msg, throwable };
+ try
+ {
+ ((Method) logger[LOGGER_METHOD_IDX]).invoke(logger[LOGGER_OBJECT_IDX],
+ params);
+ }
+ catch (InvocationTargetException ex)
+ {
+ System.err.println("Logger: " + ex);
+ }
+ catch (IllegalAccessException ex)
+ {
+ System.err.println("Logger: " + ex);
+ }
+ }
+ }
+
+ /**
+ * This method is called when the system bundle context is set;
+ * it simply adds a service listener so that the system bundle can track
+ * log services to be used as the back end of the logging mechanism. It also
+ * attempts to get an existing log service, if present, but in general
+ * there will never be a log service present since the system bundle is
+ * started before every other bundle.
+ **/
+ private synchronized void startListeningForLogService()
+ {
+ // Add a service listener for log services.
+ try
+ {
+ m_context.addServiceListener(this,
+ "(objectClass=org.osgi.service.log.LogService)");
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // This will never happen since the filter is hard coded.
+ }
+ // Try to get an existing log service.
+ m_logRef = m_context.getServiceReference("org.osgi.service.log.LogService");
+ // Get the service object if available and set it in the logger.
+ if (m_logRef != null)
+ {
+ setLogger(m_context.getService(m_logRef));
+ }
+ }
+
+ /**
+ * This method implements the callback for the ServiceListener interface.
+ * It is public as a byproduct of implementing the interface and should
+ * not be called directly. This method tracks run-time changes to log
+ * service availability. If the log service being used by the framework's
+ * logging mechanism goes away, then this will try to find an alternative.
+ * If a higher ranking log service is registered, then this will switch
+ * to the higher ranking log service.
+ **/
+ public final synchronized void serviceChanged(ServiceEvent event)
+ {
+ // If no logger is in use, then grab this one.
+ if ((event.getType() == ServiceEvent.REGISTERED) && (m_logRef == null))
+ {
+ m_logRef = event.getServiceReference();
+ // Get the service object and set it in the logger.
+ setLogger(m_context.getService(m_logRef));
+ }
+ // If a logger is in use, but this one has a higher ranking, then swap
+ // it for the existing logger.
+ else if ((event.getType() == ServiceEvent.REGISTERED) && (m_logRef != null))
+ {
+ ServiceReference ref = m_context.getServiceReference("org.osgi.service.log.LogService");
+ if (!ref.equals(m_logRef))
+ {
+ m_context.ungetService(m_logRef);
+ m_logRef = ref;
+ setLogger(m_context.getService(m_logRef));
+ }
+
+ }
+ // If the current logger is going away, release it and try to
+ // find another one.
+ else if ((event.getType() == ServiceEvent.UNREGISTERING)
+ && m_logRef.equals(event.getServiceReference()))
+ {
+ // Unget the service object.
+ m_context.ungetService(m_logRef);
+ // Try to get an existing log service.
+ m_logRef = m_context.getServiceReference("org.osgi.service.log.LogService");
+ // Get the service object if available and set it in the logger.
+ if (m_logRef != null)
+ {
+ setLogger(m_context.getService(m_logRef));
+ }
+ else
+ {
+ setLogger(null);
+ }
+ }
+ }
+
+ /**
+ * This method sets the new log service object. It also caches the method to
+ * invoke. The service object and method are stored in array to optimistically
+ * eliminate the need to locking when logging.
+ **/
+ private void setLogger(Object logObj)
+ {
+ if (logObj == null)
+ {
+ m_logger = null;
+ }
+ else
+ {
+ Class[] formalParams = { ServiceReference.class, Integer.TYPE, String.class,
+ Throwable.class };
+
+ try
+ {
+ Method logMethod = logObj.getClass().getMethod("log", formalParams);
+ logMethod.setAccessible(true);
+ m_logger = new Object[] { logObj, logMethod };
+ }
+ catch (NoSuchMethodException ex)
+ {
+ System.err.println("Logger: " + ex);
+ m_logger = null;
+ }
+ }
+ }
+}
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistration.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistration.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistration.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistration.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,190 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.util.Dictionary;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+
+import org.apache.felix.http.lightweight.servlet.ServletConfigImpl;
+import org.apache.felix.http.lightweight.servlet.ServletContextImpl;
+import org.osgi.service.http.HttpContext;
+
+/**
+ * This class stores the state from a client that registered a Servlet
+ * or resource with the HTTP Service.
+ */
+public class ServiceRegistration
+{
+ /**
+ * Servlet instance
+ */
+ private final Servlet m_servlet;
+ /**
+ * Dictionary of parameters
+ */
+ private final Dictionary m_initparams;
+ /**
+ * Reference to HttpContext
+ */
+ private final HttpContext m_context;
+ /**
+ * Alias
+ */
+ private final String m_alias;
+ /**
+ * Logger instance
+ */
+ private final Logger m_logger;
+ /**
+ * true if the servlet has been initialized. This should happen on the first request only.
+ */
+ private boolean m_initialized;
+ /**
+ * Servlet instance
+ */
+ private boolean m_isServlet;
+ /**
+ * Name of registration
+ */
+ private final String m_name;
+ private ServletConfigImpl m_servletConfigImpl;
+
+ /**
+ * @param alias Alias that the service is registered with.
+ * @param servlet Instance of servlet corresponding to alias.
+ * @param initparams initial configuration parameters
+ * @param context HTTP context
+ * @param logger Logger instance
+ */
+ public ServiceRegistration(final String alias, final Servlet servlet, final Dictionary initparams, final HttpContext context, final Logger logger)
+ {
+ this.m_alias = alias;
+ this.m_name = null;
+ this.m_servlet = servlet;
+ this.m_initparams = initparams;
+ this.m_context = context;
+ this.m_logger = logger;
+ this.m_initialized = false;
+ this.m_isServlet = true;
+ }
+
+ /**
+ * @param alias Alias that the service is registered with.
+ * @param name name of the resource
+ * @param context HTTP context
+ * @param logger Logger instance
+ */
+ public ServiceRegistration(final String alias, final String name, final HttpContext context, final Logger logger)
+ {
+ this.m_alias = alias;
+ this.m_name = name;
+ this.m_logger = logger;
+ this.m_servlet = null;
+ this.m_initparams = null;
+ this.m_context = context;
+ this.m_isServlet = false;
+ }
+
+ /**
+ * @return true if this registration represents a servlet, false for a resource.
+ */
+ public final boolean isServlet()
+ {
+ return m_isServlet;
+ }
+
+ /**
+ * @return Alias of resource
+ */
+ public final String getAlias()
+ {
+ return m_alias;
+ }
+
+ /**
+ * @return Name of resource
+ */
+ public final String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * @return true if the init() method has been called
+ * on the Servlet at some point in the past, false otherwise.
+ */
+ public final boolean hasBeenInitialized()
+ {
+ return m_initialized;
+ }
+
+ /**
+ * Set the initialized flat to true. Will throw
+ * IllegalStateException() if called multiple times on the same instance.
+ */
+ public final void setInitialized()
+ {
+ if (m_initialized)
+ {
+ throw new IllegalStateException("Servlet has already been initialized.");
+ }
+
+ m_initialized = true;
+ }
+
+ /**
+ * @return the Servlet instance.
+ */
+ public final Servlet getServlet()
+ {
+ return m_servlet;
+ }
+
+ /**
+ * @return Dictionary of init params.
+ */
+ public final Dictionary getInitparams()
+ {
+ return m_initparams;
+ }
+
+ /**
+ * @return HttpContext
+ */
+ public final HttpContext getContext()
+ {
+ return m_context;
+ }
+
+ /**
+ * @return the ServletConfig for this servlet.
+ */
+ public final ServletConfig getServletConfig()
+ {
+ if (m_servletConfigImpl == null)
+ {
+ m_servletConfigImpl = new ServletConfigImpl(m_alias, m_initparams,
+ new ServletContextImpl(m_alias, m_context, m_initparams, m_logger));
+ }
+
+ return m_servletConfigImpl;
+ }
+}
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationHandler.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationHandler.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationHandler.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,39 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+/**
+ * Represents either a Resource or a Servlet that should be processed
+ * with a valid client connection provided by the server.
+ *
+ */
+public interface ServiceRegistrationHandler
+{
+ /**
+ * Process the request against the registered provider.
+ *
+ * @throws IOException on I/O error
+ * @throws ServletException on Servlet error
+ */
+ void handle(boolean closeConnection) throws IOException, ServletException;
+}
Added: felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationResolver.java
URL: http://svn.apache.org/viewvc/felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationResolver.java?rev=1182650&view=auto
==============================================================================
--- felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationResolver.java (added)
+++ felix/trunk/httplite/src/main/java/org/apache/felix/http/lightweight/osgi/ServiceRegistrationResolver.java Thu Oct 13 05:01:42 2011
@@ -0,0 +1,69 @@
+/*
+ * 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.lightweight.osgi;
+
+import java.io.OutputStream;
+import java.net.Socket;
+
+import org.apache.felix.http.lightweight.servlet.HttpServletRequestImpl;
+import org.apache.felix.http.lightweight.servlet.HttpServletResponseImpl;
+
+/**
+ * An interface to provide internal classes with access to client service registration state.
+ * This interface serves as the connection between the internal server and the HTTP Service.
+ *
+ */
+public interface ServiceRegistrationResolver
+{
+ /**
+ * Given a socket connection return a HttpServletRequestImpl.
+ *
+ * @param socket socket connection to be associated with HTTP Request
+ * @return HttpServletRequestImpl instance
+ */
+ HttpServletRequestImpl getServletRequest(Socket socket);
+
+ /**
+ * Resolve the requestPath to a Resource or Servlet registration with the closest (deepest) match.
+ *
+ * @param requestPath URI of request
+ * @return A ServiceRegistration or null if no match was found.
+ */
+ ServiceRegistration getServiceRegistration(String requestPath);
+
+ /**
+ * Given a HttpRequest and an output stream, return a HttpServletResponseImpl.
+ *
+ * @param request HttpRequest
+ * @param output output stream associated with socket connection.
+ * @return A HttpServletResponseImpl instance
+ */
+ HttpServletResponseImpl getServletResponse(OutputStream output);
+
+ /**
+ * For a request, response, and requestPath, return a ServiceRegistrationHandler.
+ *
+ * @param request HttpRequest
+ * @param response HttpResponse
+ * @param requestPath The request URI
+ * @return A ServiceRegistrationHandler corresponding to the requestPath, or null if no match.
+ */
+ ServiceRegistrationHandler getProcessor(HttpServletRequestImpl request,
+ HttpServletResponseImpl response, String requestPath);
+}