tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r534625 - in /incubator/tuscany/java/sca/modules: binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/ http-jetty/src/main/java/org/apache/tuscany/http/jetty/ http-jetty/src/test/java/org/apache/tuscany/http/jetty/ http-tomcat/s...
Date Wed, 02 May 2007 21:43:14 GMT
Author: antelder
Date: Wed May  2 14:43:13 2007
New Revision: 534625

URL: http://svn.apache.org/viewvc?view=rev&rev=534625
Log:
Change ServletHostExtension add/removeServletMapping to use just a uri string instead of a
port and a mapping

Modified:
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.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/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/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java
    incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtension.java

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java?view=diff&rev=534625&r1=534624&r2=534625
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java
(original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceBinding.java
Wed May  2 14:43:13 2007
@@ -101,12 +101,13 @@
 
         Axis2ServiceServlet servlet = new Axis2ServiceServlet();
         servlet.init(configContext);
-        configContext.setContextRoot(getUri().toString());
-        servletHost.addServletMapping(8080, getUri().getPath(), servlet);
+        String servletURI = getUri().toString();
+        configContext.setContextRoot(servletURI);
+        servletHost.addServletMapping(servletURI, servlet);
     }
 
     public void stop() {
-        servletHost.removeServletMapping(8080, getUri().getPath());
+        servletHost.removeServletMapping(getUri().toString());
         try {
             configContext.getAxisConfiguration().removeService(getUri().toString());
         } catch (AxisFault e) {

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=534625&r1=534624&r2=534625
==============================================================================
--- 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
Wed May  2 14:43:13 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.http.jetty;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -56,6 +57,7 @@
     private static final int STARTED = 2;
     private static final int STOPPING = 3;
     private static final int STOPPED = 4;
+    private static final int DEFAULT_PORT = 8080;
 
     private final Object joinLock = new Object();
     private int state = UNINITIALIZED;
@@ -133,9 +135,12 @@
         }
     }
 
-    public void addServletMapping(int port, String path, Servlet servlet) throws ServletMappingException
{
+    public void addServletMapping(String uri, Servlet servlet) throws ServletMappingException
{
         if (state == STARTING) {
 
+            // TODO: use the port from the uri, but thats a bit harder to do 
+            int port = DEFAULT_PORT;
+            
             try {
                 server = new Server();
                 server.setThreadPool(new WorkSchedulerThreadPool());
@@ -184,14 +189,16 @@
         servletHandler.addServlet(holder);
         ServletMapping mapping = new ServletMapping();
         mapping.setServletName(holder.getName());
+        String path = URI.create(uri).getPath();
         mapping.setPathSpec(path);
         servletHandler.addServletMapping(mapping);
     }
 
-    public Servlet removeServletMapping(int port, String path) {
+    public Servlet removeServletMapping(String uri) {
         Servlet removedServlet = null;
         List<ServletMapping> mappings =
             new ArrayList<ServletMapping>(Arrays.asList(servletHandler.getServletMappings()));
+        String path = URI.create(uri).getPath();
         for (ServletMapping mapping : mappings) {
             if (Arrays.asList(mapping.getPathSpecs()).contains(path)) {
                 try {

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=534625&r1=534624&r2=534625
==============================================================================
--- 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
Wed May  2 14:43:13 2007
@@ -50,7 +50,7 @@
     private static final String REQUEST1 =
         REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT;
 
-    private static final int HTTP_PORT = 8585;
+    private static final int HTTP_PORT = 8080;
 
     private WorkScheduler workScheduler = new WorkScheduler() {
         
@@ -71,7 +71,7 @@
         JettyServer service = new JettyServer(workScheduler);
         service.init();
         TestServlet servlet = new TestServlet();
-        service.addServletMapping(HTTP_PORT, "/", servlet);
+        service.addServletMapping("http://127.0.0.1:" + HTTP_PORT + "/", servlet);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
         OutputStream os = client.getOutputStream();
         os.write(REQUEST1.getBytes());
@@ -85,8 +85,9 @@
         JettyServer service = new JettyServer(workScheduler);
         service.init();
         TestServlet servlet = new TestServlet();
-        service.addServletMapping(HTTP_PORT, "/foo", servlet);
-        service.removeServletMapping(HTTP_PORT, "/foo");
+        String uri = "http://127.0.0.1:" + HTTP_PORT + "/foo";
+        service.addServletMapping(uri, servlet);
+        service.removeServletMapping(uri);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
         OutputStream os = client.getOutputStream();
         os.write(REQUEST1.getBytes());
@@ -101,7 +102,7 @@
         service.setDebug(true);
         service.init();
         TestServlet servlet = new TestServlet();
-        service.addServletMapping(HTTP_PORT, "/", servlet);
+        service.addServletMapping("http://127.0.0.1:" + HTTP_PORT + "/", servlet);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
         OutputStream os = client.getOutputStream();
         os.write(REQUEST1.getBytes());

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=534625&r1=534624&r2=534625
==============================================================================
--- 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
Wed May  2 14:43:13 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.tuscany.http.tomcat;
 
+import java.net.URI;
 import java.util.concurrent.Executor;
 
 import javax.servlet.Servlet;
@@ -45,6 +46,7 @@
  */
 public class TomcatServer implements ServletHostExtension {
 
+    private static final int DEFAULT_PORT = 8080;
     private StandardEngine engine;
     private StandardHost host;
     private Connector connector;
@@ -162,7 +164,10 @@
         }
     }
 
-    public void addServletMapping(int port, String mapping, Servlet servlet) {
+    public void addServletMapping(String uri, Servlet servlet) {
+        
+        // TODO: use the port from the uri, but thats a bit harder to do 
+        int port = DEFAULT_PORT;
         
         // Install a default HTTP connector
         if (connector == null) {
@@ -180,6 +185,7 @@
         }
 
         // Register the servlet mapping
+        String mapping = URI.create(uri).getPath();
         Context context = host.map(mapping);
         Wrapper wrapper = new ServletWrapper(servlet);
         wrapper.setName(mapping);
@@ -189,7 +195,8 @@
         connector.getMapper().addWrapper("localhost", "", mapping, wrapper);
     }
 
-    public Servlet removeServletMapping(int port, String mapping) {
+    public Servlet removeServletMapping(String uri) {
+        String mapping = URI.create(uri).getPath();
         Context context = host.map(mapping);
         MappingData md = new MappingData();
         MessageBytes mb = MessageBytes.newInstance();

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=534625&r1=534624&r2=534625
==============================================================================
--- 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
Wed May  2 14:43:13 2007
@@ -48,7 +48,7 @@
     private static final String REQUEST1 =
         REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT;
 
-    private static final int HTTP_PORT = 8586;
+    private static final int HTTP_PORT = 8080;
     
     private WorkScheduler workScheduler = new WorkScheduler() {
         
@@ -69,7 +69,7 @@
         TomcatServer service = new TomcatServer(workScheduler);
         service.init();
         TestServlet servlet = new TestServlet();
-        service.addServletMapping(HTTP_PORT, "/foo", servlet);
+        service.addServletMapping("http://127.0.0.1:" + HTTP_PORT + "/foo", servlet);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
         OutputStream os = client.getOutputStream();
         os.write(REQUEST1.getBytes());
@@ -83,8 +83,8 @@
         TomcatServer service = new TomcatServer(workScheduler);
         service.init();
         TestServlet servlet = new TestServlet();
-        service.addServletMapping(HTTP_PORT, "/foo", servlet);
-        service.removeServletMapping(HTTP_PORT, "/foo");
+        service.addServletMapping("http://127.0.0.1:" + HTTP_PORT + "/foo", servlet);
+        service.removeServletMapping("http://127.0.0.1:" + HTTP_PORT + "/foo");
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
         OutputStream os = client.getOutputStream();
         os.write(REQUEST1.getBytes());
@@ -98,7 +98,7 @@
         TomcatServer service = new TomcatServer(workScheduler);
         service.init();
         TestServlet servlet = new TestServlet();
-        service.addServletMapping(HTTP_PORT, "/foo", servlet);
+        service.addServletMapping("http://127.0.0.1:" + HTTP_PORT + "/foo", servlet);
         Socket client = new Socket("127.0.0.1", HTTP_PORT);
         OutputStream os = client.getOutputStream();
         os.write(REQUEST1.getBytes());

Modified: 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=diff&rev=534625&r1=534624&r2=534625
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java
(original)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/DefaultServletHostExtensionPoint.java
Wed May  2 14:43:13 2007
@@ -41,22 +41,20 @@
         servletHosts.remove(servletHost);
     }
 
-    public void addServletMapping(int port, String mapping, Servlet servlet) throws ServletMappingException
{
+    public void addServletMapping(String uri, 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
+        // 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);
+        servletHosts.get(0).addServletMapping(uri, servlet);
     }
 
-    public Servlet removeServletMapping(int port, String mapping) throws ServletMappingException
{
-        // TODO implement selection of the correct servlet host based on the
-        // mapping
+    public Servlet removeServletMapping(String uri) 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);
+        return servletHosts.get(0).removeServletMapping(uri);
     }
 
 }

Modified: incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtension.java?view=diff&rev=534625&r1=534624&r2=534625
==============================================================================
--- incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtension.java
(original)
+++ incubator/tuscany/java/sca/modules/http/src/main/java/org/apache/tuscany/http/ServletHostExtension.java
Wed May  2 14:43:13 2007
@@ -22,7 +22,9 @@
 
 /**
  * Interface implemented by host environments that allow Servlets to be
- * registered. <p/> This interface allows a system service to register a servlet
+ * registered. 
+ * <p/> 
+ * This interface allows a system service to register a servlet
  * to handle inbound requests.
  * 
  * @version $Rev$ $Date$
@@ -33,21 +35,19 @@
      * 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 uri the uri-mapping for the Servlet
      * @param servlet the Servlet that should be invoked
      */
-    void addServletMapping(int host, String mapping, Servlet servlet) throws ServletMappingException;
+    void addServletMapping(String uri, Servlet servlet) throws ServletMappingException;
 
     /**
      * 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
+     * @param uri the uri-mapping for the Servlet
      * @return the servlet that was registered to the mapping, null if nothing
      *         was registered to the mapping
      */
-    Servlet removeServletMapping(int host, String mapping) throws ServletMappingException;
+    Servlet removeServletMapping(String uri) throws ServletMappingException;
 
 }



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


Mime
View raw message