You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2007/04/15 19:19:29 UTC
svn commit: r529018 - in /incubator/tuscany/java/sca/modules:
http-jetty/src/main/java/org/apache/tuscany/http/jetty/
http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/
http-jetty/src/main/resources/ http-jetty/src/main/resources/META-INF/ ...
Author: jsdelfino
Date: Sun Apr 15 10:19:27 2007
New Revision: 529018
URL: http://svn.apache.org/viewvc?view=rev&rev=529018
Log:
Defined extension point for ServletHosts and implemented ServletHosts extensions for Jetty and Tomcat.
Added:
incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/
incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java (with props)
incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/
incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/
incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/services/
incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator
incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/
incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java (with props)
incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/
incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/
incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/services/
incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator
incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java (with props)
incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java (with props)
incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/
incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java (with props)
incubator/tuscany/java/sca/modules/http/src/main/resources/
incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/
incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/services/
incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator
Modified:
incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyLogger.java
incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyServer.java
incubator/tuscany/java/sca/modules/http-jetty/src/test/java/org/apache/tuscany/http/jetty/JettyServerTestCase.java
incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/ServletWrapper.java
incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java
incubator/tuscany/java/sca/modules/http-tomcat/src/test/java/org/apache/tuscany/http/tomcat/TomcatServerTestCase.java
incubator/tuscany/java/sca/modules/http/pom.xml
incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHost.java
incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletMappingException.java
Modified: incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyLogger.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyLogger.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyLogger.java (original)
+++ incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyLogger.java Sun Apr 15 10:19:27 2007
@@ -22,7 +22,7 @@
/**
* Replaces Jetty's logging mechanism
- *
+ *
* @version $Rev$ $Date$
*/
public class JettyLogger implements Logger {
@@ -58,7 +58,7 @@
public void warn(String msg, Object arg0, Object arg1) {
if (debugEnabled) {
- System.err.println(":WARN: " + format(msg, arg0, arg1));
+ System.err.println(":WARN: " + format(msg, arg0, arg1));
}
}
Modified: incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyServer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyServer.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyServer.java (original)
+++ incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/JettyServer.java Sun Apr 15 10:19:27 2007
@@ -58,13 +58,12 @@
private final Object joinLock = new Object();
private int state = UNINITIALIZED;
- private int httpPort = 8080;
- private int httpsPort = 8484;
private String keystore;
private String certPassword;
private String keyPassword;
private boolean sendServerVersion;
private boolean https;
+ private int httpsPort = 8484;
private boolean debug;
private Server server;
private Connector connector;
@@ -88,18 +87,6 @@
}
}
- public void setHttpPort(int httpPort) {
- this.httpPort = httpPort;
- }
-
- public int getHttpPort() {
- return httpPort;
- }
-
- public void setHttpsPort(int httpsPort) {
- this.httpsPort = httpsPort;
- }
-
public void setSendServerVersion(boolean sendServerVersion) {
this.sendServerVersion = sendServerVersion;
}
@@ -124,22 +111,26 @@
debug = val;
}
- public void init() throws Exception {
+ public void init() {
state = STARTING;
}
- public void destroy() throws Exception {
+ public void destroy() {
if (state == STARTED) {
state = STOPPING;
synchronized (joinLock) {
joinLock.notifyAll();
}
- server.stop();
+ try {
+ server.stop();
+ } catch (Exception e) {
+ throw new ServletMappingException(e);
+ }
state = STOPPED;
}
}
- public void addServletMapping(String path, Servlet servlet) throws ServletMappingException {
+ public void addServletMapping(int port, String path, Servlet servlet) throws ServletMappingException {
if (state == STARTING) {
try {
@@ -150,7 +141,7 @@
if (connector == null) {
if (https) {
Connector httpConnector = new SelectChannelConnector();
- httpConnector.setPort(httpPort);
+ httpConnector.setPort(port);
SslSocketConnector sslConnector = new SslSocketConnector();
sslConnector.setPort(httpsPort);
sslConnector.setKeystore(keystore);
@@ -159,11 +150,11 @@
server.setConnectors(new Connector[] {httpConnector, sslConnector});
} else {
SelectChannelConnector selectConnector = new SelectChannelConnector();
- selectConnector.setPort(httpPort);
+ selectConnector.setPort(port);
server.setConnectors(new Connector[] {selectConnector});
}
} else {
- connector.setPort(httpPort);
+ connector.setPort(port);
server.setConnectors(new Connector[] {connector});
}
@@ -196,9 +187,10 @@
servletHandler.addServletMapping(mapping);
}
- public Servlet removeServletMapping(String path) {
+ public Servlet removeServletMapping(int port, String path) {
Servlet removedServlet = null;
- List<ServletMapping> mappings = new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
+ List<ServletMapping> mappings =
+ new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
for (ServletMapping mapping : mappings) {
if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
try {
Added: incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java (added)
+++ incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java Sun Apr 15 10:19:27 2007
@@ -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.
+ */
+
+package org.apache.tuscany.http.jetty.module;
+
+import java.util.Map;
+
+import org.apache.tuscany.http.ServletHostExtensionPoint;
+import org.apache.tuscany.http.jetty.JettyServer;
+import org.apache.tuscany.spi.bootstrap.ExtensionPointRegistry;
+import org.apache.tuscany.spi.bootstrap.ModuleActivator;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JettyRuntimeModuleActivator implements ModuleActivator {
+
+ private JettyServer server;
+
+ public Map<Class, Object> getExtensionPoints() {
+ return null;
+ }
+
+ public void start(ExtensionPointRegistry extensionPointRegistry) {
+
+ // Register a Jetty servlet host
+ ServletHostExtensionPoint servletHosts =
+ extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);
+ server = new JettyServer();
+ servletHosts.addExtension(server);
+ server.init();
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ server.destroy();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/http-jetty/src/main/java/org/apache/tuscany/http/jetty/module/JettyRuntimeModuleActivator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator (added)
+++ incubator/tuscany/java/sca/modules/http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator Sun Apr 15 10:19:27 2007
@@ -0,0 +1,2 @@
+# Implementation class for the ModuleActivator
+org.apache.tuscany.http.jetty.module.JettyRuntimeModuleActivator
Modified: incubator/tuscany/java/sca/modules/http-jetty/src/test/java/org/apache/tuscany/http/jetty/JettyServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-jetty/src/test/java/org/apache/tuscany/http/jetty/JettyServerTestCase.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-jetty/src/test/java/org/apache/tuscany/http/jetty/JettyServerTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/http-jetty/src/test/java/org/apache/tuscany/http/jetty/JettyServerTestCase.java Sun Apr 15 10:19:27 2007
@@ -40,13 +40,11 @@
public class JettyServerTestCase extends TestCase {
private static final String REQUEST1_HEADER =
- "GET / HTTP/1.0\n"
- + "Host: localhost\n"
+ "GET / HTTP/1.0\n" + "Host: localhost\n"
+ "Content-Type: text/xml\n"
+ "Connection: close\n"
+ "Content-Length: ";
- private static final String REQUEST1_CONTENT =
- "";
+ private static final String REQUEST1_CONTENT = "";
private static final String REQUEST1 =
REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT;
@@ -57,10 +55,9 @@
*/
public void testRegisterServletMapping() throws Exception {
JettyServer service = new JettyServer();
- service.setHttpPort(HTTP_PORT);
service.init();
TestServlet servlet = new TestServlet();
- service.addServletMapping("/", servlet);
+ service.addServletMapping(HTTP_PORT, "/", servlet);
Socket client = new Socket("127.0.0.1", HTTP_PORT);
OutputStream os = client.getOutputStream();
os.write(REQUEST1.getBytes());
@@ -72,11 +69,10 @@
public void testUnregisterMapping() throws Exception {
JettyServer service = new JettyServer();
- service.setHttpPort(HTTP_PORT);
service.init();
TestServlet servlet = new TestServlet();
- service.addServletMapping("/foo", servlet);
- service.removeServletMapping("/foo");
+ service.addServletMapping(HTTP_PORT, "/foo", servlet);
+ service.removeServletMapping(HTTP_PORT, "/foo");
Socket client = new Socket("127.0.0.1", HTTP_PORT);
OutputStream os = client.getOutputStream();
os.write(REQUEST1.getBytes());
@@ -89,10 +85,9 @@
public void testRequestSession() throws Exception {
JettyServer service = new JettyServer();
service.setDebug(true);
- service.setHttpPort(HTTP_PORT);
service.init();
TestServlet servlet = new TestServlet();
- service.addServletMapping("/", servlet);
+ service.addServletMapping(HTTP_PORT, "/", servlet);
Socket client = new Socket("127.0.0.1", HTTP_PORT);
OutputStream os = client.getOutputStream();
os.write(REQUEST1.getBytes());
@@ -105,7 +100,6 @@
public void testRestart() throws Exception {
JettyServer service = new JettyServer();
- service.setHttpPort(HTTP_PORT);
service.init();
service.destroy();
service.init();
@@ -114,13 +108,12 @@
public void testNoMappings() throws Exception {
JettyServer service = new JettyServer();
- service.setHttpPort(HTTP_PORT);
service.init();
Exception ex = null;
try {
new Socket("127.0.0.1", HTTP_PORT);
} catch (ConnectException e) {
- ex = e;
+ ex = e;
}
assertNotNull(ex);
service.destroy();
@@ -158,7 +151,6 @@
writer.close();
}
}
-
}
}
Modified: incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/ServletWrapper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/ServletWrapper.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/ServletWrapper.java (original)
+++ incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/ServletWrapper.java Sun Apr 15 10:19:27 2007
@@ -24,8 +24,8 @@
/**
* A servlet wrapper.
- *
- * @version $Rev$ $Date$
+ *
+ * @version $Rev$ $Date$
*/
public class ServletWrapper extends StandardWrapper {
private static final long serialVersionUID = 1L;
@@ -43,5 +43,5 @@
public Servlet getServlet() {
return servlet;
}
-
+
}
Modified: incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java (original)
+++ incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/TomcatServer.java Sun Apr 15 10:19:27 2007
@@ -32,75 +32,84 @@
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.http.mapper.MappingData;
import org.apache.tuscany.http.ServletHost;
+import org.apache.tuscany.http.ServletMappingException;
/**
- * A Tomcat based implementation of ServletHost.
- *
- * @version $Rev$ $Date$
+ * A Tomcat based implementation of ServletHost.
+ *
+ * @version $Rev$ $Date$
*/
public class TomcatServer implements ServletHost {
-
- private int httpPort = 8080;
- private Embedded tomcat;
- private Host host;
- private boolean started;
-
- public void init() throws LifecycleException {
- tomcat = new Embedded();
-
- // Create an engine
- Engine engine = tomcat.createEngine();
- engine.setDefaultHost("localhost");
-
- // Create a host
- host = tomcat.createHost("localhost", "");
- engine.addChild(host);
-
- // Create the ROOT context
- Context context = tomcat.createContext("", "");
- host.addChild(context);
-
- // Install the engine
- tomcat.addEngine(engine);
-
- // Install a default HTTP connector
- Connector connector = tomcat.createConnector((InetAddress)null, httpPort, false);
- tomcat.addConnector(connector);
+
+ private Embedded tomcat;
+ private Host host;
+ Connector connector;
+ private boolean started;
+
+ public void init() throws ServletMappingException {
+ tomcat = new Embedded();
+
+ // Create an engine
+ Engine engine = tomcat.createEngine();
+ engine.setDefaultHost("localhost");
+
+ // Create a host
+ host = tomcat.createHost("localhost", "");
+ engine.addChild(host);
+
+ // Create the ROOT context
+ Context context = tomcat.createContext("", "");
+ host.addChild(context);
+
+ // Install the engine
+ tomcat.addEngine(engine);
+
}
- public void destroy() throws LifecycleException {
-
- // Stop the server
- if (started) {
- tomcat.stop();
- started = false;
- }
+ public void destroy() throws ServletMappingException {
+
+ // Stop the server
+ if (started) {
+ try {
+ tomcat.stop();
+ } catch (LifecycleException e) {
+ throw new ServletMappingException(e);
+ }
+ started = false;
+ }
}
-
- public void addServletMapping(String mapping, Servlet servlet) {
-
+
+ public void addServletMapping(int port, String mapping, Servlet servlet) {
+
+ // Install a default HTTP connector
+ if (connector == null) {
+ //TODO support multiple connectors on different ports
+ connector = tomcat.createConnector((InetAddress)null, port, false);
+ tomcat.addConnector(connector);
+ }
+
// Register the servlet mapping
- Context context = host.map(mapping);
+ Context context = host.map(mapping);
Wrapper wrapper = new ServletWrapper(servlet);
wrapper.setName(mapping);
wrapper.addMapping(mapping);
context.addChild(wrapper);
context.addServletMapping(mapping, mapping);
- // Start Tomcat
- try {
- if (!started) {
- tomcat.start();
- started = true;
- }
-
- } catch (LifecycleException e) {
- //TODO use a better runtime exception
- throw new RuntimeException(e);
- }
- }
+ // Start Tomcat
+ try {
+ if (!started) {
+ tomcat.start();
+ started = true;
+ }
+
+ } catch (LifecycleException e) {
+ // TODO use a better runtime exception
+ throw new RuntimeException(e);
+ }
+ }
- public Servlet removeServletMapping(String mapping) {
+ public Servlet removeServletMapping(int port, String mapping) {
Context context = host.map(mapping);
MappingData md = new MappingData();
MessageBytes mb = MessageBytes.newInstance();
@@ -111,21 +120,13 @@
return null;
}
if (md.wrapper instanceof ServletWrapper) {
- ServletWrapper servletWrapper = (ServletWrapper)md.wrapper;
- context.removeServletMapping(mapping);
- context.removeChild(servletWrapper);
- return servletWrapper.getServlet();
+ ServletWrapper servletWrapper = (ServletWrapper)md.wrapper;
+ context.removeServletMapping(mapping);
+ context.removeChild(servletWrapper);
+ return servletWrapper.getServlet();
} else {
- return null;
+ return null;
}
- }
-
- public void setHttpPort(int httpPort) {
- this.httpPort = httpPort;
- }
-
- public int getHttpPort() {
- return httpPort;
- }
+ }
}
Added: incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java (added)
+++ incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java Sun Apr 15 10:19:27 2007
@@ -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.
+ */
+
+package org.apache.tuscany.http.tomcat.module;
+
+import java.util.Map;
+
+import org.apache.tuscany.http.ServletHostExtensionPoint;
+import org.apache.tuscany.http.tomcat.TomcatServer;
+import org.apache.tuscany.spi.bootstrap.ExtensionPointRegistry;
+import org.apache.tuscany.spi.bootstrap.ModuleActivator;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TomcatRuntimeModuleActivator implements ModuleActivator {
+
+ private TomcatServer server;
+
+ public Map<Class, Object> getExtensionPoints() {
+ return null;
+ }
+
+ public void start(ExtensionPointRegistry extensionPointRegistry) {
+
+ // Register a Tomcat servlet host
+ ServletHostExtensionPoint servletHosts =
+ extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);
+ server = new TomcatServer();
+ server.init();
+ servletHosts.addExtension(server);
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ server.destroy();
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/http-tomcat/src/main/java/org/apache/tuscany/http/tomcat/module/TomcatRuntimeModuleActivator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator (added)
+++ incubator/tuscany/java/sca/modules/http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator Sun Apr 15 10:19:27 2007
@@ -0,0 +1,2 @@
+# Implementation class for the ModuleActivator
+org.apache.tuscany.http.tomcat.module.TomcatRuntimeModuleActivator
Modified: incubator/tuscany/java/sca/modules/http-tomcat/src/test/java/org/apache/tuscany/http/tomcat/TomcatServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http-tomcat/src/test/java/org/apache/tuscany/http/tomcat/TomcatServerTestCase.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http-tomcat/src/test/java/org/apache/tuscany/http/tomcat/TomcatServerTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/http-tomcat/src/test/java/org/apache/tuscany/http/tomcat/TomcatServerTestCase.java Sun Apr 15 10:19:27 2007
@@ -37,13 +37,11 @@
public class TomcatServerTestCase extends TestCase {
private static final String REQUEST1_HEADER =
- "GET /foo HTTP/1.0\n"
- + "Host: localhost\n"
+ "GET /foo HTTP/1.0\n" + "Host: localhost\n"
+ "Content-Type: text/xml\n"
+ "Connection: close\n"
+ "Content-Length: ";
- private static final String REQUEST1_CONTENT =
- "";
+ private static final String REQUEST1_CONTENT = "";
private static final String REQUEST1 =
REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT;
@@ -54,10 +52,9 @@
*/
public void testRegisterServletMapping() throws Exception {
TomcatServer service = new TomcatServer();
- service.setHttpPort(HTTP_PORT);
service.init();
TestServlet servlet = new TestServlet();
- service.addServletMapping("/foo", servlet);
+ service.addServletMapping(HTTP_PORT, "/foo", servlet);
Socket client = new Socket("127.0.0.1", HTTP_PORT);
OutputStream os = client.getOutputStream();
os.write(REQUEST1.getBytes());
@@ -69,11 +66,10 @@
public void testUnregisterMapping() throws Exception {
TomcatServer service = new TomcatServer();
- service.setHttpPort(HTTP_PORT);
service.init();
TestServlet servlet = new TestServlet();
- service.addServletMapping("/foo", servlet);
- service.removeServletMapping("/foo");
+ service.addServletMapping(HTTP_PORT, "/foo", servlet);
+ service.removeServletMapping(HTTP_PORT, "/foo");
Socket client = new Socket("127.0.0.1", HTTP_PORT);
OutputStream os = client.getOutputStream();
os.write(REQUEST1.getBytes());
@@ -85,10 +81,9 @@
public void testRequestSession() throws Exception {
TomcatServer service = new TomcatServer();
- service.setHttpPort(HTTP_PORT);
service.init();
TestServlet servlet = new TestServlet();
- service.addServletMapping("/foo", servlet);
+ service.addServletMapping(HTTP_PORT, "/foo", servlet);
Socket client = new Socket("127.0.0.1", HTTP_PORT);
OutputStream os = client.getOutputStream();
os.write(REQUEST1.getBytes());
@@ -101,18 +96,16 @@
public void testRestart() throws Exception {
TomcatServer service = new TomcatServer();
- service.setHttpPort(HTTP_PORT);
service.init();
service.destroy();
service.init();
service.destroy();
}
- //FIXME this test randomly breaks on Linux, probably something
+ // FIXME this test randomly breaks on Linux, probably something
// to do with cleaning up TCP/IP connections?
- public void FIXMEtestNoMappings() throws Exception {
+ public void testNoMappings() throws Exception {
TomcatServer service = new TomcatServer();
- service.setHttpPort(HTTP_PORT);
service.init();
Exception ex = null;
try {
@@ -121,7 +114,7 @@
os.write(REQUEST1.getBytes());
os.flush();
} catch (Exception e) {
- ex = e;
+ ex = e;
}
assertNotNull(ex);
service.destroy();
@@ -159,7 +152,6 @@
writer.close();
}
}
-
}
}
Modified: incubator/tuscany/java/sca/modules/http/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/pom.xml?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/http/pom.xml Sun Apr 15 10:19:27 2007
@@ -26,9 +26,15 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>tuscany-http</artifactId>
- <name>Apache Tuscany HTTP Servlet Host</name>
+ <name>Apache Tuscany HTTP Servlet Host Extension Point</name>
<dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ </dependency>
+
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Added: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java (added)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java Sun Apr 15 10:19:27 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.http;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.Servlet;
+
+/**
+ * Default implementation of a servlet host extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultServletHostExtensionPoint implements ServletHostExtensionPoint {
+
+ private List<ServletHost> servletHosts = new ArrayList<ServletHost>();
+
+ public void addExtension(ServletHost servletHost) {
+ servletHosts.add(servletHost);
+ }
+
+ public void removeExtension(ServletHost servletHost) {
+ servletHosts.remove(servletHost);
+ }
+
+ public void addServletMapping(int port, String mapping, Servlet servlet) throws ServletMappingException {
+ if (servletHosts.isEmpty()) {
+ throw new ServletMappingException("No servlet host available");
+ }
+
+ // TODO implement selection of the correct servlet host based on the
+ // mapping
+ // For now just select the first one
+ servletHosts.get(0).addServletMapping(port, mapping, servlet);
+ }
+
+ public Servlet removeServletMapping(int port, String mapping) throws ServletMappingException {
+ // TODO implement selection of the correct servlet host based on the
+ // mapping
+ // For now just select the first one
+ return servletHosts.get(0).removeServletMapping(port, mapping);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHost.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHost.java (original)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHost.java Sun Apr 15 10:19:27 2007
@@ -21,29 +21,33 @@
import javax.servlet.Servlet;
/**
- * Interface implemented by host environments that allow Servlets to be registered.
- * <p/>
- * This interface allows a system service to register a servlet to handle inbound requests.
- *
+ * Interface implemented by host environments that allow Servlets to be
+ * registered. <p/> This interface allows a system service to register a servlet
+ * to handle inbound requests.
+ *
* @version $Rev$ $Date$
*/
public interface ServletHost {
/**
- * Add a mapping for an instance of a Servlet. This requests that the servlet container direct all requests to
- * the designated mapping to the supplied Servlet instance.
- *
+ * Add a mapping for an instance of a Servlet. This requests that the
+ * servlet container direct all requests to the designated mapping to the
+ * supplied Servlet instance.
+ *
+ * @param port the port for the Servlet
* @param mapping the uri-mapping for the Servlet
* @param servlet the Servlet that should be invoked
*/
- void addServletMapping(String mapping, Servlet servlet) throws ServletMappingException;
+ void addServletMapping(int host, String mapping, Servlet servlet) throws ServletMappingException;
/**
- * Remove a servlet mapping. This directs the servlet contain not to direct any more requests to a previously
- * registered Servlet.
- *
+ * Remove a servlet mapping. This directs the servlet contain not to direct
+ * any more requests to a previously registered Servlet.
+ *
+ * @param port the port for the Servlet
* @param mapping the uri-mapping for the Servlet
- * @return the servlet that was registered to the mapping, null if nothing was registered to the mapping
+ * @return the servlet that was registered to the mapping, null if nothing
+ * was registered to the mapping
*/
- Servlet removeServletMapping(String mapping) throws ServletMappingException;
-
+ Servlet removeServletMapping(int host, String mapping) throws ServletMappingException;
+
}
Added: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java (added)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java Sun Apr 15 10:19:27 2007
@@ -0,0 +1,42 @@
+/*
+ * 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.http;
+
+/**
+ * An extension point for servlet hosts.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ServletHostExtensionPoint extends ServletHost {
+
+ /**
+ * Adds a servlet host extension.
+ *
+ * @param servletHost
+ */
+ void addExtension(ServletHost servletHost);
+
+ /**
+ * Removes a servlet host extension.
+ *
+ * @param servletHost
+ */
+ void removeExtension(ServletHost servletHost);
+
+}
Propchange: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtensionPoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletMappingException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletMappingException.java?view=diff&rev=529018&r1=529017&r2=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletMappingException.java (original)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletMappingException.java Sun Apr 15 10:19:27 2007
@@ -18,17 +18,15 @@
*/
package org.apache.tuscany.http;
-
/**
* Indicates an exception while registering a servlet mapping.
- *
+ *
* @version $Rev$ $Date$
*/
public class ServletMappingException extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
+ private static final long serialVersionUID = 1L;
- public ServletMappingException() {
+ public ServletMappingException() {
super();
}
@@ -36,11 +34,9 @@
super(message);
}
-
public ServletMappingException(String message, Throwable cause) {
super(message, cause);
}
-
public ServletMappingException(Throwable cause) {
super(cause);
Added: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java (added)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java Sun Apr 15 10:19:27 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.http.module;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.http.DefaultServletHostExtensionPoint;
+import org.apache.tuscany.http.ServletHostExtensionPoint;
+import org.apache.tuscany.spi.bootstrap.ExtensionPointRegistry;
+import org.apache.tuscany.spi.bootstrap.ModuleActivator;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HTTPRuntimeModuleActivator implements ModuleActivator {
+
+ public Map<Class, Object> getExtensionPoints() {
+
+ // Declare Servlet host extension point
+ Map<Class, Object> map = new HashMap<Class, Object>();
+ map.put(ServletHostExtensionPoint.class, new DefaultServletHostExtensionPoint());
+ return map;
+ }
+
+ public void start(ExtensionPointRegistry extensionPointRegistry) {
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/module/HTTPRuntimeModuleActivator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator?view=auto&rev=529018
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator (added)
+++ incubator/tuscany/java/sca/modules/http/src/main/resources/META-INF/services/org.apache.tuscany.spi.bootstrap.ModuleActivator Sun Apr 15 10:19:27 2007
@@ -0,0 +1,2 @@
+# Implementation class for the ModuleActivator
+org.apache.tuscany.http.module.HTTPRuntimeModuleActivator
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org