Initial attempt at moving over Oscar's Jetty-based HTTP Service implementation
(FELIX-9).
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@395268 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiServletHandler.java b/org.apache.felix.http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiServletHandler.java
new file mode 100644
index 0000000..a3528b4
--- /dev/null
+++ b/org.apache.felix.http.jetty/src/main/java/org/mortbay/jetty/servlet/OsgiServletHandler.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * 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.
+ *
+ */
+package org.mortbay.jetty.servlet;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.mortbay.http.PathMap;
+import org.mortbay.util.Code;
+
+
+public class OsgiServletHandler
+ extends ServletHandler
+{
+ protected org.osgi.service.http.HttpContext m_osgiHttpContext;
+
+
+ public OsgiServletHandler(
+ org.osgi.service.http.HttpContext osgiHttpContext)
+ {
+ m_osgiHttpContext = osgiHttpContext;
+ }
+
+
+ // allow external adding of osgi servlet holder
+ public void addOsgiServletHolder(String pathSpec, ServletHolder holder)
+ {
+ super.addServletHolder(pathSpec, holder);
+ }
+
+
+ public OsgiServletHolder removeOsgiServletHolder(String pathSpec)
+ {
+ OsgiServletHolder holder = (OsgiServletHolder)
+ super.getServletHolder(pathSpec);
+ PathMap map = super.getServletMap();
+ map.remove(pathSpec);
+
+ // Remove holder from handler name map to allow re-registration.
+ super._nameMap.remove(holder.getName());
+
+ return holder;
+ }
+
+
+ // override standard handler behaviour to return resource from OSGi
+ // HttpContext
+ public URL getResource(String uriInContext)
+ throws MalformedURLException
+ {
+ Code.debug("OSGI ServletHandler getResource:" + uriInContext);
+ return m_osgiHttpContext.getResource(uriInContext);
+ }
+
+ // override standard behaviour to check context first
+ protected void dispatch(String pathInContext,
+ HttpServletRequest request,
+ HttpServletResponse response,
+ ServletHolder servletHolder)
+ throws ServletException,
+ UnavailableException,
+ IOException
+ {
+ Code.debug("dispatch path = " + pathInContext);
+ if (m_osgiHttpContext.handleSecurity(request, response))
+ {
+ // service request
+ servletHolder.handle(request,response);
+ }
+ else
+ {
+ //TODO: any other error/auth handling we should do in here?
+ response.flushBuffer();
+ }
+ }
+}
+
+