Quantcast

[mule-scm] [mule][25319] branches/mule-3.x: Merged revisions 25312 via svnmerge from

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[mule-scm] [mule][25319] branches/mule-3.x: Merged revisions 25312 via svnmerge from

damian.bakarcic
[mule][25319] branches/mule-3.x: Merged revisions 25312 via svnmerge from
Revision
25319
Author
damian.bakarcic
Date
2013-02-28 09:43:46 -0600 (Thu, 28 Feb 2013)

Log Message

Merged revisions 25312 via svnmerge from 
https://svn.codehaus.org/mule/branches/mule-3.3.x

................
  r25312 | damian.bakarcic | 2013-02-27 13:06:40 -0300 (Wed, 27 Feb 2013) | 11 lines
  
  Merged revisions 25310 via svnmerge from 
  https://svn.codehaus.org/mule/branches/mule-3.2.x
  
  ........
    r25310 | damian.bakarcic | 2013-02-27 09:25:58 -0300 (Wed, 27 Feb 2013) | 5 lines
    
    MULE-6697: GZipTransformer does not support streaming
    
    - Added support for the GZipCompressTransformer and GZipUncompressTransformer to support compressing/decompressing streams respectively.
  ........
................

Modified Paths

Added Paths

Property Changed

Diff

Property changes: branches/mule-3.x


Modified: svnmerge-integrated

+ /branches/mule-3.3.x:1-24195,24197-24200,24202-24241,24243-24289,24294,24297,24299,24304,24310,24313,24316,24320,24323,24326-24327,24330-24332,24337,24340-24341,24352,24356,24359-24360,24364,24366,24368,24372,24374,24377-24379,24382,24385,24387,24392,24394,24397,24403-24436,24438-24439,24442,24445-24446,24448-24457,24468,24472,24478,24484,24488,24491,24496,24502-24503,24508,24512,24518,24522,24527,24531,24535,24540,24543,24549,24551,24553,24564,24572,24575,24579,24583,24588,24590,24593,24597,24601,24604,24607,24615,24621,24626,24629,24637,24639,24642-24691,24693,24695-24757,24759-24798,24800-24803,24805-24828,24830,24833,24836,24838,24843,24847,24854-24855,24887,24893-24894,24911,24916,24920,24931,24940,24942,24960,24963-24971,24977,24981-24982,24984,24991,25008,25016,25021,25024,25026-25028,25032,25040-25046,25055,25059,25065,25067,25069,25073-25079,25081-25082,25091,25100,25117,25120,25124,25148,25151,25157,25160,25186,25190,25197,25203,25209,25211,252 28,25237,25239,25241,25246-25247,25250,25254,25258,25278,25299,25303,25312,25316

Modified: svn:mergeinfo

/branches/mule-3.2.x:24203,24208,24237-24244,24246,24250,24256,24264,24276-24279,24293-24296,24319,24350,24355,24358,24363,24371,24376,24378,24381,24384,24389-24391,24404-24408,24415,24424,24434,24441,24467,24471,24477,24481,24483,24487,24526,24530,24534,24539,24542,24548,24571,24574,24578,24582,24587,24592,24596,24600,24603,24606,24613-24614,24617-24618,24620,24625,24628,24635-24636,24641,24650,24661,24666,24680-24681,24684,24686,24693,24695,24706,24719-24721,24724,24740,24743,24752-24753,24763,24768,24785-24786,24796,24832,24835,24841-24842,24846,24852,24875,24892,24897,24910,24915,24930,24957,24983,24990,25015,25030,25043,25064,25068,25072,25075,25077,25096,25156,25158,25185,25196,25202,25227,25233,25298,25313-25315 /branches/mule-3.3.x:24204,24209,24211-24214,24216-24218,24223-24224,24226,24231-24241,24245,24248,24257,24259-24265,24269-24284,24294,24297,24299,24304,24310,24313,24316,24320,24323,24326-24327,24330-24332,24337,24340-24341,24352,24356,24359-24360,24364,24366,24368,24372,24374,24377-24379,24382,24385,24387,24392,24394,24397,24403,24405-24407,24409-24410,24412-24413,24416-24418,24420,24422-24423,24425-24427,24430-24433,24435-24436,24438-24439,24442,24445-24446,24448,24450-24451,24453-24457,24468,24472,24478,24484,24488,24491,24496,24502,24508,24512,24518,24522,24527,24531,24535,24540,24543,24549,24551,24564,24572,24575,24579,24583,24588,24590,24593,24597,24601,24604,24607,24615,24621,24626,24629,24637,24639,24642-24646,24648,24651-24652,24655,24657-24658,24660,24663-24667,24669,24682,24685,24687,24690,24696,24698-24699,24702,24707,24714,24716-24718,24722,24725,24727-24738,24741,24744-24748,24750,24754-24755,24759-24760,24764,24769,24771,24773-24774,247 77,24780-24783,24787-24788,24791-24792,24794,24797,24801-24802,24806-24807,24824-24828,24830,24833,24836,24838,24843,24847,24854-24855,24887,24893-24894,24911,24916,24920,24931,24940,24942,24960,24963-24964,24966,24977,24981-24982,24984,24991,25008,25016,25021,25024,25026-25028,25032,25040-25041,25044,25046,25055,25059,25065,25067,25069,25073-25074,25076,25078-25079,25081-25082,25091,25100,25117,25124,25148,25151,25157,25160,25186,25197,25203,25211,25228,25237,25239,25241,25246-25247,25250,25254,25258,25278,25299,25303,25316 + /branches/mule-3.1.x:24202,24318,24349,24354,24362,24370,24388,24414,24466,24470,24482,24486,24525,24529,24533,24537-24538,24547,24570,24577,24586,24595,24599,24619,24623-24624,24634,24665,24677-24679,24705,24739,24742,24749-24751,24851,24874,24891,24914,24956,24980,24988-24989,25042,25063,25095,25195,25198,25225,25232,25294 /branches/mule-3.2.x:24203,24208,24237-24244,24246,24250,24256,24264,24276-24279,24293-24296,24319,24350,24355,24358,24363,24371,24376,24378,24381,24384,24389-24391,24404-24408,24415,24424,24434,24441,24467,24471,24477,24481,24483,24487,24526,24530,24534,24539,24542,24548,24571,24574,24578,24582,24587,24592,24596,24600,24603,24606,24613-24614,24617-24618,24620,24625,24628,24635-24636,24641,24650,24661,24666,24680-24681,24684,24686,24693,24695,24706,24719-24721,24724,24740,24743,24752-24753,24763,24768,24785-24786,24796,24832,24835,24841-24842,24846,24852,24875,24892,24897,24910,24915,24930,24957,24983,24990,25015,25030,25043,25064,25068,25072,25075,25077,25096,25156,25158,25185,25196,25202,25227,25233,25298,25310,25313-25315 /branches/mule-3.3.x:24204,24209,24211-24214,24216-24218,24223-24224,24226,24231-24241,24245,24248,24257,24259-24265,24269-24284,24294,24297,24299,24304,24310,24313,24316,24320,24323,24326-24327,24330-24332,24337,24340-24341,24352,24356,24359-24360,24364,24366,24368,24372,24374,24377-24379,24382,24385,24387,24392,24394,24397,24403,24405-24407,24409-24410,24412-24413,24416-24418,24420,24422-24423,24425-24427,24430-24433,24435-24436,24438-24439,24442,24445-24446,24448,24450-24451,24453-24457,24468,24472,24478,24484,24488,24491,24496,24502,24508,24512,24518,24522,24527,24531,24535,24540,24543,24549,24551,24564,24572,24575,24579,24583,24588,24590,24593,24597,24601,24604,24607,24615,24621,24626,24629,24637,24639,24642-24646,24648,24651-24652,24655,24657-24658,24660,24663-24667,24669,24682,24685,24687,24690,24696,24698-24699,24702,24707,24714,24716-24718,24722,24725,24727-24738,24741,24744-24748,24750,24754-24755,24759-24760,24764,24769,24771,24773-24774,247 77,24780-24783,24787-24788,24791-24792,24794,24797,24801-24802,24806-24807,24824-24828,24830,24833,24836,24838,24843,24847,24854-24855,24887,24893-24894,24911,24916,24920,24931,24940,24942,24960,24963-24964,24966,24977,24981-24982,24984,24991,25008,25016,25021,25024,25026-25028,25032,25040-25041,25044,25046,25055,25059,25065,25067,25069,25073-25074,25076,25078-25079,25081-25082,25091,25100,25117,25124,25148,25151,25157,25160,25186,25197,25203,25211,25228,25237,25239,25241,25246-25247,25250,25254,25258,25278,25299,25303,25312,25316

Modified: branches/mule-3.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java (25318 => 25319)


--- branches/mule-3.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java	2013-02-27 21:25:03 UTC (rev 25318)
+++ branches/mule-3.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -12,7 +12,6 @@
 
 import org.mule.api.transformer.TransformerException;
 import org.mule.transformer.types.DataTypeFactory;
-import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 import org.mule.util.compression.GZipCompression;
 
@@ -33,7 +32,8 @@
         this.registerSourceType(DataTypeFactory.create(Serializable.class));
         this.registerSourceType(DataTypeFactory.BYTE_ARRAY);
         this.registerSourceType(DataTypeFactory.INPUT_STREAM);
-        this.setReturnDataType(DataTypeFactory.BYTE_ARRAY);
+        // No type checking for the return type by default. It could either be a byte array or an input stream.
+        this.setReturnDataType(DataTypeFactory.OBJECT);
     }
 
     @Override
@@ -41,28 +41,23 @@
     {
         try
         {
-            byte[] data = null;
-            if (src instanceof byte[])
+            if (src instanceof InputStream)
             {
-                data = (byte[]) src;
+                return getStrategy().compressInputStream((InputStream) src);
             }
-            else if (src instanceof InputStream)
+            else
             {
-                InputStream input = (InputStream)src;
-                try
+                byte[] data;
+                if (src instanceof byte[])
                 {
-                    data = IOUtils.toByteArray(input);
+                    data = (byte[]) src;
                 }
-                finally
+                else
                 {
-                    input.close();
+                    data = SerializationUtils.serialize((Serializable) src);
                 }
+                return getStrategy().compressByteArray(data);
             }
-            else
-            {
-                data = SerializationUtils.serialize((Serializable) src);
-            }
-            return this.getStrategy().compressByteArray(data);
         }
         catch (IOException ioex)
         {

Modified: branches/mule-3.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java (25318 => 25319)


--- branches/mule-3.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java	2013-02-27 21:25:03 UTC (rev 25318)
+++ branches/mule-3.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -10,10 +10,10 @@
 
 package org.mule.transformer.compression;
 
+import org.mule.api.transformer.DataType;
 import org.mule.api.transformer.TransformerException;
 import org.mule.config.i18n.MessageFactory;
 import org.mule.transformer.types.DataTypeFactory;
-import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 import org.mule.util.compression.GZipCompression;
 
@@ -31,47 +31,37 @@
         this.setStrategy(new GZipCompression());
         this.registerSourceType(DataTypeFactory.BYTE_ARRAY);
         this.registerSourceType(DataTypeFactory.INPUT_STREAM);
-        this.setReturnDataType(DataTypeFactory.BYTE_ARRAY);
+        // No type checking for the return type by default. It could either be a byte array or an input stream.
+        this.setReturnDataType(DataTypeFactory.OBJECT);
     }
 
     @Override
     public Object doTransform(Object src, String outputEncoding) throws TransformerException
     {
-        byte[] buffer;
-
         try
         {
-            byte[] input = null;
             if (src instanceof InputStream)
             {
-                InputStream inputStream = (InputStream) src;
-                try
+                return getStrategy().uncompressInputStream((InputStream) src);
+            }
+            else
+            {
+                byte[] buffer = getStrategy().uncompressByteArray((byte[]) src);
+                DataType<?> returnDataType = getReturnDataType();
+                if (!DataTypeFactory.OBJECT.equals(returnDataType) && !DataTypeFactory.BYTE_ARRAY.equals(getReturnDataType()))
                 {
-                    input = IOUtils.toByteArray(inputStream);
+                    return SerializationUtils.deserialize(buffer, muleContext);
                 }
-                finally
+                else
                 {
-                    inputStream.close();
+                    return buffer;
                 }
             }
-            else
-            {
-                input = (byte[]) src;
-            }
-
-            buffer = getStrategy().uncompressByteArray(input);
         }
         catch (IOException e)
         {
             throw new TransformerException(
                     MessageFactory.createStaticMessage("Failed to uncompress message."), this, e);
         }
-
-        if (!DataTypeFactory.BYTE_ARRAY.equals(getReturnDataType()))
-        {
-            return SerializationUtils.deserialize(buffer, muleContext);
-        }
-
-        return buffer;
     }
 }

Modified: branches/mule-3.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java (25318 => 25319)


--- branches/mule-3.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java	2013-02-27 21:25:03 UTC (rev 25318)
+++ branches/mule-3.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -11,6 +11,7 @@
 package org.mule.util.compression;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 /**
  * <code>CompressionStrategy</code> is a base interface for Different compression
@@ -32,9 +33,48 @@
      */
     String SERVICE_ID = "META-INF/services/org.mule.util.compression.CompressionStrategy";
 
+    /**
+     * Compresses a byte array.
+     *
+     * @param bytes The byte array to compress.
+     * @return The compressed byte array.
+     * @throws IOException If an I/O error has occurred.
+     */
     byte[] compressByteArray(byte[] bytes) throws IOException;
 
+    /**
+     * Compresses an {@link InputStream}.
+     *
+     * @param is The {@link InputStream} to compress.
+     * @return The compressed {@link InputStream}.
+     * @throws IOException If an I/O error has occurred.
+     */
+    InputStream compressInputStream(InputStream is) throws IOException;
+
+    /**
+     * Uncompresses a compressed byte array.
+     *
+     * @param bytes The byte array to uncompress.
+     * @return The uncompressed byte array.
+     * @throws IOException If an I/O error has occurred.
+     */
     byte[] uncompressByteArray(byte[] bytes) throws IOException;
 
+    /**
+     * Uncompresses a compressed {@link InputStream}.
+     *
+     * @param is The compressed {@link InputStream}.
+     * @return The uncompressed {@link InputStream}.
+     * @throws IOException If an I/O error has occurred.
+     */
+    InputStream uncompressInputStream(InputStream is) throws IOException;
+
+    /**
+     * Checks whether a byte array has been compressed or not.
+     *
+     * @param bytes The byte array.
+     * @return True if the byte array is compressed, false otherwise.
+     * @throws IOException If an I/O error has occurred.
+     */
     boolean isCompressed(byte[] bytes) throws IOException;
 }

Copied: branches/mule-3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java (from rev 25312, branches/mule-3.3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java) (0 => 25319)


--- branches/mule-3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java	                        (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -0,0 +1,177 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.util.compression;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterInputStream;
+
+/**
+ * Implements an input stream for compressing input data in the GZIP compression format.
+ */
+public class GZIPCompressorInputStream extends DeflaterInputStream
+{
+    // GZIP header magic number.
+    private final static int GZIP_MAGIC = 0x8b1f;
+
+    // Writes GZIP member header.
+    private final static byte[] HEADER = {
+        (byte) GZIP_MAGIC,                // Magic number (short)
+        (byte)(GZIP_MAGIC >> 8),          // Magic number (short)
+        Deflater.DEFLATED,                // Compression method (CM)
+        0,                                // Flags (FLG)
+        0,                                // Modification time MTIME (int)
+        0,                                // Modification time MTIME (int)
+        0,                                // Modification time MTIME (int)
+        0,                                // Modification time MTIME (int)
+        0,                                // Extra flags (XFLG)
+        0                                 // Operating system (OS)
+    };
+
+    // Trailer length in bytes.
+    private final static int TRAILER_LENGTH = 8;
+
+    // If true, the GZIP trailer has been written.
+    private boolean trailerWritten = false;
+
+    // Internal buffer for GZIP header and trailer.
+    private Buffer buffer;
+
+    /**
+     * Helper inner class containing the length and position of the internal buffer.
+     */
+    private class Buffer
+    {
+        public byte[] data;
+        public int position;
+        public int length;
+
+        /**
+         * Creates a new buffer initializing it with the GZIP header content.
+         */
+        public Buffer()
+        {
+            data = new byte[Math.max(HEADER.length, TRAILER_LENGTH)];
+            System.arraycopy(HEADER, 0, data, 0, HEADER.length);
+            position = 0;
+            length = HEADER.length;
+        }
+
+        /**
+         * Returns the amount of bytes that are left to be read from the buffer.
+         *
+         * @return The byte counts to be read.
+         */
+        int getByteCountRemainder()
+        {
+            return length - position;
+        }
+    }
+
+    /**
+     * Creates a new {@link GZIPCompressorInputStream} from an uncompressed {@link InputStream}.
+     *
+     * @param in The uncompressed {@link InputStream}.
+     */
+    public GZIPCompressorInputStream(InputStream in)
+    {
+        super(new CheckedInputStream(in, new CRC32()), new Deflater(Deflater.DEFAULT_COMPRESSION, true));
+        buffer = new Buffer();
+    }
+
+    public int read(byte b[], int off, int len) throws IOException
+    {
+        // Check if there are bytes left to be read from the internal buffer. This is used to provide the header
+        // or trailer, and always takes precedence.
+        int count;
+        if (buffer.getByteCountRemainder() > 0)
+        {
+            // Write data from the internal buffer into b.
+            count = Math.min(len, buffer.getByteCountRemainder());
+            System.arraycopy(buffer.data, buffer.position, b, off, count);
+
+            // Advance the internal buffer position as "count" bytes have already been read.
+            buffer.position += count;
+            return count;
+        }
+
+        // Attempt to read compressed input data.
+        count = super.read(b, off, len);
+        if (count > 0)
+        {
+            return count;
+        }
+
+        /* If the stream has reached completion, write out the GZIP trailer and re-attempt
+         * the read */
+        if (count <= 0 && !trailerWritten)
+        {
+            buffer.position = 0;
+            buffer.length = writeTrailer(buffer.data, buffer.position);
+            trailerWritten = true;
+            return read(b, off, len);
+        }
+        else
+        {
+            return count;
+        }
+    }
+
+    /**
+     * Writes GZIP member trailer to a byte array, starting at a given offset.
+     *
+     * @param buf The buffer to write the trailer to.
+     * @param offset The offset from which to start writing.
+     * @return The amount of bytes that were written.
+     * @throws IOException If an I/O error is produced.
+     */
+    private int writeTrailer(byte[] buf, int offset) throws IOException
+    {
+        int count = writeInt((int) ((CheckedInputStream) this.in).getChecksum().getValue(), buf, offset); // CRC-32 of uncompr. data
+        count += writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes
+        return count;
+    }
+
+    /**
+     * Writes integer in Intel byte order to a byte array, starting at a given offset.
+     *
+     * @param i The integer to write.
+     * @param buf The buffer to write the integer to.
+     * @param offset The offset from which to start writing.
+     * @return The amount of bytes written.
+     * @throws IOException If an I/O error is produced.
+     */
+    private int writeInt(int i, byte[] buf, int offset) throws IOException
+    {
+        int count = writeShort(i & 0xffff, buf, offset);
+        count += writeShort((i >> 16) & 0xffff, buf, offset + 2);
+        return count;
+    }
+
+    /**
+     * Writes short integer in Intel byte order to a byte array, starting at a given offset.
+     *
+     * @param s The short to write.
+     * @param buf The buffer to write the integer to.
+     * @param offset The offset from which to start writing.
+     * @return The amount of bytes written.
+     * @throws IOException If an I/O error is produced.
+     */
+    private int writeShort(int s, byte[] buf, int offset) throws IOException
+    {
+        buf[offset] = (byte)(s & 0xff);
+        buf[offset + 1] = (byte)((s >> 8) & 0xff);
+        return 2;
+    }
+}

Modified: branches/mule-3.x/core/src/main/java/org/mule/util/compression/GZipCompression.java (25318 => 25319)


--- branches/mule-3.x/core/src/main/java/org/mule/util/compression/GZipCompression.java	2013-02-27 21:25:03 UTC (rev 25318)
+++ branches/mule-3.x/core/src/main/java/org/mule/util/compression/GZipCompression.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -12,6 +12,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 
@@ -115,6 +116,11 @@
         }
     }
 
+    public InputStream compressInputStream(InputStream is) throws IOException
+    {
+        return new GZIPCompressorInputStream(is);
+    }
+
     /**
      * Used for uncompressing a byte array into a uncompressed byte array using GZIP
      * 
@@ -185,4 +191,9 @@
         }
     }
 
+    public InputStream uncompressInputStream(InputStream is) throws IOException
+    {
+        return new GZIPInputStream(is);
+    }
+
 }

Modified: branches/mule-3.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java (25318 => 25319)


--- branches/mule-3.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java	2013-02-27 21:25:03 UTC (rev 25318)
+++ branches/mule-3.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -10,7 +10,11 @@
 
 package org.mule.transformer.compression;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import org.mule.api.transformer.TransformerException;
+import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 
 import java.io.ByteArrayInputStream;
@@ -19,23 +23,24 @@
 
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 public class GZipTransformerStreamTestCase extends GZipTransformerTestCase
 {
     
     @Test
     public void testStreamingCompression() throws TransformerException
     {
-        GZipCompressTransformer transformer = new GZipCompressTransformer();
+        GZipCompressTransformer transformer = (GZipCompressTransformer) super.getTransformer();
         
-        InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+        InputStream uncompressedInputStream = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
 
-        byte[] expected = (byte[]) this.getResultData();
-        byte[] result = (byte[]) transformer.transform(input);
-        
-        assertTrue(Arrays.equals(expected, result));
+        // Compress input data.
+        InputStream compressedInputStream = (InputStream) transformer.transform(uncompressedInputStream);
+
+        byte[] compressedBytes = (byte[]) getResultData();
+        assertTrue(Arrays.equals(compressedBytes, IOUtils.toByteArray(compressedInputStream)));
+
+        IOUtils.closeQuietly(uncompressedInputStream);
+        IOUtils.closeQuietly(compressedInputStream);
     }
 
     @Test
@@ -43,12 +48,37 @@
     {
         GZipUncompressTransformer transformer = new GZipUncompressTransformer();
         transformer.setMuleContext(muleContext);
-        
-        InputStream input = new ByteArrayInputStream((byte[]) this.getResultData());
-        byte[] resultBytes = (byte[]) transformer.transform(input);
-        assertEquals(TEST_DATA, SerializationUtils.deserialize(resultBytes));
+
+        InputStream compressedInputStream = new ByteArrayInputStream((byte[]) getResultData());
+
+        // Decompress the input data.
+        InputStream decompressedInputStream = (InputStream) transformer.transform(compressedInputStream);
+
+        assertEquals(TEST_DATA, SerializationUtils.deserialize(IOUtils.toByteArray(decompressedInputStream)));
+
+        IOUtils.closeQuietly(compressedInputStream);
+        IOUtils.closeQuietly(decompressedInputStream);
     }
 
+    @Test
+    public void testStreamingCompressionDecompression() throws TransformerException
+    {
+        GZipCompressTransformer compressTransformer = (GZipCompressTransformer) super.getTransformer();
+        GZipUncompressTransformer decompressTransformer = new GZipUncompressTransformer();
+        decompressTransformer.setMuleContext(muleContext);
+
+        InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+
+        // Compress the input data.
+        InputStream compressedInputStream = (InputStream) compressTransformer.transform(input);
+        // Decompress the input data.
+        InputStream decompressedInputStream = (InputStream) decompressTransformer.transform(compressedInputStream);
+
+        assertEquals(SerializationUtils.deserialize(IOUtils.toByteArray(decompressedInputStream)), TEST_DATA);
+
+        IOUtils.closeQuietly(compressedInputStream);
+        IOUtils.closeQuietly(decompressedInputStream);
+    }
 }
 
 

Copied: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java (from rev 25312, branches/mule-3.3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java) (0 => 25319)


--- branches/mule-3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java	                        (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java	2013-02-28 15:43:46 UTC (rev 25319)
@@ -0,0 +1,81 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+
+package org.mule.test.transformers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.mule.api.MuleMessage;
+import org.mule.module.client.MuleClient;
+import org.mule.tck.junit4.FunctionalTestCase;
+import org.mule.util.IOUtils;
+import org.mule.util.SerializationUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.junit.Test;
+
+/**
+ * Functional test case for the GZipCompressTransformer and GZipUncompressTransformer.
+ */
+public class GZipTransformerFunctionalTestCase extends FunctionalTestCase
+{
+    private static final String TEST_DATA = "the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog";
+
+    @Override
+    protected String getConfigResources()
+    {
+        return "org/mule/test/transformers/gzip-transformer-functional-test.xml";
+    }
+
+    @Test
+    public void testCompressDecompressByteArray() throws Exception
+    {
+        byte[] testDataByteArray = SerializationUtils.serialize(TEST_DATA);
+        MuleClient client = new MuleClient(muleContext);
+
+        // Compress input.
+        MuleMessage compressedResponse = client.send("vm://compressInput", testDataByteArray, null);
+        assertNotNull(compressedResponse);
+        assertTrue(compressedResponse.getPayload() instanceof byte[]);
+
+        // Decompress response.
+        MuleMessage uncompressedResponse = client.send("vm://decompressInput", compressedResponse.getPayload(), null);
+        assertNotNull(uncompressedResponse);
+        assertTrue(uncompressedResponse.getPayload() instanceof byte[]);
+
+        String uncompressedStr = (String) SerializationUtils.deserialize((byte[]) uncompressedResponse.getPayload());
+        assertEquals(TEST_DATA, uncompressedStr);
+    }
+
+    @Test
+    public void testCompressDecompressInputStream() throws Exception
+    {
+        ByteArrayInputStream bis = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+        MuleClient client = new MuleClient(muleContext);
+
+        // Compress input.
+        MuleMessage compressedResponse = client.send("vm://compressInput", bis, null);
+        assertNotNull(compressedResponse);
+        assertTrue(compressedResponse.getPayload() instanceof InputStream);
+
+        // Decompress response.
+        MuleMessage uncompressedResponse = client.send("vm://decompressInput", compressedResponse.getPayload(), null);
+        assertNotNull(uncompressedResponse);
+        assertTrue(uncompressedResponse.getPayload() instanceof InputStream);
+
+        byte[] uncompressedByteArray = IOUtils.toByteArray((InputStream) uncompressedResponse.getPayload());
+        String uncompressedStr = (String) SerializationUtils.deserialize(uncompressedByteArray);
+        assertEquals(TEST_DATA, uncompressedStr);
+    }
+}

Copied: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml (from rev 25312, branches/mule-3.3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml) (0 => 25319)


--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml	                        (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml	2013-02-28 15:43:46 UTC (rev 25319)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
+      xsi:schemaLocation="
+          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+          http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd">
+
+    <flow name="compressInput">
+        <vm:inbound-endpoint path="compressInput" exchange-pattern="request-response"/>
+        <gzip-compress-transformer/>
+    </flow>
+
+    <flow name="decompressInput">
+        <vm:inbound-endpoint path="decompressInput" exchange-pattern="request-response"/>
+        <gzip-uncompress-transformer/>
+    </flow>
+
+</mule>

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Loading...