Author: rfeng
Date: Wed Aug 22 22:52:07 2007
New Revision: 568832

URL: http://svn.apache.org/viewvc?rev=568832&view=rev
Log:
Short-term fix for TUSCANY-1573

Modified:
    
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java
    
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Modified: 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java?rev=568832&r1=568831&r2=568832&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java
 Wed Aug 22 22:52:07 2007
@@ -29,8 +29,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import static 
org.apache.tuscany.sca.binding.jsonrpc.JSONRPCService.SERVICE_PREFIX;
-
 /**
  * Servlet to handle requests for the scaDomain.js script.
  * 
@@ -42,20 +40,20 @@
     private static final long serialVersionUID = 1L;
 
     protected transient List<String> serviceNames;
-    
+
     public ScaDomainScriptServlet() {
         serviceNames = new ArrayList<String>();
     }
 
     @Override
     public void doGet(HttpServletRequest request, HttpServletResponse 
response) throws IOException {
-        
+
         ServletOutputStream os = response.getOutputStream();
 
         os.println();
         os.println("/* Apache Tuscany scaDomain.js Header */");
         os.println();
-        
+
         writeJSONRPCJavaScript(os);
         writeScaDomainCode(os, request.getServletPath());
     }
@@ -69,16 +67,16 @@
         out.println("/* Apache Tuscany scaDomain.js Footer  */");
         out.println();
         out.println("function scaDomain() {}");
-        
+
         // remove the leading slash '/' character
         path = path.substring(1);
-        
+
         for (String serviceName : serviceNames) {
             out.println();
-            
+
             // A slight hack to make the service function available with a 
variable named 'serviceName'
-            // to do that the JSONRpcClient is added to the scaDomain and then 
the service function is got from that 
-            out.println("scaDomain." + serviceName + " = new JSONRpcClient(\"" 
+ path + SERVICE_PREFIX + serviceName +"\");");
+            // to do that the JSONRpcClient is added to the scaDomain and then 
the service function is got from that
+            out.println("scaDomain." + serviceName + " = " + "new 
JSONRpcClient(\"" + path + "/" + serviceName + "\");");
             out.println(serviceName + " = scaDomain." + serviceName + "." + 
serviceName + ";");
         }
 

Modified: 
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=568832&r1=568831&r2=568832&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
 Wed Aug 22 22:52:07 2007
@@ -52,7 +52,7 @@
 
     public void addServletMapping(String path, Servlet servlet) throws 
ServletMappingException {
         URI pathURI = URI.create(path);
-        
+
         // Ignore registrations of our default resource servlet, as resources
         // are already served by the web container
         if (servlet instanceof DefaultResourceServlet) {
@@ -62,26 +62,40 @@
             // in the web container that we are running in.
             return;
         }
-            
+
         // For webapps just use the path and ignore the host and port
-        servlets.put(pathURI.getPath(), servlet);
-        logger.info("addServletMapping: " + pathURI.getPath());
+        path = pathURI.getPath();
+        if (!path.startsWith("/")) {
+            path = '/' + path;
+        }
+        servlets.put(path, servlet);
+        logger.info("addServletMapping: " + path);
     }
 
     public Servlet removeServletMapping(String path) throws 
ServletMappingException {
         URI pathURI = URI.create(path);
+        path = pathURI.getPath();
+        if (!path.startsWith("/")) {
+            path = '/' + path;
+        }
         // for webapps just use the path and ignore the host and port
-        return servlets.remove(pathURI.getPath());
+        return servlets.remove(path);
     }
 
     public Servlet getServlet(String path) {
+        if (path == null) {
+            return null;
+        }
+        if (!path.startsWith("/")) {
+            path = '/' + path;
+        }
         Servlet servlet = servlets.get(path);
         if (servlet != null) {
             return servlet;
         }
         for (String servletPath : servlets.keySet()) {
             if (servletPath.endsWith("*")) {
-                if (path.startsWith(servletPath.substring(0, 
servletPath.length()-1))) { 
+                if (path.startsWith(servletPath.substring(0, 
servletPath.length() - 1))) {
                     return servlets.get(servletPath);
                 }
             }
@@ -92,7 +106,7 @@
     public static WebAppServletHost getInstance() {
         return instance;
     }
-    
+
     public void init(ServletConfig config) throws ServletException {
         for (Servlet servlet : servlets.values()) {
             servlet.init(config);



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to