Flex⇔Axis2との通信でObject(AS3)を使う
Axis2とFlex間で、Objectを利用するためのサンプル。Objectは、Javaのほうのjava.lang.Objectじゃなくて、Flex側のObjectデータの送受信についてのメモ。Flex側は単に引数に{foo:"foo", bar:"bar"}を渡してあげるだけ。
Flex側
var webService:WebService = new WebService(); webService.wsdl = "http://localhost:8080/WebServiceProject/services/Test?wsdl"; webService.loadWSDL(); webService.echoOption({foo:"foo", bar:"bar"});
Axis2側
パラメータとしてOMElementを利用するのがポイント。サンプル・コードでは、
- OMElementを操作して、HashMapのkey、valueに変換してあげている。
- さらに、fooノードを追加した、OMElementを返している。
public OMElement echoOption(OMElement option) { OMFactory factory = OMAbstractFactory.getOMFactory(); HashMap<String, String> map = new HashMap<String, String>(); // 1 for(Iterator<OMElement> i=option.getChildElements();i.hasNext();) { OMElement element = i.next(); map.put(element.getLocalName(), element.getText()); }; // 2 OMElement child = factory.createOMElement("foo", null); child.setText("aaa"); option.addChild(child); System.out.println(map.toString()); return option; };