tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r400232 - in /incubator/tuscany/java/sca/tomcat/src: main/java/org/apache/tuscany/tomcat/ test/java/org/apache/tuscany/tomcat/integration/
Date Sat, 06 May 2006 04:00:25 GMT
Author: jboynes
Date: Fri May  5 21:00:23 2006
New Revision: 400232

URL: http://svn.apache.org/viewcvs?rev=400232&view=rev
Log:
support direct mapping of servlets for entry points

Added:
    incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java
  (with props)
Modified:
    incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TomcatHost.java
    incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java
    incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/AbstractTomcatTest.java
    incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/TomcatIntegrationTestCase.java

Modified: incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TomcatHost.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TomcatHost.java?rev=400232&r1=400231&r2=400232&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TomcatHost.java
(original)
+++ incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TomcatHost.java
Fri May  5 21:00:23 2006
@@ -16,23 +16,34 @@
  */
 package org.apache.tuscany.tomcat;
 
-import org.apache.catalina.Host;
+import javax.servlet.Servlet;
+
 import org.osoa.sca.annotations.Scope;
 
+import org.apache.tuscany.core.webapp.ServletHost;
+
 /**
  * SCA Component that acts as a proxy for the Tomcat Host container that created the runtime.
  *
  * @version $Rev$ $Date$
  */
 @Scope("MODULE")
-public class TomcatHost {
-    private Host host;
+public class TomcatHost implements ServletHost {
+    private TuscanyHost host;
 
-    public void setHost(Host host) {
+    public void setHost(TuscanyHost host) {
         this.host = host;
     }
 
-    public Host getHost() {
+    public TuscanyHost getHost() {
         return host;
+    }
+
+    public void registerMapping(String mapping, Servlet servlet) {
+        host.registerMapping(mapping, servlet);
+    }
+
+    public void unregisterMapping(String mapping) {
+        host.unregisterMapping(mapping);
     }
 }

Modified: incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java?rev=400232&r1=400231&r2=400232&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java
(original)
+++ incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyHost.java
Fri May  5 21:00:23 2006
@@ -19,7 +19,9 @@
 import javax.servlet.Servlet;
 
 import org.apache.catalina.Container;
+import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleException;
+import org.apache.catalina.Wrapper;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.core.StandardHost;
 import org.apache.catalina.util.StringManager;
@@ -137,6 +139,18 @@
     }
 
     public void registerMapping(String mapping, Servlet servlet) {
+        // strip leading "/" as Tomcat uses host-relative context names
+        if (mapping.charAt(0) == '/') {
+            mapping = mapping.substring(1);
+        }
+        Context ctx = map(mapping);
+        if (ctx == null) {
+            throw new UnsupportedOperationException("Cannot find context for mapping " +
mapping);
+        }
+        Wrapper wrapper = new TuscanyWrapper(servlet);
+        ctx.addChild(wrapper);
+        wrapper.addMapping(mapping);
+        ctx.getMapper().addWrapper(mapping, wrapper, false);
     }
 
     public void unregisterMapping(String mapping) {

Added: incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java?rev=400232&view=auto
==============================================================================
--- incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java
(added)
+++ incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java
Fri May  5 21:00:23 2006
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.apache.tuscany.tomcat;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.catalina.core.StandardWrapper;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyWrapper extends StandardWrapper {
+    private final Servlet servlet;
+
+    public TuscanyWrapper(Servlet servlet) {
+        super();
+        this.servlet = servlet;
+    }
+
+    public synchronized Servlet loadServlet() throws ServletException {
+        return servlet;
+    }
+}

Propchange: incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/tomcat/src/main/java/org/apache/tuscany/tomcat/TuscanyWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Modified: incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/AbstractTomcatTest.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/AbstractTomcatTest.java?rev=400232&r1=400231&r2=400232&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/AbstractTomcatTest.java
(original)
+++ incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/AbstractTomcatTest.java
Fri May  5 21:00:23 2006
@@ -40,6 +40,8 @@
 import org.apache.catalina.core.ApplicationFilterFactory;
 import org.apache.catalina.core.StandardEngine;
 
+import org.apache.tuscany.tomcat.TuscanyHost;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -173,27 +175,27 @@
 
         @Override
         public String getRemoteHost() {
-           
+
             return "locahost";
         }
 
         @Override
         public int getRemotePort() {
-           
+
             return 1080;
         }
 
         @Override
         public String getRemoteAddr() {
-          
+
             return "127.0.0.1";
         }
-        
+
         @Override
         public Enumeration getParameterNames() {
             return new Vector().elements();
         }
-        
+
         @Override
         public String getParameter(String param) {
             if ("wsdl".equals(param)) {

Modified: incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/TomcatIntegrationTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/TomcatIntegrationTestCase.java?rev=400232&r1=400231&r2=400232&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/TomcatIntegrationTestCase.java
(original)
+++ incubator/tuscany/java/sca/tomcat/src/test/java/org/apache/tuscany/tomcat/integration/TomcatIntegrationTestCase.java
Fri May  5 21:00:23 2006
@@ -22,11 +22,20 @@
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.core.StandardWrapper;
 import org.apache.catalina.startup.ContextConfig;
+import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.http.mapper.MappingData;
+
 import org.apache.tuscany.tomcat.TuscanyHost;
 import org.apache.tuscany.tomcat.TuscanyValve;
 import org.apache.tuscany.tomcat.ContainerLoader;
 
 import java.io.File;
+import java.io.IOException;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
 
 /**
  * @version $Rev$ $Date$
@@ -34,15 +43,9 @@
 public class TomcatIntegrationTestCase extends AbstractTomcatTest {
     protected File app1;
     private Loader loader;
+    private StandardContext ctx;
 
     public void testComponentIntegration() throws Exception {
-        // create the webapp Context
-        StandardContext ctx = new StandardContext();
-        ctx.addLifecycleListener(new ContextConfig());
-        ctx.setName("testContext");
-        ctx.setDocBase(app1.getAbsolutePath());
-        ctx.setLoader(loader);
-
         // define our test servlet
         StandardWrapper wrapper = new StandardWrapper();
         wrapper.setServletClass(TestServlet.class.getName());
@@ -66,13 +69,6 @@
     }
 
     public void testWebServiceIntegration() throws Exception {
-        // create the webapp Context
-        StandardContext ctx = new StandardContext();
-        ctx.addLifecycleListener(new ContextConfig());
-        ctx.setName("testContext");
-        ctx.setDocBase(app1.getAbsolutePath());
-        ctx.setLoader(loader);
-
         host.addChild(ctx);
 
         Wrapper wrapper = (Wrapper) ctx.findChild("TuscanyAxis2EntryPointServlet");
@@ -103,15 +99,6 @@
      * Test ?WSDL works
      */
     public void testWebServiceIntegrationWSDL() throws Exception {
-//        // create the webapp Context
-//        StandardContext ctx = new StandardContext();
-//        ctx.addLifecycleListener(new ContextConfig());
-//        ctx.setName("testContext");
-//        ctx.setDocBase(app1.getAbsolutePath());
-//        ctx.setLoader(loader);
-//
-//        host.addChild(ctx);
-//
 //        Wrapper wrapper = (Wrapper) ctx.findChild("TuscanyAxis2EntryPointServlet");
 //        assertNotNull("No webservice wrapper present", wrapper);
 //        request.setContext(ctx);
@@ -130,6 +117,19 @@
 //        host.removeChild(ctx);
     }
 
+    public void testServletMapping() throws Exception {
+        host.addChild(ctx);
+
+        ((TuscanyHost)host).registerMapping("testContext/magicServlet", new MockServlet());
+        assertSame(ctx, host.map("testContext/magicServlet"));
+        MessageBytes uri = MessageBytes.newInstance();
+        uri.setString("testContext/magicServlet");
+        MappingData mappingData = new MappingData();
+        ctx.getMapper().map(uri, mappingData);
+        assertEquals("/magicServlet", mappingData.requestPath.getString());
+        host.removeChild(ctx);
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         app1 = new File(getClass().getResource("/app1").toURI());
@@ -140,6 +140,13 @@
         TestClassLoader cl = new TestClassLoader(classes, new File(app1, "WEB-INF/classes").toURL(),
getClass().getClassLoader());
         cl.start();
         loader = new ContainerLoader(cl);
+
+        // create the webapp Context
+        ctx = new StandardContext();
+        ctx.addLifecycleListener(new ContextConfig());
+        ctx.setName("testContext");
+        ctx.setDocBase(app1.getAbsolutePath());
+        ctx.setLoader(loader);
     }
 
     protected void tearDown() throws Exception {
@@ -147,4 +154,24 @@
         super.tearDown();
     }
 
+    public static class MockServlet implements Servlet {
+        public void init(ServletConfig servletConfig) throws ServletException {
+            throw new UnsupportedOperationException();
+        }
+
+        public ServletConfig getServletConfig() {
+            throw new UnsupportedOperationException();
+        }
+
+        public void service(ServletRequest servletRequest, ServletResponse servletResponse)
throws ServletException, IOException {
+        }
+
+        public String getServletInfo() {
+            throw new UnsupportedOperationException();
+        }
+
+        public void destroy() {
+            throw new UnsupportedOperationException();
+        }
+    }
 }



Mime
View raw message