Tag Archive for amf

zend amf class

<?

class Tutorials
{
function __construct()
{
# code...
mysql_connect("localhost:8889", "root", "root");
mysql_select_db("information_schema");
}

public function getTutorials(){
$result = mysql_query("SELECT * FROM COLUMNS");
$t = array();

while($row = mysql_fetch_assoc($result)){
array_push($t, $row);
}
return $t;
}
}

?>

source

Zend amf setup

<?
error_reporting(E_ALL|E_STRICT);
ini_set("display_errors", "on");

ini_set("include_path", ini_get("include_path") . ":/Applications/MAMP/frameworks");

require_once 'Zend/Amf/Server.php';
require_once 'Tutorials.php';

$server = new Zend_Amf_Server();
$server->setClass("Tutorials");

echo($server->handle());

?>

source

amfphp

import flash.net.*;

var gw:NetConnection = new NetConnection();
gw.connect("http://YOUR_SERVER/amfphp/gateway.php");

var res:Responder = new Responder(onResult, onFault);

function onResult(responds:Object):void
{
// parse the ArrayCollection
var t:Array = responds.serverInfo.initialData;
for(var i:uint=0; i<t.length; i++)
{
trace(t[i][2]);
}
}

function onFault(responds:Object):void
{
for(var i in responds)
{
trace(responds[i]);
}
}

gw.call("Service.method", res);

source

Serialization of Java object to AMF

package amfdemo;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.Amf3Input;
import flex.messaging.io.amf.Amf3Output;
import javax.xml.parsers.DocumentBuilderFactory;

public class AmfTest {

public static void main(String[] args) {
try {

SerializationContext context = getSerializationContext();

TestBean testBean = new TestBean();
testBean.setByte(new Byte((byte) 9));
testBean.setBigDecimal(new BigDecimal("9.9"));
testBean.setBoolean(new Boolean("true"));
testBean.setCharacter(new Character('c'));
testBean.setCalendar(Calendar.getInstance());
testBean.setDate(Calendar.getInstance().getTime());
testBean.setDouble(new Double(999.9));
testBean.setFloat(new Float(99.9f));
testBean.setInteger(new Integer("999"));
testBean.setList(new ArrayList());
testBean.setLong(new Long(99999));
testBean.setMap(new HashMap());
testBean.setDocument(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
testBean.setShort(new Short("99"));
testBean.setString("test");

ByteArrayOutputStream bout = new ByteArrayOutputStream();
Amf3Output amf3Output = new Amf3Output(context);
amf3Output.setOutputStream(bout);
amf3Output.writeObject(testBean);
amf3Output.flush();
amf3Output.close();

InputStream bIn = new ByteArrayInputStream(bout.toByteArray());
Amf3Input amf3Input = new Amf3Input(context);
amf3Input.setInputStream(bIn);
TestBean o = (TestBean) amf3Input.readObject();

System.out.println(o.getByte().equals(testBean.getByte()));
System.out.println(o.getBigDecimal().equals(testBean.getBigDecimal()));
System.out.println(o.getBoolean().equals(testBean.getBoolean()));
System.out.println(o.getCharacter().equals(testBean.getCharacter()));
System.out.println(o.getCalendar().equals(testBean.getCalendar()));
System.out.println(o.getDate().equals(testBean.getDate()));
System.out.println(o.getDouble().equals(testBean.getDouble()));
System.out.println(o.getFloat().equals(testBean.getFloat()));
System.out.println(o.getInteger().equals(testBean.getInteger()));
System.out.println(o.getLong().equals(testBean.getLong()));
System.out.println(o.getString().equals(testBean.getString()));

} catch (Exception e) {
e.printStackTrace();
}
}

public static SerializationContext getSerializationContext() {

//Threadlocal SerializationContent
SerializationContext serializationContext = SerializationContext.getSerializationContext();
serializationContext.enableSmallMessages = true;
serializationContext.instantiateTypes = true;
//use _remoteClass field
serializationContext.supportRemoteClass = true;
//false  Legacy Flex 1.5 behavior was to return a java.util.Collection for Array
//ture New Flex 2+ behavior is to return Object[] for AS3 Array
serializationContext.legacyCollection = false;

serializationContext.legacyMap = false;
//false Legacy flash.xml.XMLDocument Type
//true New E4X XML Type
serializationContext.legacyXMLDocument = false;

//determines whether the constructed Document is name-space aware
serializationContext.legacyXMLNamespaces = false;
serializationContext.legacyThrowable = false;
serializationContext.legacyBigNumbers = false;

serializationContext.restoreReferences = false;
serializationContext.logPropertyErrors = false;
serializationContext.ignorePropertyErrors = true;
return serializationContext;

/*
serializationContext.enableSmallMessages = serialization.getPropertyAsBoolean(ENABLE_SMALL_MESSAGES, true);
serializationContext.instantiateTypes = serialization.getPropertyAsBoolean(INSTANTIATE_TYPES, true);
serializationContext.supportRemoteClass = serialization.getPropertyAsBoolean(SUPPORT_REMOTE_CLASS, false);
serializationContext.legacyCollection = serialization.getPropertyAsBoolean(LEGACY_COLLECTION, false);
serializationContext.legacyMap = serialization.getPropertyAsBoolean(LEGACY_MAP, false);
serializationContext.legacyXMLDocument = serialization.getPropertyAsBoolean(LEGACY_XML, false);
serializationContext.legacyXMLNamespaces = serialization.getPropertyAsBoolean(LEGACY_XML_NAMESPACES, false);
serializationContext.legacyThrowable = serialization.getPropertyAsBoolean(LEGACY_THROWABLE, false);
serializationContext.legacyBigNumbers = serialization.getPropertyAsBoolean(LEGACY_BIG_NUMBERS, false);
boolean showStacktraces = serialization.getPropertyAsBoolean(SHOW_STACKTRACES, false);
if (showStacktraces && Log.isWarn())
log.warn("The " + SHOW_STACKTRACES + " configuration option is deprecated and non-functional. Please remove this from your configuration file.");
serializationContext.restoreReferences = serialization.getPropertyAsBoolean(RESTORE_REFERENCES, false);
serializationContext.logPropertyErrors = serialization.getPropertyAsBoolean(LOG_PROPERTY_ERRORS, false);
serializationContext.ignorePropertyErrors = serialization.getPropertyAsBoolean(IGNORE_PROPERTY_ERRORS, true);
*/
}
}

source

amf

<?php

class Email
{
/**
* This service sends an email
* @returns true or false
*/

//als je een underscore voor de functie plaatst wordt dit een private function
function send($to, $subject, $message)
{
return mail($to, $subject, $message);
}
}

?>

source

amf php class

<?php

class service
{

function name(){

}
}

?>

source