Result handler not being invoked
Michael Guyver <[email protected]> Mon, 5 Feb 2007 15:47:21 +0000 (UTC)
| Newsgroups | gmane.comp.java.openamf.user |
|---|---|
| Message-ID | <[email protected]> |
Hi there,
I've been trying to get OpenAMF working with Flex 2.1. I am new to Flex/AS3 so
this may have some wonderfully obvious reason why it's not working - I hope so
as a quick fix would be most welcome.
I hope that if I post my code someone can tell me where I'm going wrong. In
essence, I've lifted part of the OpenAMF code as I simply want to get this
working; I haven't configured invokers etc, but am simply using the
AMFSerializer class. Perhaps that's the problem? Perhaps the message I'm
returning is to blame (see the DefaultAmfServlet.java below).
I'm using ethereal/wireshark to check the calls are being made (which they are)
and the RemotingConnection idiom described at
http://www.adobe.com/devnet/flex/articles/flex2_amfphp_03.html to ensure AMF0 is
used. If someone could please explain why neither the fault handler nor the
result handler is being called I'd be very grateful.
Regards
Mike
PS Anyway:
---------------------------------------------------------------------
---------------------------------------------------------------- MXML
---------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns="*"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:guyverm="guyverm.*"
paddingTop="2"
paddingBottom="2"
paddingLeft="2"
paddingRight="2">
<mx:TextArea width="100%" height="100%" id="debugPane"></mx:TextArea>
<guyverm:ErsteKlasse
debugArea="{debugPane}"
id="serviceTarget"/>
<mx:Button label="Flex butt" click="serviceTarget.makeRemoteConnection()" />
</mx:Application>
---------------------------------------------------------------------
------------------------------------------------------- Action Script
---------------------------------------------------------------------
/**
* @author guyverm
* Relies on the corelib library from http://code.google.com/p/
*/
package guyverm {
import flash.display.DisplayObjectContainer;
import flash.events.Event;
import flash.net.Responder;
import mx.controls.TextArea;
import mx.core.IMXMLObject;
public class ErsteKlasse implements IMXMLObject {
private var displayObj:DisplayObjectContainer;
private var traceArea:TextArea;
function ErsteKlasse(){
super();
}
/**
* From interface IMXMLObject.
*/
public function initialized(document:Object, id:String):void {
displayObj = (document as DisplayObjectContainer);
}
private function log(message:String):void {
if (traceArea != null){
traceArea.htmlText = traceArea.htmlText + "<br/>" + message;
}
}
flash.net.registerClassAlias( "guyverm.Person", guyverm.Person );
public function makeRemoteConnection():void {
log("creating RemotingConnection");
var gateway:RemotingConnection = new
RemotingConnection("http://swf.localhost/flex/butt.amf");
log("invoking .call(\"sample.getUsers\", new Responder(onResult, onFault)");
gateway.call("sample.getUsers", new Responder(onResult, onFault));
log("done");
}
private function onResult():void {
mx.controls.Alert.show("result");
log("result");
}
private function onFault():void {
mx.controls.Alert.show("result");
log("fault");
}
public function set debugArea(uiComponent:TextArea):void {
traceArea = uiComponent;
}
}
}
package guyverm {
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
public class RemotingConnection extends NetConnection {
public function RemotingConnection( sURL:String ) {
objectEncoding = ObjectEncoding.AMF0;
if (sURL) connect( sURL );
}
public function AppendToGatewayUrl( s : String ) : void {
//
}
}
}
---------------------------------------------------------------------
---------------------------------------------------------- Java stuff
---------------------------------------------------------------------
------------------------------------------------------------- web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>ActionScript 3 AMF demo</display-name>
<servlet>
<servlet-name>amfService</servlet-name>
<servlet-class>uk.co.mindfruit.flex.amf.DefaultAmfServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>amfService</servlet-name>
<url-pattern>*.amf</url-pattern>
</servlet-mapping>
</web-app>
---------------------------------------------- DefaultAmfServlet.java
package uk.co.mindfruit.flex.amf;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openamf.AMFBody;
import org.openamf.AMFMessage;
import org.openamf.io.AMFSerializer;
public class DefaultAmfServlet extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
AMFMessage message = new AMFMessage();
message.addBody(new AMFBody("/onResult", "null", new Person("Michael",
"Guyver")));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AMFSerializer serializer = new AMFSerializer(new DataOutputStream(baos));
serializer.serializeMessage(message);
response.setContentType("application/x-amf");
response.setContentLength(baos.size());
ServletOutputStream sos = response.getOutputStream();
baos.writeTo(sos);
sos.flush();
}
}
--------------------------------------------------------- Person.java
package uk.co.mindfruit.flex.amf;
public class Person {
private String firstName;
private String surname;
public Person(String firstName, String surname) {
super();
this.firstName = firstName;
this.surname = surname;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642