在现有的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中直接测试.
本文介绍如何将WebORB for Java整合到现有Web应用程序中,并通过示例演示如何配置和服务调用流程。此外,还介绍了如何部署WebORB管理控制台。
134

被折叠的 条评论
为什么被折叠?



