Author: rfeng
Date: Tue Oct  6 16:55:15 2009
New Revision: 822343

URL: http://svn.apache.org/viewvc?rev=822343&view=rev
Log:
Enable lazy loading of ServletHost extensions

Added:
    
tuscany/java/sca/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHost
Removed:
    
tuscany/java/sca/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyRuntimeModuleActivator.java
    
tuscany/java/sca/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
    
tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java
    
tuscany/java/sca/modules/host-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
Modified:
    tuscany/java/sca/modules/host-http/META-INF/MANIFEST.MF
    
tuscany/java/sca/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
    
tuscany/java/sca/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java
    
tuscany/java/sca/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java
    
tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java

Modified: tuscany/java/sca/modules/host-http/META-INF/MANIFEST.MF
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-http/META-INF/MANIFEST.MF?rev=822343&r1=822342&r2=822343&view=diff
==============================================================================
--- tuscany/java/sca/modules/host-http/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/host-http/META-INF/MANIFEST.MF Tue Oct  6 16:55:15 
2009
@@ -11,8 +11,11 @@
 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
 Bundle-Description: Apache Tuscany SCA HTTP Servlet Host Extension Poi
  nt
-Import-Package: javax.servlet,javax.servlet.http,org.apache.tuscany.sc
- a.host.http;version="2.0.0"
+Import-Package: javax.servlet,
+ javax.servlet.http,
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
+ org.apache.tuscany.sca.host.http;version="2.0.0"
 Bundle-SymbolicName: org.apache.tuscany.sca.host.http
 Bundle-DocURL: http://www.apache.org/
 Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6

Modified: 
tuscany/java/sca/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java?rev=822343&r1=822342&r2=822343&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
 (original)
+++ 
tuscany/java/sca/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java
 Tue Oct  6 16:55:15 2009
@@ -19,27 +19,176 @@
 
 package org.apache.tuscany.sca.host.http;
 
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.LifeCycleListener;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
 /**
  * Default implementation of a Servlet host extension point.
  * 
  * @version $Rev$ $Date$
  */
-public class DefaultServletHostExtensionPoint implements 
ServletHostExtensionPoint {
+public class DefaultServletHostExtensionPoint implements 
ServletHostExtensionPoint, LifeCycleListener {
 
     private List<ServletHost> servletHosts = new ArrayList<ServletHost>();
+    private boolean loaded;
+
+    private ExtensionPointRegistry registry;
+
+    public DefaultServletHostExtensionPoint(ExtensionPointRegistry registry) {
+        this.registry = registry;
+    }
 
     public void addServletHost(ServletHost servletHost) {
         servletHosts.add(servletHost);
+        if (servletHost instanceof LifeCycleListener) {
+            ((LifeCycleListener)servletHost).start();
+        }
     }
 
     public void removeServletHost(ServletHost servletHost) {
         servletHosts.remove(servletHost);
+        if (servletHost instanceof LifeCycleListener) {
+            ((LifeCycleListener)servletHost).stop();
+        }
     }
 
     public List<ServletHost> getServletHosts() {
+        loadServletHosts();
         return servletHosts;
     }
+
+    private synchronized void loadServletHosts() {
+        if (loaded)
+            return;
+
+        // Get the databinding service declarations
+        Collection<ServiceDeclaration> sds;
+        try {
+            sds = 
ServiceDiscovery.getInstance().getServiceDeclarations(ServletHost.class, true);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+
+        // Load data bindings
+        for (ServiceDeclaration sd : sds) {
+            // Create a data binding wrapper and register it
+            ServletHost servletHost = new LazyServletHost(sd);
+            addServletHost(servletHost);
+        }
+
+        loaded = true;
+    }
+
+    /**
+     * A data binding facade allowing data bindings to be lazily loaded and
+     * initialized.
+     */
+    private class LazyServletHost implements ServletHost, LifeCycleListener {
+        private ServiceDeclaration sd;
+        private ServletHost host;
+
+        /**
+         * @param sd
+         */
+        public LazyServletHost(ServiceDeclaration sd) {
+            super();
+            this.sd = sd;
+        }
+
+        private synchronized ServletHost getServletHost() {
+            if (host == null) {
+                try {
+                    Class<?> cls = sd.loadClass();
+                    Constructor<?> ctor = null;
+                    try {
+                        ctor = 
cls.getConstructor(ExtensionPointRegistry.class);
+                        host = (ServletHost)ctor.newInstance(registry);
+                    } catch (NoSuchMethodException e) {
+                        ctor = cls.getConstructor();
+                        host = (ServletHost)ctor.newInstance();
+                    }
+                    if(host instanceof LifeCycleListener) {
+                        ((LifeCycleListener) host).start();
+                    }
+                } catch (Throwable e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+            return host;
+        }
+
+        public void addServletMapping(String uri, Servlet servlet) throws 
ServletMappingException {
+            getServletHost().addServletMapping(uri, servlet);
+        }
+
+        public String getContextPath() {
+            return getServletHost().getContextPath();
+        }
+
+        public int getDefaultPort() {
+            return getServletHost().getDefaultPort();
+        }
+
+        public RequestDispatcher getRequestDispatcher(String uri) throws 
ServletMappingException {
+            return getServletHost().getRequestDispatcher(uri);
+        }
+
+        public Servlet getServletMapping(String uri) throws 
ServletMappingException {
+            return getServletHost().getServletMapping(uri);
+        }
+
+        public URL getURLMapping(String uri) {
+            return getServletHost().getURLMapping(uri);
+        }
+
+        public Servlet removeServletMapping(String uri) throws 
ServletMappingException {
+            return getServletHost().removeServletMapping(uri);
+        }
+
+        public void setAttribute(String name, Object value) {
+            getServletHost().setAttribute(name, value);
+        }
+
+        public void setContextPath(String path) {
+            getServletHost().setContextPath(path);
+        }
+
+        public void setDefaultPort(int port) {
+            getServletHost().setDefaultPort(port);
+        }
+
+        public void start() {
+        }
+
+        public void stop() {
+            if (host instanceof LifeCycleListener) {
+                ((LifeCycleListener)host).stop();
+            }
+        }
+    }
+
+    public void start() {
+    }
+
+    public void stop() {
+        for (ServletHost host : servletHosts) {
+            if (host instanceof LifeCycleListener) {
+                ((LifeCycleListener)host).stop();
+            }
+        }
+        servletHosts.clear();
+        registry = null;
+    }
 }

Modified: 
tuscany/java/sca/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java?rev=822343&r1=822342&r2=822343&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java
 (original)
+++ 
tuscany/java/sca/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java
 Tue Oct  6 16:55:15 2009
@@ -40,6 +40,9 @@
 import javax.servlet.Servlet;
 import javax.servlet.ServletException;
 
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.LifeCycleListener;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 import org.apache.tuscany.sca.host.http.DefaultResourceServlet;
 import org.apache.tuscany.sca.host.http.ServletHost;
 import org.apache.tuscany.sca.host.http.ServletMappingException;
@@ -62,7 +65,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class JettyServer implements ServletHost {
+public class JettyServer implements ServletHost, LifeCycleListener {
     private static final Logger logger = 
Logger.getLogger(JettyServer.class.getName());
 
     private final Object joinLock = new Object();
@@ -74,7 +77,6 @@
     private String keyStoreType;
     private String trustStoreType;
 
-    
     private boolean sendServerVersion;
     private WorkScheduler workScheduler;
     private int defaultPort = portDefault;
@@ -86,7 +88,7 @@
     private class Port {
         private Server server;
         private ServletHandler servletHandler;
-        
+
         private Port(Server server, ServletHandler servletHandler) {
             this.server = server;
             this.servletHandler = servletHandler;
@@ -95,26 +97,23 @@
         public Server getServer() {
             return server;
         }
-        
+
         public ServletHandler getServletHandler() {
             return servletHandler;
         }
     }
-    
+
     private Map<Integer, Port> ports = new HashMap<Integer, Port>();
 
     private String contextPath = "/";
     private org.mortbay.log.Logger jettyLogger;
 
-    public JettyServer(WorkScheduler workScheduler) {
+    public JettyServer(ExtensionPointRegistry registry) {
+        
this(registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(WorkScheduler.class));
+    }
+
+    protected JettyServer(WorkScheduler workScheduler) {
         this.workScheduler = workScheduler;
-        try {
-            jettyLogger = Log.getLog();
-        } catch (Throwable e) {
-            // Ignore
-        } finally {
-            Log.setLog(new JettyLogger());
-        }
         AccessController.doPrivileged(new PrivilegedAction<Object>() {
             public Object run() {
                 trustStore = System.getProperty("javax.net.ssl.trustStore");
@@ -128,11 +127,11 @@
             }
         });
     }
-    
+
     public void setDefaultPort(int port) {
         defaultPort = port;
     }
-    
+
     public int getDefaultPort() {
         return defaultPort;
     }
@@ -150,7 +149,7 @@
         }
         try {
             Set<Entry<Integer, Port>> entries = new HashSet<Entry<Integer, 
Port>>(ports.entrySet());
-            for (Entry<Integer, Port> entry: entries) {
+            for (Entry<Integer, Port> entry : entries) {
                 Port port = entry.getValue();
                 Server server = port.getServer();
                 server.stop();
@@ -166,7 +165,7 @@
             }
         }
     }
-    
+
     private void configureSSL(SslSocketConnector connector) {
         connector.setProtocol("TLS");
         connector.setKeystore(keyStore);
@@ -186,7 +185,7 @@
 
     public void addServletMapping(String suri, Servlet servlet) throws 
ServletMappingException {
         URI uri = URI.create(suri);
-        
+
         // Get the URI scheme and port
         String scheme = uri.getScheme();
         if (scheme == null) {
@@ -206,8 +205,8 @@
                 Server server = new Server();
                 server.setThreadPool(new WorkSchedulerThreadPool());
                 if ("https".equals(scheme)) {
-//                    Connector httpConnector = new SelectChannelConnector();
-//                    httpConnector.setPort(portNumber);
+                    //                    Connector httpConnector = new 
SelectChannelConnector();
+                    //                    httpConnector.setPort(portNumber);
                     SslSocketConnector sslConnector = new SslSocketConnector();
                     sslConnector.setPort(portNumber);
                     configureSSL(sslConnector);
@@ -217,26 +216,26 @@
                     selectConnector.setPort(portNumber);
                     server.setConnectors(new Connector[] {selectConnector});
                 }
-    
+
                 ContextHandler contextHandler = new ContextHandler();
                 //contextHandler.setContextPath(contextPath);
                 contextHandler.setContextPath("/");
                 server.setHandler(contextHandler);
-    
+
                 SessionHandler sessionHandler = new SessionHandler();
                 ServletHandler servletHandler = new ServletHandler();
                 sessionHandler.addHandler(servletHandler);
-    
+
                 contextHandler.setHandler(sessionHandler);
-    
+
                 server.setStopAtShutdown(true);
                 server.setSendServerVersion(sendServerVersion);
                 server.start();
-                
+
                 // Keep track of the new server and Servlet handler 
                 port = new Port(server, servletHandler);
                 ports.put(portNumber, port);
-                
+
             } catch (Exception e) {
                 throw new ServletMappingException(e);
             }
@@ -246,44 +245,44 @@
         ServletHandler servletHandler = port.getServletHandler();
         ServletHolder holder;
         if (servlet instanceof DefaultResourceServlet) {
-            
+
             // Optimize the handling of resource requests, use the Jetty 
default Servlet
             // instead of our default resource Servlet
             String servletPath = uri.getPath();
             if (servletPath.endsWith("*")) {
-                servletPath = servletPath.substring(0, servletPath.length()-1);
+                servletPath = servletPath.substring(0, servletPath.length() - 
1);
             }
             if (servletPath.endsWith("/")) {
-                servletPath = servletPath.substring(0, servletPath.length()-1);
-            }          
+                servletPath = servletPath.substring(0, servletPath.length() - 
1);
+            }
             if (!servletPath.startsWith("/")) {
                 servletPath = '/' + servletPath;
-            }     
-       
+            }
+
             DefaultResourceServlet resourceServlet = 
(DefaultResourceServlet)servlet;
             DefaultServlet defaultServlet = new 
JettyDefaultServlet(servletPath, resourceServlet.getDocumentRoot());
             holder = new ServletHolder(defaultServlet);
-            
+
         } else {
             holder = new ServletHolder(servlet);
         }
         servletHandler.addServlet(holder);
-        
+
         ServletMapping mapping = new ServletMapping();
         mapping.setServletName(holder.getName());
         String path = uri.getPath();
-        
+
         if (!path.startsWith("/")) {
             path = '/' + path;
         }
-        
+
         if (!path.startsWith(contextPath)) {
             path = contextPath + path;
-        }  
-                
+        }
+
         mapping.setPathSpec(path);
         servletHandler.addServletMapping(mapping);
-        
+
         // Compute the complete URL
         String host;
         try {
@@ -299,7 +298,7 @@
         }
         logger.info("Added Servlet mapping: " + addedURL);
     }
-    
+
     public URL getURLMapping(String suri) throws ServletMappingException {
         URI uri = URI.create(suri);
 
@@ -312,7 +311,7 @@
         if (portNumber == -1) {
             portNumber = defaultPort;
         }
-        
+
         // Get the host
         String host;
         try {
@@ -320,11 +319,10 @@
         } catch (UnknownHostException e) {
             host = "localhost";
         }
-        
+
         // Construct the URL
         String path = uri.getPath();
 
-       
         if (!path.startsWith("/")) {
             path = '/' + path;
         }
@@ -332,7 +330,6 @@
         if (!path.startsWith(contextPath)) {
             path = contextPath + path;
         }
-        
 
         URL url;
         try {
@@ -342,15 +339,15 @@
         }
         return url;
     }
-        
+
     public Servlet getServletMapping(String suri) throws 
ServletMappingException {
-        
-        if (suri == null){
+
+        if (suri == null) {
             return null;
         }
-        
+
         URI uri = URI.create(suri);
-        
+
         // Get the URI port
         int portNumber = uri.getPort();
         if (portNumber == -1) {
@@ -362,22 +359,22 @@
         if (port == null) {
             return null;
         }
-        
+
         // Remove the Servlet mapping for the given Servlet 
         ServletHandler servletHandler = port.getServletHandler();
         Servlet servlet = null;
         List<ServletMapping> mappings =
             new 
ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
         String path = uri.getPath();
-        
+
         if (!path.startsWith("/")) {
             path = '/' + path;
         }
-        
+
         if (!path.startsWith(contextPath)) {
             path = contextPath + path;
         }
-        
+
         for (ServletMapping mapping : mappings) {
             if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                 try {
@@ -393,7 +390,7 @@
 
     public Servlet removeServletMapping(String suri) {
         URI uri = URI.create(suri);
-        
+
         // Get the URI port
         int portNumber = uri.getPort();
         if (portNumber == -1) {
@@ -410,22 +407,22 @@
             logger.warning("No servlet registered at this URI: " + suri);
             return null;
         }
-        
+
         // Remove the Servlet mapping for the given Servlet 
         ServletHandler servletHandler = port.getServletHandler();
         Servlet removedServlet = null;
         List<ServletMapping> mappings =
             new 
ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
         String path = uri.getPath();
-        
+
         if (!path.startsWith("/")) {
             path = '/' + path;
         }
-        
+
         if (!path.startsWith(contextPath)) {
             path = contextPath + path;
         }
-        
+
         for (ServletMapping mapping : mappings) {
             if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                 try {
@@ -440,7 +437,7 @@
         }
         if (removedServlet != null) {
             servletHandler.setServletMappings(mappings.toArray(new 
ServletMapping[mappings.size()]));
-            
+
             // Stop the port if there are no servlet mappings on it anymore
             if (mappings.size() == 0) {
                 try {
@@ -452,11 +449,11 @@
                 }
                 ports.remove(portNumber);
             }
-            
+
         } else {
             logger.warning("Trying to Remove servlet mapping: " + path + " 
where mapping is not registered");
         }
-        
+
         return removedServlet;
     }
 
@@ -464,11 +461,11 @@
         //FIXME implement this later
         return null;
     }
-    
+
     public String getContextPath() {
         return contextPath;
     }
-    
+
     public void setContextPath(String path) {
         this.contextPath = path;
     }
@@ -506,4 +503,14 @@
         throw new UnsupportedOperationException();
     }
 
+    public void start() {
+        try {
+            jettyLogger = Log.getLog();
+        } catch (Throwable e) {
+            // Ignore
+        } finally {
+            Log.setLog(new JettyLogger());
+        }
+    }
+
 }

Added: 
tuscany/java/sca/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHost
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHost?rev=822343&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHost
 (added)
+++ 
tuscany/java/sca/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHost
 Tue Oct  6 16:55:15 2009
@@ -0,0 +1,18 @@
+# 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.
+# Implementation class for the ServletHost
+org.apache.tuscany.sca.http.jetty.JettyServer;ranking=100
\ No newline at end of file

Modified: 
tuscany/java/sca/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java?rev=822343&r1=822342&r2=822343&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java
 (original)
+++ 
tuscany/java/sca/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java
 Tue Oct  6 16:55:15 2009
@@ -87,6 +87,7 @@
      */
     public void testRegisterServletMapping() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         TestServlet servlet = new TestServlet();
         service.addServletMapping("http://127.0.0.1:"; + HTTP_PORT + "/", 
servlet);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
@@ -103,6 +104,7 @@
         System.setProperty("javax.net.ssl.keyStorePassword", "apache");
         System.setProperty("jetty.ssl.password", "apache");
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         TestServlet servlet = new TestServlet();
         try {
             service.addServletMapping("https://127.0.0.1:"; + HTTP_PORT + 
"/foo", servlet);
@@ -134,6 +136,7 @@
      */
     public void testRegisterMultiplePorts() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         TestServlet servlet = new TestServlet();
         service.addServletMapping("http://127.0.0.1:"; + HTTP_PORT + "/", 
servlet);
         TestServlet servlet2 = new TestServlet();
@@ -160,6 +163,7 @@
 
     public void testUnregisterMapping() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         TestServlet servlet = new TestServlet();
         String uri = "http://127.0.0.1:"; + HTTP_PORT + "/foo";
         service.addServletMapping(uri, servlet);
@@ -179,6 +183,7 @@
 
     public void testRequestSession() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         TestServlet servlet = new TestServlet();
         service.addServletMapping("http://127.0.0.1:"; + HTTP_PORT + "/", 
servlet);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
@@ -193,12 +198,14 @@
 
     public void testRestart() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         service.stop();
         service.stop();
     }
 
     public void testNoMappings() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
         Exception ex = null;
         try {
             new Socket("127.0.0.1", HTTP_PORT);
@@ -211,6 +218,7 @@
 
     public void testResourceServlet() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
 
         String documentRoot = 
getClass().getClassLoader().getResource("content/test.html").toString();
         documentRoot = documentRoot.substring(0, 
documentRoot.lastIndexOf('/'));
@@ -231,6 +239,7 @@
 
     public void testDefaultServlet() throws Exception {
         JettyServer service = new JettyServer(workScheduler);
+        service.start();
 
         String documentRoot = 
getClass().getClassLoader().getResource("content/test.html").toString();
         documentRoot = documentRoot.substring(0, 
documentRoot.lastIndexOf('/'));

Modified: 
tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java?rev=822343&r1=822342&r2=822343&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
 (original)
+++ 
tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java
 Tue Oct  6 16:55:15 2009
@@ -162,11 +162,12 @@
         if (hosts == null || hosts.size() < 1) {
             throw new IllegalStateException("No ServletHost found");
         }
-        ServletHost servletHost = hosts.get(0);
-        if (!(servletHost instanceof WebAppServletHost)) {
-            throw new IllegalStateException("unexpected ServletHost type: " + 
servletHost);
+        for (ServletHost servletHost : hosts) {
+            if ((servletHost instanceof WebAppServletHost)) {
+                return (WebAppServletHost)servletHost;
+            }
         }
-        return (WebAppServletHost)servletHost;
+        throw new IllegalStateException("No WebApp Servlet host is 
configured");
     }
 
     private static Node createNode(final ServletContext servletContext) throws 
ServletException {


Reply via email to