You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2006/08/19 11:38:08 UTC

svn commit: r432820 - /incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java

Author: antelder
Date: Sat Aug 19 02:38:08 2006
New Revision: 432820

URL: http://svn.apache.org/viewvc?rev=432820&view=rev
Log:
Add a ServletHost impl. 
Enables Tuscany bindings to register servlets which receive servlet request from the Tuscany servlet for  

Added:
    incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java   (with props)

Added: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java?rev=432820&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java (added)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java Sat Aug 19 02:38:08 2006
@@ -0,0 +1,68 @@
+/*
+ * 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.tuscany.core.launcher;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * ServletHost impl that forwards requests to registered servlets
+ * TODO: TUSCANY-649, move this and ServletLauncherListener to a new webapp-host module
+ */
+@Scope("MODULE")
+public class ServletHostImpl implements ServletHost, ServletRequestInjector {
+
+    protected Map<String, Servlet> servlets;
+
+    public ServletHostImpl() {
+        this.servlets = new HashMap<String, Servlet>();
+    }
+
+    public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
+        String path = ((HttpServletRequest) req).getPathInfo();
+        Servlet servlet = servlets.get(path);
+        if (servlet == null) {
+            throw new IllegalStateException("no servlet registered for path: " + path);
+        }
+        servlet.service(req, resp);
+    }
+
+    public void registerMapping(String path, Servlet servlet) {
+        if (servlets.containsKey(path)) {
+            throw new IllegalStateException("servlet already registered at path: " + path);
+        }
+        servlets.put(path, servlet);
+    }
+
+    public void unregisterMapping(String path) {
+        servlets.remove(path);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/launcher/ServletHostImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org