blob: c79879b0388223ef060c23e51a170621729a75e7 [file]
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<j:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:j="library://ns.apache.org/royale/jewel"
xmlns:js="library://ns.apache.org/royale/basic"
xmlns:mx="library://ns.apache.org/royale/mx"
initialize="iniApp(event)"
>
<fx:Style source="../../main/resources/styles.css"/>
<fx:Script>
<![CDATA[
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import org.apache.royale.collections.ArrayList;
import org.apache.royale.events.Event;
import org.apache.royale.net.remoting.amf.AMFBinaryData;
import org.apache.royale.reflection.registerClassAlias;
import valueObjects.ClientValueObject;
import valueObjects.Product;
import valueObjects.Zone;
import valueObjects.Taxonomy;
private function iniApp(event:Event):void{
AMFBinaryData.DEBUG = true;
registerClassAlias('org.apache.royale.collections.ArrayList', ArrayList);
}
private function onFault(evt:FaultEvent):void
{
trace("[onFault]", evt);
}
// Test AsyncToken - Responder
private var token:AsyncToken;
private var responder:Responder;
private function sendEcho(evt:MouseEvent):void
{
responder = new Responder(onEchoResult, onFault);
token = serviceResp.echo(nameResp_txt.text);
token.addResponder(responder);
trace(token);
}
private function onEchoResult(event:ResultEvent):void
{
trace("[onEchoResult]", event);
result_txt.text = event.result as String;
}
/**
* create a complex object in royale and send to java
*/
public function sendClientVO(event:MouseEvent):void
{
trace("sendClientVO called");
var clientVO:ClientValueObject = new ClientValueObject();
clientVO.id = Math.round(Math.random()*100);
var r:Responder = new Responder(sendClientVOResult, onFault);
var t:AsyncToken = serviceResp.sendClientVO(clientVO);
t.addResponder(r);
trace("the token: ", t);
}
private function sendClientVOResult(event:ResultEvent):void
{
trace("[sendClientVOResult]", event);
result2_txt.text = event.result as String;
}
/**
* create a complex object in royale and send to java
*/
public function sendSomeProduct(event:MouseEvent):void
{
trace("sendSomeProduct called");
var product:Product = new Product();
product.name = "Some royale product";
product.description = "This product is only a clientside created test typed value object to test AMF strong types";
var taxonomy:Taxonomy = new Taxonomy();
taxonomy.type = "a clientside taxonomy type";
taxonomy.description = "a clientside taxonomy for this product";
product.taxonomy = taxonomy;
var zones:ArrayList = new ArrayList();
var zone:Zone= new Zone();
zone.id = 1;
zone.name = 'Europe';
zones.addItem(zone);
zone = new Zone();
zone.id = 2;
zone.name = 'USA';
zones.addItem(zone);
zone = new Zone();
zone.id = 3;
zone.name = 'Asia-Pacific';
zones.addItem(zone);
var flavors:ArrayList = new ArrayList();
flavors.addItem('X');
flavors.addItem('Y');
flavors.addItem('Z');
product.flavors = flavors;
product.zones = zones;
var r:Responder = new Responder(onSendSomeProductResult, onFault);
var t:AsyncToken = serviceResp.sendSomeProduct(product);
t.addResponder(r);
trace("the token: ", t);
}
private function onSendSomeProductResult(event:ResultEvent):void
{
trace("[onSendSomeProductResult]", event);
result3_txt.text = event.result as String;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- <mx:RemoteObject id="service" fault="onFault(event)"
endpoint="http://localhost:8080/messagebroker/websocket-amf"
destination="exampleService">
<mx:method name="echo">
<mx:arguments>
<symbol>{name_txt.text}</symbol>
</mx:arguments>
</mx:method>
<mx:method name="getObjectArray1">
</mx:method>
<mx:method name="getSomeProduct">
</mx:method>
</mx:RemoteObject> -->
<mx:RemoteObject id="serviceResp" fault="onFault(event)"
endpoint="http://localhost:8080/messagebroker/websocket-amf"
destination="exampleService"/>
</fx:Declarations>
<j:beads>
<js:ClassAliasBead />
</j:beads>
<j:valuesImpl>
<js:SimpleCSSValuesImpl />
</j:valuesImpl>
<j:initialView>
<j:ResponsiveView>
<!-- <mx:VBox width="400">
<mx:HBox>
<mx:VBox>
<mx:Label text="Name to send via AMF"/>
<mx:TextInput id="name_txt"/>
</mx:VBox>
<mx:Button label="Send to Name" click="service.echo.send()"/>
</mx:HBox>
<mx:Label text="{(service.echo as Operation).lastResult}"/>
</mx:VBox> -->
<j:VGroup width="400">
<j:HGroup>
<j:VGroup>
<j:Label text="Name to send via AMF (With Responder)"/>
<j:TextInput id="nameResp_txt"/>
</j:VGroup>
<j:Button text="Send to Name (With Responder)" click="sendEcho(event)"/>
</j:HGroup>
<j:Label id="result_txt"/>
<j:VGroup>
<j:Button text="Send client vo to java" click="sendClientVO(event)"/>
<j:Label id="result2_txt"/>
</j:VGroup>
<j:VGroup>
<j:Button text="Send complex object to java" click="sendSomeProduct(event)"/>
<j:Label id="result3_txt"/>
</j:VGroup>
</j:VGroup>
</j:ResponsiveView>
</j:initialView>
<!-- <mx:VBox width="400">
<mx:Button label="Get Array Of Objects" click="service.getObjectArray1.send()"/>
<mx:List id="list" labelField="id" width="100%" height="200"
dataProvider="{(service.getObjectArray1 as Operation).lastResult}" />
<mx:Label text="{list.selectedItem}"/>
</mx:VBox>
<mx:VBox width="400">
<mx:Button label="Get Some Product" click="service.getSomeProduct.send()"/>
<mx:Label text="{((service.getSomeProduct as Operation).lastResult as Product).name}"/>
</mx:VBox> -->
</j:Application>