You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/05/01 01:26:18 UTC

svn commit: r939874 - in /tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src: main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/ main/java/org/apache/tuscany/sca/binding/rest/provider/ main/java/org/apache/tuscany/...

Author: rfeng
Date: Fri Apr 30 23:26:18 2010
New Revision: 939874

URL: http://svn.apache.org/viewvc?rev=939874&view=rev
Log:
Add basic support for binary data types for binding.rest

Added:
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/binary.composite
Modified:
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java
    tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java?rev=939874&r1=939873&r2=939874&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java Fri Apr 30 23:26:18 2010
@@ -19,10 +19,17 @@
 
 package org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.net.URLDecoder;
 import java.util.List;
 
+import javax.activation.DataSource;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -49,22 +56,22 @@ import org.apache.tuscany.sca.runtime.Ru
 public class JAXRSOperationSelectorInterceptor implements Interceptor {
     private ExtensionPointRegistry extensionPoints;
     private RuntimeEndpoint endpoint;
-    
+
     private RuntimeComponentService service;
     private InterfaceContract interfaceContract;
     private List<Operation> serviceOperations;
-    
+
     private Invoker next;
 
     public JAXRSOperationSelectorInterceptor(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) {
         this.extensionPoints = extensionPoints;
         this.endpoint = endpoint;
-        
+
         this.service = (RuntimeComponentService)endpoint.getService();
         this.interfaceContract = service.getInterfaceContract();
         this.serviceOperations = service.getInterfaceContract().getInterface().getOperations();
     }
-    
+
     public Invoker getNext() {
         return next;
     }
@@ -75,35 +82,122 @@ public class JAXRSOperationSelectorInter
 
     public Message invoke(Message msg) {
         try {
-            HTTPContext bindingContext = (HTTPContext) msg.getBindingContext();
+            HTTPContext bindingContext = (HTTPContext)msg.getBindingContext();
 
             String path = URLDecoder.decode(HTTPUtil.getRequestPath(bindingContext.getHttpRequest()), "UTF-8");
-            
-            if(path.startsWith("/")) {
+
+            if (path.startsWith("/")) {
                 path = path.substring(1);
             }
 
-            List<Operation> operations = filterOperationsByHttpMethod(interfaceContract, bindingContext.getHttpRequest().getMethod());
+            List<Operation> operations =
+                filterOperationsByHttpMethod(interfaceContract, bindingContext.getHttpRequest().getMethod());
 
             Operation operation = findOperation(path, operations);
 
-            final JavaOperation javaOperation = (JavaOperation) operation;
+            final JavaOperation javaOperation = (JavaOperation)operation;
             final Method method = javaOperation.getJavaMethod();
-            
-            if(path != null && path.length() > 0) {
-                if(method.getAnnotation(Path.class) != null) {
-                    msg.setBody(new Object[]{path});
+
+            if (path != null && path.length() > 0) {
+                if (method.getAnnotation(Path.class) != null) {
+                    msg.setBody(new Object[] {path});
                 }
             }
-            
+
+            // FIXME: [rfeng] We should follow JAX-RS rules to identify the entity parameter
+            Class<?>[] paramTypes = method.getParameterTypes();
+            if (paramTypes.length == 1) {
+                Class<?> type = paramTypes[0];
+                InputStream is = (InputStream)((Object[])msg.getBody())[0];
+                Object target = convert(is, bindingContext.getHttpRequest().getContentType(), type);
+                msg.setBody(new Object[] {target});
+            } else if (paramTypes.length == 0) {
+                msg.setBody(null);
+            }
+
             msg.setOperation(operation);
 
             return getNext().invoke(msg);
-        } catch(Exception e) {
+        } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
+    private Object convert(InputStream content, String contentType, Class<?> type) {
+        if (type == DataSource.class) {
+            return type.cast(new InputStreamDataSource(content, contentType));
+        } else if (type == InputStream.class) {
+            return type.cast(content);
+        } else if (type == String.class) {
+            try {
+                StringWriter sw = new StringWriter();
+                InputStreamReader reader = new InputStreamReader(content, "UTF-8");
+                char[] buf = new char[8192];
+                while (true) {
+                    int size = reader.read(buf);
+                    if (size < 0) {
+                        break;
+                    }
+                    sw.write(buf, 0, size);
+                }
+                return type.cast(sw.toString());
+            } catch (Exception e) {
+                throw new IllegalArgumentException(e);
+            }
+        } else if (type == byte[].class) {
+            try {
+                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                byte[] buf = new byte[8192];
+                while (true) {
+                    int size = content.read(buf);
+                    if (size < 0) {
+                        break;
+                    }
+                    bos.write(buf, 0, size);
+                }
+                return type.cast(bos.toByteArray());
+            } catch (Exception e) {
+                throw new IllegalArgumentException(e);
+            }
+        } else {
+            return content;
+        }
+    }
+    
+    public static final class InputStreamDataSource implements DataSource {
+
+        public static final String DEFAULT_TYPE = "application/octet-stream";
+
+        private final InputStream in;
+        private final String ctype;
+
+        public InputStreamDataSource(InputStream in) {
+            this(in, null);
+        }
+
+        public InputStreamDataSource(InputStream in, String ctype) {
+            this.in = in;
+            this.ctype = (ctype != null) ? ctype : DEFAULT_TYPE;
+        }
+
+        public String getContentType() {
+            return ctype;
+        }
+
+        public String getName() {
+            return null;
+        }
+
+        public InputStream getInputStream() throws IOException {
+            return in;
+        }
+
+        public OutputStream getOutputStream() throws IOException {
+            return null;
+        }
+
+    }
+
     /**
      * Find the operation from the component service contract
      * @param componentService
@@ -112,20 +206,20 @@ public class JAXRSOperationSelectorInter
      */
     private static List<Operation> filterOperationsByHttpMethod(InterfaceContract interfaceContract, String http_method) {
         List<Operation> operations = null;
-        
-        if(http_method.equalsIgnoreCase("get")) {
-            operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(GET.class);
-        }else if(http_method.equalsIgnoreCase("put")) {
-            operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(PUT.class);
-        }else if(http_method.equalsIgnoreCase("post")) {
-            operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(POST.class);
-        }else if(http_method.equalsIgnoreCase("delete")) {
-            operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(DELETE.class);
+
+        if (http_method.equalsIgnoreCase("get")) {
+            operations = (List<Operation>)interfaceContract.getInterface().getAttributes().get(GET.class);
+        } else if (http_method.equalsIgnoreCase("put")) {
+            operations = (List<Operation>)interfaceContract.getInterface().getAttributes().get(PUT.class);
+        } else if (http_method.equalsIgnoreCase("post")) {
+            operations = (List<Operation>)interfaceContract.getInterface().getAttributes().get(POST.class);
+        } else if (http_method.equalsIgnoreCase("delete")) {
+            operations = (List<Operation>)interfaceContract.getInterface().getAttributes().get(DELETE.class);
         }
-        
+
         return operations;
     }
-    
+
     /**
      * Find the operation from the component service contract
      * @param componentService
@@ -134,24 +228,24 @@ public class JAXRSOperationSelectorInter
      */
     private Operation findOperation(String path, List<Operation> operations) {
         Operation operation = null;
-        
-        for(Operation op : operations) {
-            final JavaOperation javaOperation = (JavaOperation) op;
+
+        for (Operation op : operations) {
+            final JavaOperation javaOperation = (JavaOperation)op;
             final Method method = javaOperation.getJavaMethod();
-            
-            if(path != null && path.length() > 0) {
-                if(method.getAnnotation(Path.class) != null) {
+
+            if (path != null && path.length() > 0) {
+                if (method.getAnnotation(Path.class) != null) {
                     operation = op;
                     break;
                 }
             } else {
-                if(method.getAnnotation(Path.class) == null) {
+                if (method.getAnnotation(Path.class) == null) {
                     operation = op;
                     break;
                 }
             }
         }
-        
+
         return operation;
     }
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java?rev=939874&r1=939873&r2=939874&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java Fri Apr 30 23:26:18 2010
@@ -19,11 +19,8 @@
 
 package org.apache.tuscany.sca.binding.rest.provider;
 
-import java.io.BufferedReader;
-import java.io.CharArrayWriter;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.URLDecoder;
 import java.text.ParseException;
@@ -74,10 +71,32 @@ public class RESTBindingListenerServlet 
         this.messageFactory = messageFactory;
     }
 
+    private void write(OutputStream out, Object obj) throws IOException {
+        if (obj == null) {
+            return;
+        }
+        if (obj instanceof String) {
+            out.write(((String)obj).getBytes("UTF-8"));
+        } else if (obj instanceof byte[]) {
+            out.write((byte[])obj);
+        } else if (obj instanceof InputStream) {
+            byte[] buf = new byte[8192];
+            InputStream in = (InputStream)obj;
+            while (true) {
+                int size = in.read(buf);
+                if (size < 0) {
+                    break;
+                }
+                out.write(buf, 0, size);
+            }
+        } else {
+            out.write(obj.toString().getBytes("UTF-8"));
+        }
+    }
     
     @Override
     protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-        if( binding.getOperationSelector() != null && binding.getRequestWireFormat() != null) {
+        if( binding.getOperationSelector() != null || binding.getRequestWireFormat() != null) {
             // Decode using the charset in the request if it exists otherwise
             // use UTF-8 as this is what all browser implementations use.
             String charset = request.getCharacterEncoding();
@@ -85,6 +104,7 @@ public class RESTBindingListenerServlet 
                 charset = "UTF-8";
             }
 
+            /*
             BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset));
 
             // Read the request
@@ -94,6 +114,7 @@ public class RESTBindingListenerServlet 
             while ((ret = in.read(buf, 0, 4096)) != -1) {
                 data.write(buf, 0, ret);
             }
+            */
             
             HTTPContext bindingContext = new HTTPContext();
             bindingContext.setHttpRequest(request);
@@ -102,9 +123,14 @@ public class RESTBindingListenerServlet 
             // Dispatch the service interaction to the service invoker
             Message requestMessage = messageFactory.createMessage();
             requestMessage.setBindingContext(bindingContext);
+            
+            requestMessage.setBody(new Object[] {request.getInputStream()});
+            
+            /*
             if(data.size() > 0) {
                 requestMessage.setBody(new Object[]{data});
             }
+            */
             
             Message responseMessage = bindingInvoker.invoke(requestMessage);
             
@@ -116,13 +142,9 @@ public class RESTBindingListenerServlet 
                 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
             } else {
                 //handle void operations
-                if(responseMessage.getBody() != null) {
-                    byte[] bout;
-                    bout = responseMessage.<Object>getBody().toString().getBytes("UTF-8");
-                    response.getOutputStream().write(bout);
-                    response.getOutputStream().flush();
-                    response.getOutputStream().close();                    
-                }
+                write(response.getOutputStream(), responseMessage.getBody());
+                response.getOutputStream().flush();
+                response.getOutputStream().close();                  
             } 
         } else {
             super.service(request, response);

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java?rev=939874&r1=939873&r2=939874&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java Fri Apr 30 23:26:18 2010
@@ -19,7 +19,10 @@
 
 package org.apache.tuscany.sca.binding.rest.wireformat.json.provider;
 
-import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringWriter;
 
 import org.apache.tuscany.sca.common.http.HTTPContext;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
@@ -48,6 +51,20 @@ public class JSONWireFormatInterceptor i
     public void setNext(Invoker next) {
         this.next = next;
     }
+    
+    private String read(InputStream in) throws IOException {
+        StringWriter sw = new StringWriter();
+        InputStreamReader reader = new InputStreamReader(in, "UTF-8");
+        char[] buf = new char[8192];
+        while (true) {
+            int size = reader.read(buf);
+            if (size < 0) {
+                break;
+            }
+            sw.write(buf, 0, size);
+        }
+        return sw.toString();
+    }
 
     public Message invoke(Message msg) {
         HTTPContext bindingContext = (HTTPContext) msg.getBindingContext();
@@ -55,9 +72,9 @@ public class JSONWireFormatInterceptor i
         try {
             if(bindingContext.getHttpRequest().getMethod().equalsIgnoreCase("get") == false && bindingContext.getHttpRequest().getMethod().equalsIgnoreCase("delete") == false  && msg.getBody() != null) {
                 Object[] args = msg.getBody();
-                CharArrayWriter data = (CharArrayWriter) args[0];
-                
-                JSONObject jsonPayload = new JSONObject(data.toString());
+                InputStream in = (InputStream) args[0];
+                String data = read(in);
+                JSONObject jsonPayload = new JSONObject(data);
                 msg.setBody(new Object[]{jsonPayload});
             }
         } catch(Exception e) {

Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java?rev=939874&r1=939873&r2=939874&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatInterceptor.java Fri Apr 30 23:26:18 2010
@@ -19,8 +19,7 @@
 
 package org.apache.tuscany.sca.binding.rest.wireformat.xml.provider;
 
-import java.io.CharArrayReader;
-import java.io.CharArrayWriter;
+import java.io.InputStream;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamReader;
@@ -59,8 +58,8 @@ public class XMLWireFormatInterceptor im
         try {
             if(msg.getBody() != null) {
                 Object[] args = msg.getBody();
-                CharArrayWriter data = (CharArrayWriter) args[0];
-                XMLStreamReader xmlPayload = inputFactory.createXMLStreamReader(new CharArrayReader(data.toCharArray()));
+                InputStream data = (InputStream) args[0];
+                XMLStreamReader xmlPayload = inputFactory.createXMLStreamReader(data);
                 msg.setBody(new Object[]{xmlPayload});
             }
         } catch(Exception e) {

Added: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java?rev=939874&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/binary/BinaryServiceTestCase.java Fri Apr 30 23:26:18 2010
@@ -0,0 +1,106 @@
+/*
+ * 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.sca.binding.rest.wireformat.binary;
+
+import java.io.ByteArrayInputStream;
+import java.net.Socket;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.PostMethodWebRequest;
+import com.meterware.httpunit.PutMethodWebRequest;
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+public class BinaryServiceTestCase {
+    private static final String SERVICE_URL = "http://localhost:8085/Binary";
+
+    private static final String CONTENT = "ABCDefgh";
+    private static final String UPDATED_CONTENT = "abcdEFGH";
+
+    private static Node node;
+
+    @BeforeClass
+    public static void init() throws Exception {
+        try {
+            String contribution = ContributionLocationHelper.getContributionLocation(BinaryServiceTestCase.class);
+            node = NodeFactory.newInstance().createNode("binary.composite", new Contribution("binary", contribution));
+            node.start();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @AfterClass
+    public static void destroy() throws Exception {
+        if (node != null) {
+            node.stop();
+        }
+    }
+
+    @Test
+    public void testPing() throws Exception {
+        new Socket("127.0.0.1", 8085);
+        //System.in.read();
+    }
+
+    @Test
+    public void testMethods() throws Exception {
+        WebConversation wc = new WebConversation();
+
+        // Create content
+        WebRequest request =
+            new PostMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(CONTENT.getBytes("UTF-8")),
+                                     "application/octet-stream");
+        WebResponse response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+        
+        // Read the content
+        request = new GetMethodWebRequest(SERVICE_URL);
+        response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+        Assert.assertEquals(CONTENT, response.getText());
+
+        request =
+            new PutMethodWebRequest(SERVICE_URL, new ByteArrayInputStream(UPDATED_CONTENT.getBytes("UTF-8")),
+                                     "application/octet-stream");
+        response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+
+        //read new results and expect to get new item back in the response
+        request = new GetMethodWebRequest(SERVICE_URL);
+        response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+        Assert.assertEquals(UPDATED_CONTENT, response.getText());
+    }
+}

Added: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java?rev=939874&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryService.java Fri Apr 30 23:26:18 2010
@@ -0,0 +1,45 @@
+/*
+ * 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 services.binary;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.activation.DataSource;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * 
+ */
+@Remotable
+public interface BinaryService {
+    @GET
+    InputStream get();
+    
+    @PUT
+    void update(InputStream is) throws IOException;
+    
+    @POST
+    void create(DataSource dataSource) throws IOException;
+}

Added: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java?rev=939874&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/binary/BinaryServiceImpl.java Fri Apr 30 23:26:18 2010
@@ -0,0 +1,57 @@
+/*
+ * 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 services.binary;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.activation.DataSource;
+
+import org.oasisopen.sca.annotation.Scope;
+
+/**
+ * 
+ */
+@Scope("COMPOSITE")
+public class BinaryServiceImpl implements BinaryService {
+    private byte[] content;
+    private int length;
+
+    public void create(DataSource dataSource) throws IOException {
+        content = new byte[10240];
+        InputStream is = dataSource.getInputStream();
+        length = is.read(content);
+        System.out.println("Content received: " + length);
+    }
+
+    public InputStream get() {
+        byte[] bytes = new byte[length];
+        System.arraycopy(content, 0, bytes, 0, length);
+        System.out.println("Content sent: " + length);
+        return new ByteArrayInputStream(bytes);
+    }
+
+    public void update(InputStream is) throws IOException {
+        length = is.read(content);
+        System.out.println("Content updated: " + length);
+    }
+
+}

Added: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/binary.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/binary.composite?rev=939874&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/binary.composite (added)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/binary.composite Fri Apr 30 23:26:18 2010
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite	xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+		xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+		targetNamespace="http://binary"
+		name="Binary">
+		
+	<component name="BinaryService">
+		<implementation.java class="services.binary.BinaryServiceImpl"/> 
+		<service name="BinaryService">
+			<tuscany:binding.rest uri="http://localhost:8085/Binary">
+			    <tuscany:operationSelector.jaxrs />
+    		</tuscany:binding.rest>
+   		</service>
+	</component>
+</composite>