|
|
Flex 4 Blazeds Java Integration
I'm having a problem calling Java services via Flex BlazeDS.
I'm using Spring 3.0.5 with Annotations and Flex 1.0.3.
I've created a POJO as quot;Groupquot; with public attributes, and I have a AS4 quot;Groupquot; class with the same attributes.
I setup my RemoteObject as so:
Code:
public static function getRemoteObject(destination:String, event:Function, error:Function, showBusyCursor:Boolean=false):RemoteObject {
var cs:ChannelSet = new ChannelSet();
var amfChannel:AMFChannel = new AMFChannel(quot;my-amfquot;, quot;messagebroker/amfquot;);
cs.addChannel(amfChannel);
var service:RemoteObject = new RemoteObject();
service.channelSet = cs;
service.destination = destination;
service.showBusyCursor = showBusyCursor;
service.addEventListener(ResultEvent.RESULT, event);
service.addEventListener(FaultEvent.FAULT, error);
return service;
}
and call this from my modules as:Code:
var grp:Group = new Group();
... load group
var service:RemoteObject = RemoteCalls.getRemoteObject(quot;GroupDAOquot;, resultHandler, faultHandler);
service.createGroup(grp);
This works without a problem, but if I call another service from the same bean, Flex/BlazeDS doesn't seem to be able to map the Flex Group object to the POJO.
I've listed the BlazeDS logs for a successful request and a failed request. Both services work, but I can only use one of them as many times as I want, but the other will not work until I reload the Flex App.
Successful:
[BlazeDS]Serializing AMF/from response
Version: 3 (Message #0 targetURI=/2/onResult, responseURI=) (Externalizable Object #0 'DSK') (Externalizable Object #1 'flex.messaging.io.ArrayCollection') (Array #2) [0] = (Typed Object #3 'com.group.entity.Group')appId = 14admin = 0userId = nullname = quot;Allquot;cmnt = quot;quot;updateId = quot;quot;type = 1updateDate = quot;2011-02-13 19:04:26.0quot;grpId = 22 [1] = (Typed Object #4 'com.group.entity.Group')appId = 14admin = 0userId = nullname = quot;Junkquot;cmnt = quot;quot;updateId = quot;quot;type = 1updateDate = quot;2011-02-15 21:16:16.0quot;grpId = 28 [2] = (Typed Object #5 'com.group.entity.Group')appId = 14admin = 0userId = nullname = quot;TEST5quot;cmnt = nullupdateId = quot;quot;type = 2updateDate = quot;2011-02-04 08:41:23.0quot;grpId = 21
1.297822576209E12Failed
[BlazeDS]Deserializing AMF/from request
Version: 3 (Message #0 targetURI=null, responseURI=/2) (Array #0) [0] = (Typed Object #0 'flex.messaging.messages.RemotingMessage') source = null operation = quot;createUserLinkedGroupquot; timestamp = 0 headers = (Object #1) DSId = quot;BA0A04ED-B518-B539-8D32-D2B0229B6A6Aquot; DSEndpoint = quot;my-amfquot; destination = quot;GroupDaoquot; body = (Array #2) [0] = (Object #3)name = nullupdateDate = nullgrpId = 28appId = 14userId = quot;quot;type = 0cmnt = nulladmin = 2updateId = null clientId = null messageId = quot;3AA0A73A-DA80-0AE0-FD86-2C42AF0AEEECquot; timeToLive = 0
[BlazeDS]Serializing AMF/from response
Version: 3 (Message #0 targetURI=/2/onStatus, responseURI=) (Typed Object #0 'flex.messaging.messages.ErrorMessage') headers = (Object #1) rootCause = (Typed Object #2 'flex.messaging.messages.ErrorMessage') headers = (Object #3) rootCause = null body = null correlationId = null faultDetail = null faultString = quot;Cannot convert type flex.messaging.io.amf.ASObject with remote type specified as 'null' to an instance of class com.group.entity.Groupquot; clientId = null timeToLive = 0.0 destination = null timestamp = 1.29782269116E12 extendedData = null faultCode = quot;Client.Message.Deserialize.InvalidTypequot; messageId = quot;BA0ECE15-D82F-FB38-C928-A17D37B02453quot; body = null correlationId = quot;3AA0A73A-DA80-0AE0-FD86-2C42AF0AEEECquot; faultDetail = quot;The expected argument types are (com.group.entity.Group) but the supplied types were (flex.messaging.io.amf.ASObject) and converted to (null).quot; faultString = quot;Cannot invoke method 'createUserLinkedGroup'.quot; clientId = quot;BA0ECE15-D80A-19E2-936E-ACB39CA25F34quot; timeToLive = 0.0 destination = quot;GroupDaoquot; timestamp = 1.29782269116E12 extendedData = null faultCode = quot;Server.ResourceUnavailablequot; messageId = quot;BA0ECE15-D819-513C-E9CD-9850697CD5C1quot;As you can see from the logs, in the successful transactions the correct 'Group' object was used, but in the failed, its unable to locate the correct object to pass.
Any ideas of where I need to look to understand what I am doing wrong ?
Could this issue be related to the Spring Annotations?
I tried changing my definitions from:
Code:
@Repository(quot;GroupDaoquot;)
@RemotingDestination
public class GroupDaoImpl implements GroupDao {
to:Code:
@Service(quot;GroupDaoquot;)
@RemotingDestination
public class GroupDaoImpl implements GroupDao {
and now neither of the services will map to the typed Object and I get the same error returned:
faultString = #8220;Cannot convert type flex.messaging.io.amf.ASObject with remote type specified as #8216;null#8217; to an instance of class com.group.entity.Group#8221;
Thanks
That error indicates that you are doing something wrong on the Flex side, though I've not seen enough of your code to say for certain what is wrong. Have you specified the [RemoteClass] metadata properly on all of your objects?
One thing that's a little strange is that you are recreating the ChannelSet every time you create your RemoteObject. You should only need to have a single instance of ChannelSet that gets reused for each new RemoteObject.
Yes, they are defined as below.
Code:
[RemoteClass(alias=quot;com.group.entity.Groupquot;)]
public class Group {...
I will adjust the code to reuse the channelset, thanks for that tip.
Other than that, I'm still lost here. I've tried many different ways on these classes, from private vars with getters and setters to public vars, I've tried implmenting serializable for the POJOs, but I just can't seem to find where the problem is.
I'm still thinking it may be a Spring Annotation issue, because the services should work when I change the @Repository to @Service, but they won't map the typed beans, they only seem to except standard objects like String.
Originally Posted by StaticSpaceI'm still thinking it may be a Spring Annotation issue, because the services should work when I change the @Repository to @Service, but they won't map the typed beans, they only seem to except standard objects like String.
I really don't see how that could be the case. The logs you posted clearly show that the AMF message is being sent from the Flex client without the necessary type mapping information. The deserialization to the appropriately typed object on the Java side happens well before the call gets routed to the given Spring bean. |
|