OSGI-flex-blazeds通信

1.发布服务
Dictionary<String, String> initparams = new Hashtable<String, String>();
 initparams.put("services.configuration.file", "D:/javatools/factoryspaces/loowj.base/WEB-INF/flex/services-config.xml");
 initparams.put("load-on-startup", "1");
 
 ServiceReference httpServiceRef = context.getServiceReference(HttpService.class.getName());
 httpService = (HttpService) context.getService(httpServiceRef);
 // 直接发布
 try {
 httpService.registerServlet("/messagebroker", new MessageBrokerServlet(), initparams, null);
 } catch (ServletException e) {
 e.printStackTrace();
 } catch (NamespaceException e) {
 e.printStackTrace();
 }

2.XML调用
<mx:Button click="submit()" label="hello" horizontalCenter="0" verticalCenter="0"/>  

public function submit():void{  
	           var remote:RemoteObject = new RemoteObject();  
	           //监听调用成功事件  
	           remote.addEventListener(ResultEvent.RESULT,result);                  
	           //监听失败事件  
	           remote.addEventListener(FaultEvent.FAULT,fault);    
	           //调用在J2EE端remoting-config.xml中配置的暴露出的类的名称 id  
	           remote.destination = "hello";  
	           remote.endpoint = "http://{server.name}:{server.port}/messagebroker/amf/";
	           //调用J2EE端类中的方法  
	           var operation:AbstractOperation=remote.getOperation("hello");  
	           operation.arguments=['loow'];
				operation.send();	
	       }  
	         
	       private function result(evt:ResultEvent):void{  
	           Alert.show(evt.result.toString());  
	       }  
	        private function fault(evt:FaultEvent):void{  
	        	trace(evt.message);
	           Alert.show("调用失败!");  
	       } 

3. 启动 
进入propertyies-->Flex Build Path -->Output folder URL --> 配置为访问的地址如:http://localhost:8888
Debug Configurations-->URL ro path to launch 将会变为 http://localhost:8888

你可能感兴趣的:(OSGI-flex-blazeds通信)