royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosrov...@apache.org
Subject [royale-asjs] branch develop updated: Update SampleAmfWebApp to include a java adapter that perfoms compression of AMF data and use it in conjuntion with the new CompressedRemoteObject in Royale that is capable to inflate the data on the client
Date Sun, 20 May 2018 12:00:43 GMT
This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 16231b1  Update SampleAmfWebApp to include a java adapter that perfoms compression
of AMF data and use it in conjuntion with the new CompressedRemoteObject in Royale that is
capable to inflate the data on the client
16231b1 is described below

commit 16231b1fac8f3d6968474500058bebff29bd515f
Author: Carlos Rovira <carlosrovira@apache.org>
AuthorDate: Sun May 20 14:00:38 2018 +0200

    Update SampleAmfWebApp to include a java adapter that perfoms compression of AMF data
and use it in conjuntion with the new CompressedRemoteObject in Royale that is capable to
inflate the data on the client
---
 .../amfsamples/BlazeDSSpringBootApplication.java   |  21 ++-
 .../amfsamples/services/CompressedService.java     |  80 ++++++++++
 .../amf/adapter/AMFByteArrayCompressor.java        |  95 +++++++++++
 .../remoting/amf/adapter/AMFCompressionError.java} |  31 ++--
 .../amf/adapter/AMFCompressionException.java}      |  37 +++--
 .../remoting/amf/adapter/AMFCompressorAdapter.java | 173 +++++++++++++++++++++
 .../remoting/amf/adapter/ByteArrayCompressor.java  |  81 ++++++++++
 .../resources/META-INF/flex/services-config.xml    |   3 +
 .../RemoteObjectAMFTest/src/main/royale/App.mxml   |  15 +-
 9 files changed, 510 insertions(+), 26 deletions(-)

diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
index af660fd..a637ae0 100644
--- a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
@@ -23,13 +23,32 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 
+import flex.messaging.MessageBroker;
+import flex.messaging.config.ConfigMap;
+import flex.messaging.services.ServiceAdapter;
+import flex.messaging.services.remoting.RemotingDestination;
+
 @SpringBootApplication
 @ServletComponentScan("org.apache.royale.amfsamples")
 public class BlazeDSSpringBootApplication {
 
     public static void main(String[] args) {
+
+        //BlazeDS normal application setup
         SpringApplication application = new SpringApplication(BlazeDSSpringBootApplication.class);
         application.run(args);
-    }
 
+        // makes "compressedService" uses "compressed-java-object" adapter that performs
compression on AMF data
+        // this can be done usgin spring xml with <flex:remoting-service default-adapter-id="the-compression-adapter"/>
+        MessageBroker messageBroker = MessageBroker.getMessageBroker("_messageBroker");
+        RemotingDestination destination = RemotingDestination.getRemotingDestination("_messageBroker",
"compressedService");
+
+        ConfigMap serviceAdapterConfig = new ConfigMap();
+        serviceAdapterConfig.addProperty("include-packages", "org.apache.royale.");
+
+        ServiceAdapter serviceAdapter = destination.createAdapter("compressed-java-object");
+        serviceAdapter.initialize("compressed-java-object", serviceAdapterConfig);
+
+        destination.setAdapter(serviceAdapter);
+    }
 }
diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/services/CompressedService.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/services/CompressedService.java
new file mode 100644
index 0000000..a5e41c4
--- /dev/null
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/services/CompressedService.java
@@ -0,0 +1,80 @@
+/*
+ *
+ *  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.royale.amfsamples.services;
+
+import org.apache.royale.amfsamples.valueobjects.ServerCustomType;
+import org.apache.royale.amfsamples.valueobjects.Product;
+import org.apache.royale.amfsamples.valueobjects.Taxonomy;
+import org.apache.royale.amfsamples.valueobjects.Zone;
+import org.springframework.flex.remoting.RemotingDestination;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+@Service("compressedService")
+@RemotingDestination
+public class CompressedService {
+
+    public Product getSomeCompressedProduct()
+    {
+        System.out.println("getSomeCompressedProduct called");
+
+        Product product = new Product();
+        product.setName("Some compressed product");
+        product.setDescription("This compressed product is only a test typed value object
to test AMF strong types");
+        
+        Taxonomy taxonomy = new Taxonomy();
+        taxonomy.setType("a type");
+        taxonomy.setDescription("a taxonomy for this compressed product");
+
+        product.setTaxonomy(taxonomy);
+
+        Object[] zones = new Object[3];
+        for (int i = 0; i < zones.length; i++)
+        {
+            Zone zone = new Zone();
+            zone.setId(i);
+            if (i == 0)
+                zone.setName("Europa");
+            else if (i == 1)
+                zone.setName("USA");
+            else if (i == 2)
+                zone.setName("Asia");
+            zones[i] = zone;
+        }
+
+        product.setZones(zones);
+        
+        List<CharSequence> list = new ArrayList<CharSequence>();
+        list.add("A");
+        list.add("B");
+        list.add("A");
+        list.add("C");
+        list.add("C");
+        list.add("B");
+        product.setFlavors(new HashSet<CharSequence>(list));
+
+        return product;
+    }
+}
diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFByteArrayCompressor.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFByteArrayCompressor.java
new file mode 100644
index 0000000..6eba7bb
--- /dev/null
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFByteArrayCompressor.java
@@ -0,0 +1,95 @@
+/*
+ *
+ *  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.royale.net.remoting.amf.adapter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.DataFormatException;
+
+import flex.messaging.io.SerializationContext;
+import flex.messaging.io.amf.Amf3Input;
+import flex.messaging.io.amf.Amf3Output;
+
+/**
+ * The {@link AMFByteArrayCompressor} provides methods for AMF to Java compression.
+ */
+public final class AMFByteArrayCompressor {
+
+    /**
+     * Default constructor.
+     */
+    private AMFByteArrayCompressor() {
+
+    }
+
+    /**
+     * Inflate (uncompress) an array of bytes into a Java object.
+     * 
+     * @param ba The bytearray
+     * @return The compressed object.
+     * @throws AMFCompressionException if there's an error during the compression.
+     */
+    public static Object inflate(final byte[] ba) throws AMFCompressionException {
+        Object result = null;
+        try {
+            ByteArrayInputStream bais = new ByteArrayInputStream(ByteArrayCompressor.inflate(ba));
+            SerializationContext sc = new SerializationContext();
+            Amf3Input amf3Input = new Amf3Input(sc);
+            amf3Input.setInputStream(bais);
+            result = amf3Input.readObject();
+            amf3Input.close();
+            bais.close();
+        } catch (ClassNotFoundException e) {
+            throw new AMFCompressionException(AMFCompressionError.AMF_COMPRESSION_ERROR);
+        } catch (IOException e) {
+            throw new AMFCompressionException(AMFCompressionError.AMF_COMPRESSION_ERROR);
+        } catch (DataFormatException e) {
+            throw new AMFCompressionException(AMFCompressionError.AMF_COMPRESSION_ERROR);
+        }
+        return result;
+    }
+
+    /**
+     * Deflate (compress) a Java object into a bytearray.
+     * 
+     * @param obj The serializable Java object.
+     * @return The uncompressed object.
+     * @throws AMFCompressionException if there's an error during the compression.
+     */
+    public static byte[] deflate(final Object obj) throws AMFCompressionException {
+        byte[] ba = null;
+        try {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            SerializationContext sc = new SerializationContext();
+            Amf3Output amf3Output = new Amf3Output(sc);
+            amf3Output.setOutputStream(baos);
+            amf3Output.writeObject(obj);
+            amf3Output.flush();
+            amf3Output.close();
+            baos.close();
+            ba = ByteArrayCompressor.deflate(baos.toByteArray());
+        } catch (IOException e) {
+            throw new AMFCompressionException(AMFCompressionError.AMF_COMPRESSION_ERROR);
+        } catch (DataFormatException e) {
+            throw new AMFCompressionException(AMFCompressionError.AMF_COMPRESSION_ERROR);
+        }
+        return ba;
+    }
+}
diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressionError.java
similarity index 61%
copy from examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
copy to examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressionError.java
index af660fd..f319855 100644
--- a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressionError.java
@@ -16,20 +16,29 @@
  *  limitations under the License.
  *
  */
+package org.apache.royale.net.remoting.amf.adapter;
 
-package org.apache.royale.amfsamples;
+/**
+ * Typed error for signaling an error compressing an ActionScript Object.
+ */
+public enum AMFCompressionError {
+
+	AMF_COMPRESSION_ERROR(10000, "Compression serialization error has occurred");
+	
+	private int code;
+	private String message;
 
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.servlet.ServletComponentScan;
+	private AMFCompressionError(int code, String message) {
+		this.code = code;
+		this.message = message;
+	}
 
-@SpringBootApplication
-@ServletComponentScan("org.apache.royale.amfsamples")
-public class BlazeDSSpringBootApplication {
+	public int getCode() {
+		return code;
+	}
 
-    public static void main(String[] args) {
-        SpringApplication application = new SpringApplication(BlazeDSSpringBootApplication.class);
-        application.run(args);
-    }
 
+	public String getMessage() {
+		return message;
+	}
 }
diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressionException.java
similarity index 53%
copy from examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
copy to examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressionException.java
index af660fd..530153a 100644
--- a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/amfsamples/BlazeDSSpringBootApplication.java
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressionException.java
@@ -16,20 +16,31 @@
  *  limitations under the License.
  *
  */
+package org.apache.royale.net.remoting.amf.adapter;
 
-package org.apache.royale.amfsamples;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.servlet.ServletComponentScan;
-
-@SpringBootApplication
-@ServletComponentScan("org.apache.royale.amfsamples")
-public class BlazeDSSpringBootApplication {
+/**
+ * Thrown to indicate that there was a problem compressing an ActionScript Object.
+ */
+public class AMFCompressionException extends RuntimeException {
+    
+	private static final long serialVersionUID = 3373303053093469687L;
 
-    public static void main(String[] args) {
-        SpringApplication application = new SpringApplication(BlazeDSSpringBootApplication.class);
-        application.run(args);
-    }
+	/**
+	 * Creates an exception with an error code.
+	 *
+	 * @param code
+	 */
+	public AMFCompressionException(AMFCompressionError compressionError) {
+		super(compressionError.getMessage());
+	}
 
+	/**
+	 * Creates an exception with an error code and cause.
+	 *
+	 * @param code
+	 * @param cause
+	 */
+	public AMFCompressionException(AMFCompressionError compressionError, Throwable cause) {
+		super(compressionError.getMessage(), cause);
+	}
 }
diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressorAdapter.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressorAdapter.java
new file mode 100644
index 0000000..4fc682a
--- /dev/null
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/AMFCompressorAdapter.java
@@ -0,0 +1,173 @@
+/*
+ *
+ *  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.royale.net.remoting.amf.adapter;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Arrays;
+
+import flex.messaging.config.ConfigMap;
+import flex.messaging.messages.Message;
+import flex.messaging.services.remoting.adapters.JavaAdapter;
+
+/**
+ * BlazeDS Java adapter extension for AMF compression of complex data types using
+ * ByteArrays for performance optimization.
+ */
+public class AMFCompressorAdapter extends JavaAdapter
+{
+    private List<String> includePackages;
+    private List<String> includeClasses;
+    private List<String> excludeClasses;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see flex.messaging.services.remoting.adapters.JavaAdapter#initialize(java.lang.String,
flex.messaging.config.ConfigMap)
+     */
+    @Override
+    public void initialize(final String id, final ConfigMap properties) {
+        super.initialize(id, properties);
+        
+        includePackages = properties.getPropertyAsList("include-packages", null);
+        includeClasses = properties.getPropertyAsList("include-classes", null);
+        excludeClasses = properties.getPropertyAsList("exclude-classes", null);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see flex.messaging.services.remoting.adapters.JavaAdapter#invoke(flex.messaging.messages.Message)
+     */
+    @Override
+    public Object invoke(final Message message) {
+        Object body = message.getBody();
+        
+        try {
+            Object[] parameters = (Object[]) body;
+            for (int i = 0; i < parameters.length; i++) {
+                if (parameters[i] instanceof byte[]) {
+                    parameters[i] = AMFByteArrayCompressor.inflate((byte[]) parameters[i]);
+                }
+            }
+            message.setBody(parameters);
+            Object result = super.invoke(message);
+            if (isIncludedInCompression(result)) {
+                result = AMFByteArrayCompressor.deflate(result);
+            }
+            return result;
+        } catch (AMFCompressionException e) {            
+            throw new AMFCompressionException(AMFCompressionError.AMF_COMPRESSION_ERROR);
+        }
+    }
+
+    /**
+     * Specifies whether an object should be compressed as a bytearray or not.
+     * 
+     * @param obj The object to compress.
+     * @return Whether to serialize the object as a bytearray or not.
+     */
+    private boolean isIncludedInCompression(final Object obj) {
+        return obj != null && !isInExcludedClasses(obj) && (isInIncludedPackages(obj)
|| isInIncludedClasses(obj));
+    }
+
+    /**
+     * Specifies whether an object belongs to the list of included packages or not.
+     * 
+     * @param obj The object to compress.
+     * @return Whether the object is in the list of included packages or not.
+     */
+    protected final boolean isInIncludedPackages(final Object obj) {
+        Class<?> objClass = obj.getClass();
+        if (includePackages != null && includePackages.size() > 0) {
+            if (obj instanceof Collection<?> && ((Collection<?>) obj).size()
> 0) {
+                objClass = ((Collection<?>) obj).toArray()[0].getClass();
+            }
+            for (String includePackage:includePackages) {
+                if (objClass.getPackage().getName().contains(includePackage)) {
+                    return true;
+	            }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Specifies whether an object belongs to the list of included classes or not.
+     * 
+     * @param obj The object to inspect.
+     * @return Whether the object is in the list of included classes or not.
+     */
+    protected final boolean isInIncludedClasses(final Object obj) {
+        return includeClasses != null && includeClasses.size() > 0 &&
includeClasses.contains(obj.getClass().getName());
+    }
+
+    /**
+     * Specifies whether an object belongs to the list of excluded classes or not.
+     * 
+     * @param obj The object to inspect.
+     * @return Whether the object is in the list of excluded classes or not.
+     */
+    protected final boolean isInExcludedClasses(final Object obj) {
+        return excludeClasses != null && excludeClasses.size() > 0 &&
excludeClasses.contains(obj.getClass().getName());
+    }
+
+    /**
+     * @return The packages that shall be compressed.
+     */
+    public List<String> getIncludePackages() {
+        return includePackages;
+    }
+
+    /**
+     * @param newIncludePackages The packages that shall be compressed.
+     */
+    public void setIncludePackages(final List<String> newIncludePackages) {
+        includePackages = newIncludePackages;
+    }
+
+    /**
+     * @return The classes that shall be compressed.
+     */
+    public List<String> getIncludeClasses() {
+        return includeClasses;
+    }
+
+    /**
+     * @param newIncludeClasses The classes that shall be compressed.
+     */
+    public void setIncludeClasses(final List<String> newIncludeClasses) {
+        includeClasses = newIncludeClasses;
+    }
+
+    /**
+     * @return The classes that shall not be compressed.
+     */
+    public List<String> getExcludeClasses() {
+        return excludeClasses;
+    }
+
+    /**
+     * @param newExcludeClasses
+     *            The classes that shall not be compressed.
+     */
+    public void setExcludeClasses(final List<String> newExcludeClasses) {
+        includeClasses = newExcludeClasses;
+    }
+}
diff --git a/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/ByteArrayCompressor.java
b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/ByteArrayCompressor.java
new file mode 100644
index 0000000..024ffb0
--- /dev/null
+++ b/examples/amf/SampleAmfWebApp/src/main/java/org/apache/royale/net/remoting/amf/adapter/ByteArrayCompressor.java
@@ -0,0 +1,81 @@
+/*
+ *
+ *  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.royale.net.remoting.amf.adapter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.DataFormatException;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+
+/**
+ * The {@link ByteArrayCompressor} class provides methods for bytearray compression.
+ */
+public final class ByteArrayCompressor {
+
+    /**
+     * Default constructor.
+     */
+    private ByteArrayCompressor() {
+    }
+
+    /**
+     * Compresses a bytearray.
+     * 
+     * @param ba The source bytearray.
+     * @return A compressed bytearray.
+     * @throws IOException If there is an IO error.
+     * @throws DataFormatException If the data cannot be uncompressed.
+     */
+    public static byte[] deflate(final byte[] ba) throws IOException, DataFormatException
{
+        Deflater deflater = new Deflater();
+        deflater.setInput(ba);
+        deflater.finish();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        final int overflow = 128;
+        byte[] defBa = new byte[ba.length + overflow];
+        while (!deflater.finished()) {
+            int count = deflater.deflate(defBa);
+            baos.write(defBa, 0, count);
+        }
+        baos.close();
+        return baos.toByteArray();
+    }
+
+    /**
+     * Uncompresses an previously compressed bytearray.
+     * 
+     * @param ba The compressed bytearray.
+     * @return An uncompressed bytearray.
+     * @throws IOException If there is an IO error.
+     * @throws DataFormatException If the data cannot be uncompressed.
+     */
+    public static byte[] inflate(final byte[] ba) throws IOException, DataFormatException
{
+        Inflater inflater = new Inflater();
+        inflater.setInput(ba);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] infBa = new byte[ba.length * 2];
+        while (!inflater.finished()) {
+            int count = inflater.inflate(infBa);
+            baos.write(infBa, 0, count);
+        }
+        baos.close();
+        return baos.toByteArray();
+    }
+}
diff --git a/examples/amf/SampleAmfWebApp/src/main/resources/META-INF/flex/services-config.xml
b/examples/amf/SampleAmfWebApp/src/main/resources/META-INF/flex/services-config.xml
index 5b76e21..08f8a7b 100644
--- a/examples/amf/SampleAmfWebApp/src/main/resources/META-INF/flex/services-config.xml
+++ b/examples/amf/SampleAmfWebApp/src/main/resources/META-INF/flex/services-config.xml
@@ -25,6 +25,9 @@
                 id="java-object"
                 class="flex.messaging.services.remoting.adapters.JavaAdapter"
                 default="true"/>
+        <adapter-definition
+                id="compressed-java-object"
+                class="org.apache.royale.net.remoting.amf.adapter.AMFCompressorAdapter"/>
       </adapters>
       <default-channels>
         <channel ref="websocketAmf"/>
diff --git a/examples/royale/RemoteObjectAMFTest/src/main/royale/App.mxml b/examples/royale/RemoteObjectAMFTest/src/main/royale/App.mxml
index 77943bc..e4281d6 100644
--- a/examples/royale/RemoteObjectAMFTest/src/main/royale/App.mxml
+++ b/examples/royale/RemoteObjectAMFTest/src/main/royale/App.mxml
@@ -85,7 +85,12 @@ limitations under the License.
 			
 			private function onFault(evt:FaultEvent):void
 			{
-				trace("Fault=" + evt.message);
+				for(var key:String in evt["message"])
+				{
+					var element:Object = evt["message"][key];
+					trace(key + ", " + element);					
+				}
+				//trace("Fault = " + evt.message);
 			}
 
 			protected function getVOs():void
@@ -109,6 +114,10 @@ limitations under the License.
                 received2.text = "Selected: " + vo.id;
             }
 			
+            protected function getSomeCompressedProduct():void
+			{
+                compressedService.send("getSomeCompressedProduct", []);
+			}
 		]]>
 	</fx:Script>
 
@@ -117,6 +126,9 @@ limitations under the License.
         <js:RemoteObject id="service" result="onResult(event)" fault="onFault(event)"
                          endPoint = "http://localhost:8080/messagebroker/websocket-amf"
                          destination = "exampleService"/>
+        <js:CompressedRemoteObject id="compressedService" result="onResult(event)" fault="onFault(event)"
+                         endPoint = "http://localhost:8080/messagebroker/websocket-amf"
+                         destination = "compressedService"/>
                          <!--source = "exampleService" source is not needed when using
JavaAdapter on BlazeDS-->
     </j:beads>
 
@@ -163,6 +175,7 @@ limitations under the License.
                     <j:VerticalLayoutWithPaddingAndGap gap="10"/>
                 </j:beads>
                 <j:Button text="Get Some Product" primary="true" click="getSomeProduct()"/>
+                <j:Button text="Get Some Compressed Product" primary="true" click="getSomeCompressedProduct()"/>
                 <j:MultilineLabel id="received3" text="Received:"/>
             </j:Group>
 

-- 
To stop receiving notification emails like this one, please contact
carlosrovira@apache.org.

Mime
View raw message