0

I am using Flex 3 and make a call through a RemoteObject to a Java 1.6 method and exposed with BlazeDS and Spring 2.5.5 Integration over a SecureAMFChannel. The ActionScript is as follows (this code is an example of the real thing which is on a separate dev network);

import com.adobe.cairngorm.business.ServiceLocator;
import mx.collections.ArrayCollection;
import mx.rpc.remoting.RemoteObject;
import mx.rpc.IResponder;

public class MyClass implements IResponder
{

    private var service:RemoteObject = ServiceLocator.getInstance().getRemoteOjbect("mySerivce");

    public MyClass()
    {
        [ArrayElementType("Number")]
        private var myArray:ArrayCollection;

        var id1:Number = 1;
        var id2:Number = 2;
        var id3:Number = 3;

        myArray = new ArrayCollection([id1, id2, id3]);

        getData(myArray);

    }

    public function getData(myArrayParam:ArrayCollection):void
    {
        var token:AsyncToken = service.getData(myArrayParam);
        token.addResponder(this.responder); //Assume responder implementation method exists and works
    }

}

This will make a call, once created to the service Java class which is exposed through BlazeDS (assume the mechanics work because they do for all other calls not involving Collection parameters). My Java service class looks like this;

public class MySerivce {
    public Collection<DataObjectPOJO> getData(Collection<Long> myArrayParam) {
        //The following line is never executed and throws an exception
        for (Long l : myArrayParam) {
            System.out.println(l);
        }
    }

}

The exception that is thrown is a ClassCastException saying that a java.lang.Integer cannot be cast to a java.lang.Long. I worked around this issue by looping through the collection using Object instead, checking to see if it is an Integer, cast it to one, then do a .longValue() on it then add it to a temp ArraList. Yuk.

The big problem is my application is supposed to handle records in the billions from a DB and the id will overflow the 2.147 billion limit of an integer. I would love to have BlazeDS or the JavaAdapter in it, translate the ActionScript Number to a Long as specified in the method. I hate that even though I use the generic the underlying element type of the collection is an Integer. If this was straight Java, it wouldn't compile.

Any ideas are appreciated. Solutions are even better! :)

3 Answers 3

1

Please read the following threads related to your issue. You can find there some workarounds.

https://bugs.adobe.com/jira/browse/BLZ-115

https://bugs.adobe.com/jira/browse/BLZ-305

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for identifying the problem correctly + giving official references/workarounds
0

You can also change the argument on the Java side to expect a Long[] rather than a Collection<Long>. Because the native Java array is strongly typed, it deserializes correctly.

Comments

0

Flex serializes an ArrayCollection of Numbers to an ArrayCollection<Integer> in Java.

Since Adobe's ArrayCollection extends ArrayList, you can run the Collection through the following function. This should produce a List of Long values.

public class TransformUtils {
  public static final <T extends Number> List<Long> toLongList(Collection<T> values) {
    List<Long> list = new ArrayList();
    for (T value : values) {
      list.add(value.longValue());
    }
    return list;
  }
}
public class MySerivce {
  public Collection<DataObjectPOJO> getData(Collection<Long> myArrayParam) {
    myArrayParam = TransformUtils.toLongList(myArrayParam);
    for (Long l : myArrayParam) {
      System.out.println(l);
    }
  }
}

Guava :)

public static final <T extends Number> List<Long> toLongList(Collection<T> values) {
  return Lists.newArrayList(new Function<T, Long>() {
    @Override public Long apply(T value) {
      return value.longValue(); }));}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.