Flex 与 WebORB 学习(二)

在现有的web app中整合WebORB and flex应用。
http://www.themidnightcoders.com/weborb/java/deploying_weborb_into_java_ee_server.shtm

 

使用
WebORB for Java 3.0 Beta 1
Tomcat 5.5.23

 

[WEBORB_INSTALL] 指WebORB解压缩目录
[YOUR APP PATH] 指现有web app的web root目录

 

一、POJO与WebORB整合

例如现有的web应用中有一个UserService

public class UserService {

	public UserBean getUserBean(int id) {
		
		UserBean bean = new UserBean();
		bean.setId(id);
		bean.setName("aaaa");
		
		return bean;
	}
}

 

1.复制 [WEBORB_INSTALL]\webapp\WEB-INF\classes\weborb-config.xml
到 [YOUR APP PATH]\WEB-INF\classes

 

2.复制 [WEBORB_INSTALL]\weborb.jar
到 [YOUR APP PATH]\WEB-INF\lib

 

3.修改 [YOUR APP PATH]\WEB-INF\web.xml 添加

<servlet>
  <servlet-name>weborb</servlet-name>
  <servlet-class>weborb.ORBServlet</servlet-class>
  <load-on-startup> 1 </load-on-startup>
</servlet>

<servlet>
  <servlet-name>download</servlet-name>
  <servlet-class>weborb.DownloadServlet</servlet-class>
  <load-on-startup> 1 </load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>download</servlet-name>
  <url-pattern>/codegen.wo</url-pattern>
</servlet-mapping>

<servlet-mapping>
  <servlet-name>weborb</servlet-name>
  <url-pattern>*.wo</url-pattern>
</servlet-mapping>

  

4.创建 [YOUR APP PATH]\WEB-INF\flex 目录
复制 [WEBORB_INSTALL]\webapp\WEB-INF\flex 所有内容
到 [YOUR APP PATH]\WEB-INF\flex

 

打开Flex Builder创建project
File -> New -> Flex Project -> Flex Data Services

 

Root folder: [YOUR APP PATH]
Root URL: http://localhost:8080/[Your App Context]
Context root: /[Your App Context]

 

项目名称我使用的是 flexWebORB1 (会自动创建[YOUR APP PATH]\flexWebORB1 目录)
mxml内容如下

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	
	<mx:Script>
		[CDATA[
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			private function faultHandler( event:FaultEvent ):void {
			    Alert.show( event.fault.faultString, "Error" ); 
			}
			
			private function getComputerInfoHandler( event:ResultEvent ):void {
				Alert.show(event.result.name);
			}
			
			public function onClick() : void {
				compinfo.getUserBean(1);
			}
		]]
	</mx:Script>
	
	<mx:RemoteObject id="compinfo" source="myapp.service.UserService" 
	                 destination="GenericDestination" 
	                 showBusyCursor="true"
	                 fault="faultHandler(event)" >
	     <mx:method name="getUserBean" result="getComputerInfoHandler(event)"/>
	</mx:RemoteObject>
	
	<mx:Button x="10" y="10" label="Button" click="onClick()"/>
	
</mx:Application>

 

RemoteObject中的 source="myapp.service.UserService" 是java类的完全限定名
destination="GenericDestination" 是配置在[YOUR APP PATH]\WEB-INF\flex\remoting-config.xml 中

 

    <destination id="GenericDestination">
        <properties>
            <source>*</source>
        </properties>
    </destination> 

 

编译flex, 启动tomcat就可以测试了swf了.

 

我们也可以添加一个destination
在remoting-config.xml 中添加

    <destination id="UserServiceDestination">
        <properties>
            <source>myapp.service.UserService</source>
        </properties>
    </destination> 

 

修改mxml

	<mx:RemoteObject id="compinfo" 
	                 destination="UserServiceDestination"
	                 showBusyCursor="true"
	                 fault="faultHandler(event)" >
	     <mx:method name="getUserBean" result="getComputerInfoHandler(event)"/>
	</mx:RemoteObject>

 

重启Tomcat进行测试

 

二、整合WebORB 管理控制台


1.复制 [WEBORB_INSTALL]\webapp\weborbconsole.html
到[YOUR APP PATH]


2.复制
[WEBORB_INSTALL]\webapp\console
[WEBORB_INSTALL]\webapp\weborbassets
两个文件夹到 [YOUR APP PATH]

 

重启 tomcat后,可以在 http://localhost:8080/[Your App Context]/weborbconsole.html 看到控制台.

 

可以在Management -> Services -> Deployed classes 中找到 WEB-INF/classes 节点
找到UserService,可以在CodeGenerator产生AS3代码
选中一个方法,可以在Test Drive中直接测试.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值