Tuesday, October 31, 2006

Sending custom class object thru remoting using OpenAmf

Passing UDT from java to flex using openAmf based remoting.

Finally the battle is over. Was in lot of pain pasing a
custom object as response to remote call to java. 2 man days
wasted.

Java (server side) :

Remote Class (UDT): TestClass.java

package com.vishwajit.test.BO;

import java.io.Serializable;

public class TestClass implements Serializable {

private String testValue ;

public TestClass() {
}

public String getTestValue() {
return testValue;
}

public void setTestValue(String testValue) {
this.testValue = testValue;
}
}

Remote Method : (Inside Service.java)

public static TestClass Test()
{
TestClass obj = new TestClass();
obj.setTestValue("setyblch");
return obj;
}

Open AMF Mapping

(if you have not already set this one...)
<amf-serializer>

 <force-lower-case-keys>false</force-lower-case-keys>

</amf-serializer>

      


<custom-class-mapping>>

 <java-class>com.vishwajit.test.BO.TestClass</java-class>

 <custom-class>vishwajit.TestClass</custom-class>

</custom-class-mapping>



Client Side (flex / swf):

public function TestHandler (obj : Object ):void {

var testObj:TestClass = TestClass(obj);
Alert.show("" + testObj.testValue );
}

1 comment:

Mayur said...

Can u please explain in details,
like where u have invoke the openamf connection and where all the jars for openamf are kept etc.
I am starting of with one project which needs open amf connection and we are in brainstroming phase. can you please explain me in detail.
It will be a massive help
Thanks a ton