Index: src/java/org/fluidproject/kettle/ResourceUtil.java
===================================================================
--- src/java/org/fluidproject/kettle/ResourceUtil.java	(revision 8506)
+++ src/java/org/fluidproject/kettle/ResourceUtil.java	(working copy)
@@ -29,6 +29,12 @@
 import uk.org.ponder.streamutil.StreamCopyUtil;
 import uk.org.ponder.util.UniversalRuntimeException;
 
+/**
+ * A class of utilities useful for dealing with data streams and JSON values in the 
+ * Kettle environment. This is a temporary piece of infrastructure pending the
+ * abandonment of a Java-based Javascript environment. 
+ */
+
 public class ResourceUtil {
     public static boolean booleanValue(Object totest) {
         if (totest == null) return false;
@@ -96,12 +102,37 @@
         }
         catch (Exception e) {
             System.err.print("Error writing response: " + e.getMessage());
+            e.printStackTrace(System.err);
         }
         finally {
             StreamCloseUtil.closeOutputStream(os);
         }
     }
-
+    
+    /** Copy an input to output stream using a fixed-sized buffer, and guarantee to close
+     * both streams.
+     */
+    public static void copyStream(InputStream is, OutputStream os) {
+        StreamCopyUtil.inputToOutput(is, os, true, true, null);
+    }
+    
+    /** Copy a String to output using UTF-8, guarantees to close the stream. Exceptions
+     * will be propagated.
+     */
+    
+    public static void copyString(String tosend, OutputStream os) {
+        try {
+            String s = tosend.toString();
+            os.write(s.getBytes("UTF-8"));
+        }
+        catch (Exception e) {
+            throw UniversalRuntimeException.accumulate(e, "Error copying to output");
+        }
+        finally {
+            StreamCloseUtil.closeOutputStream(os);
+        }
+    }
+    
     public static void sendFile(File tosend, OutputStream os) {
         try {
             InputStream is = new FileInputStream(tosend);
Index: src/webapp/kettle/js/env.js
===================================================================
--- src/webapp/kettle/js/env.js	(revision 8506)
+++ src/webapp/kettle/js/env.js	(working copy)
@@ -689,6 +689,7 @@
 					var connection = url.openConnection();
 					
 					connection.setRequestMethod( self.method );
+					connection.setDoOutput(true); // PATCH: Sveto/AMB
 					
 					// Add headers to Java connection
 					for (var header in self.headers)
@@ -696,6 +697,14 @@
 				
 					connection.connect();
 					
+          // PATCH: Sveto/AMB               
+          text = new java.lang.String( data || "" )                   
+          if (text.length() > 0) {
+              // Write content to the connection's stream
+              var out = connection.getOutputStream();
+              Packages.org.fluidproject.kettle.ResourceUtil.copyString(text, out);
+          }
+					
 					// Stick the response headers into responseHeaders
 					for (var i = 0; ; i++) { 
 						var headerName = connection.getHeaderFieldKey(i); 
@@ -717,21 +726,14 @@
 						stream = (contentEncoding.equalsIgnoreCase("gzip") || contentEncoding.equalsIgnoreCase("decompress") )?
        							new java.util.zip.GZIPInputStream(connection.getInputStream()) :
        							connection.getInputStream(),
-						baos = new java.io.ByteArrayOutputStream(),
-       						buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024),
-						length,
-						responseXML = null;
+						baos = new java.io.ByteArrayOutputStream();
+						
+          Packages.org.fluidproject.kettle.ResourceUtil.copyStream(stream, baos);
 
-					while ((length = stream.read(buffer)) != -1) {
-						baos.write(buffer, 0, length);
-					}
-
-					baos.close();
-					stream.close();
-
 					self.responseText = java.nio.charset.Charset.forName(contentEncoding)
 						.decode(java.nio.ByteBuffer.wrap(baos.toByteArray())).toString();
 					
+					var responseXML = null;
 					self.__defineGetter__("responseXML", function(){
 						return responseXML;
 					});
