views:

945

answers:

2

Hello,

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! :)

A: 

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

Cornel Creanga
A: 

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.

Markus