tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r1350974 - in /tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime: pom.xml src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
Date Sat, 16 Jun 2012 18:13:58 GMT
Author: lresende
Date: Sat Jun 16 18:13:58 2012
New Revision: 1350974

URL: http://svn.apache.org/viewvc?rev=1350974&view=rev
Log:
Enhancing widget invoker to handled more details of what resource is being requested. This
logic was present on a specific servlet from the binding, but makes more sense to be together
with the widget implementation

Modified:
    tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/pom.xml
    tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/pom.xml?rev=1350974&r1=1350973&r2=1350974&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/pom.xml Sat Jun 16 18:13:58
2012
@@ -50,18 +50,58 @@
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-common-http</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-host-http</artifactId>
             <version>2.0-SNAPSHOT</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-binding-http</artifactId>
+            <version>2.0-SNAPSHOT</version>
+        </dependency>
+        
        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <version>2.5</version> <!-- to keep compatible with older servlet
containers --> 
             <scope>provided</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-node-impl</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-java-runtime</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-host-jetty</artifactId>
+            <version>2.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
         
         <dependency>
+	        <groupId>httpunit</groupId>
+	        <artifactId>httpunit</artifactId>
+	        <version>1.7</version>
+	        <scope>test</scope>
+        </dependency>
+                
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.8.1</version>

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java?rev=1350974&r1=1350973&r2=1350974&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget-runtime/src/main/java/org/apache/tuscany/sca/implementation/widget/provider/WidgetImplementationInvoker.java
Sat Jun 16 18:13:58 2012
@@ -23,10 +23,16 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLDecoder;
 
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
 import org.apache.tuscany.sca.invocation.Invoker;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
@@ -54,18 +60,33 @@ class WidgetImplementationInvoker implem
     }
     
     public Message invoke(Message msg) {
+        HTTPContext bindingContext = (HTTPContext) msg.getBindingContext();
+        HttpServletRequest request = bindingContext.getHttpRequest();
+
+
+        // Get the request path
+        String pathInfo = request.getPathInfo();
+        String path = null;
         
+        if(pathInfo != null) {
+            try {
+                path = URLDecoder.decode(pathInfo, "UTF-8");
+            } catch (UnsupportedEncodingException uee) {
+                //ignore for now
+            }            
+        }
+
         // Get the resource id from the request message
-    	
-        String id = msg.getBody() == null ? "" : (String)((Object[])msg.getBody())[0];
+        String id = path == null ? "" : path.substring(1);
         try {
             
             if (id.length() == 0) {
 
                 // Return an input stream for the widget resource
                 URL url = new URL(widgetLocationURL);
-                InputStream is = url.openStream();
-                msg.setBody(is);
+                //InputStream is = url.openStream();
+                //msg.setBody(is);
+                writeResponse(bindingContext, url.openStream());
                 
             } else if (id.equals(widgetName)) {
                 
@@ -77,7 +98,8 @@ class WidgetImplementationInvoker implem
                 
                 InputStream is = new ByteArrayInputStream(bos.toByteArray());
                 
-                msg.setBody(is);
+                //msg.setBody(is);
+                writeResponse(bindingContext, is);
                 
             } else {
 
@@ -85,7 +107,8 @@ class WidgetImplementationInvoker implem
                 // widget folder
                 URL url = new URL(widgetFolderURL +'/' + id);
                 InputStream is = url.openStream();
-                msg.setBody(is);
+                //msg.setBody(is);
+                writeResponse(bindingContext, is);
             }
         } catch (MalformedURLException e) {
 
@@ -99,4 +122,23 @@ class WidgetImplementationInvoker implem
         }
         return msg;
     }
+    
+    /**
+     * Write the widget response to the http response outputstream
+     * @param bindingContext
+     * @param is
+     * @throws IOException 
+     */
+    private static void writeResponse(HTTPContext bindingContext, InputStream is) throws
IOException {
+        OutputStream os = bindingContext.getHttpResponse().getOutputStream();
+        byte[] buffer = new byte[2048];
+        for (;;) {
+            int n = is.read(buffer);
+            if (n <= 0)
+                break;
+            os.write(buffer, 0, n);
+        }
+        os.flush();
+        os.close();        
+    }
 }



Mime
View raw message