blazeds使用remote访问
欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3487128.html
1.配置及说明
- jar包说明
 
从官方上下的Blazeds中,默认的配置有四个文件,都在WEB-INF/Flex目录下:services-config.xml、remoting-config.xml、proxy-config.xml、messaging-config.xml。要使用他,首先把lib目录下的jar包拷贝到你自己创建的web项目中去,当然你可以用maven来管理jar包,这样就会方便很多。这里作为demo,我把目录的截图展示一下:

其中xalan.jar在本例中并没有用到,它是处理xml文档的一个jar包。
- web.xml配置文件
 
在web.xml中加入监听(就是个设计模式中的观察者模式),来将HttpFlexSession类作为监听器注册到web.xml中,这样当J2EE HttpSession属性和代理属性的变化时候,就会通知FlexSession属性和目前绑定的listener做相应处理。
<!-- Http Flex Session attribute and binding listener support -->
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
加入blazeds提供的servlet,这样当URL请求符合/messagebroker/*(这个和后面展示的channel中的那个路径对应)模式时候,它会在Servlet容器启动时启动,并在启动时读取配置文件/WEB-INF/flex/services-config.xml.
<!-- MessageBroker Servlet -->
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
- 服务配置文件flex/services-config.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<services-config> <services>
<service-include file-path="remoting-config.xml" />
<service-include file-path="proxy-config.xml" />
<service-include file-path="messaging-config.xml" />
</services> <security>
<login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
<!-- Uncomment the correct app server
<login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
<login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>
<login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
<login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
--> <!--
<security-constraint id="basic-read-access">
<auth-method>Basic</auth-method>
<roles>
<role>guests</role>
<role>accountants</role>
<role>employees</role>
<role>managers</role>
</roles>
</security-constraint>
-->
</security>
<!--Channel的作用就是帮助我们传输消息.Channel使用URL与Endpoint通信.Endpoint就是消息传输的接收器,它并不真正处理消息,它将处理过程委托给service -->
<channels> <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition> <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition> <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>true</polling-enabled>
<polling-interval-seconds>4</polling-interval-seconds>
</properties>
</channel-definition> <!--
<channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
</channel-definition> <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
<endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
</properties>
</channel-definition>
-->
</channels> <logging>
<!-- 输出到控制台 ,若要使用Servlet日志文件作为目标,将class属性改为"flex.messaging.log.ServletLogTarget".-->
<!-- 中level="Error"为日志的记录级别.有None,Error,Warn,Info,Debug,All六种选择 -->
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>false</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<!-- 信息的过滤条件,只有匹配的类别才会被记录到指定的目标中 -->
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging> <system>
<redeploy>
<enabled>false</enabled>
<!--
<watch-interval>20</watch-interval>
<watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
<watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
<touch-file>{context.root}/WEB-INF/web.xml</touch-file>
-->
</redeploy>
</system> </services-config>
配置文件就简单说明到这,有兴趣自己googling。。。。。
2.创建简单remote例子。
这里面我就用flexbuilder4.6和myeclipse两个分开来创建项目。我觉得这样舒服,你要是不爽,你也可以装插件,都在eclipse中编译。
- 后代java代码
 
 package com.bing.test;
 public class HelloWorld {
     public String getHelloWorld(String name){
         System.out.println("hello "+name);
         return "this is a test for " +name;
     }
 }
- 远程服务配置文件
 
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" class="flex.messaging.services.RemotingService"> <adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true" />
</adapters> <default-channels>
<channel ref="my-amf" />
</default-channels>
<!-- destination设置服务终端的目的地,属性id为客户端组件RemoteObject的destination -->
<destination id="helloWorld" channels="my-amf">
<properties>
<source>com.bing.test.HelloWorld</source>
</properties>
</destination>
</service>
- 前台flexbuilder中配置及代码
 
新建flex项目dstest,在服务器设置这一步,选择如下,当然你也可以创建好项目后在设置。

创建好之后,编写flex代码
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent; // Send the message in response to a Button click.
private function dotest():void {
var text:String = ti.text;
remoteObject.getHelloWorld(text);
} // Handle the recevied message.
private function resultHandler(event:ResultEvent):void {
ta.text += "服务器返回: "+ event.result + "\n";
} // Handle a message fault.
private function faultHandler(event:FaultEvent):void {
ta.text += "Received fault: " + event.fault + "\n";
}
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject id="remoteObject"
destination="helloWorld"
result="resultHandler(event);"
fault="faultHandler(event);"/>
</fx:Declarations> <s:layout>
<s:VerticalLayout gap="10" />
</s:layout>
<s:Label text="输入名字"/>
<s:TextInput id="ti" text="Hello World!"/>
<s:Button label="Send" click="dotest();"/>
<s:TextArea id="ta" width="100%" height="100%"/>
</s:Application>
编译之后,在myeclipse的项目目录下会出现一个debug目录,如下:

修改index.jsp页面,加入超链接
<html>
<body>
<h2>Hello World!</h2>
<a href="dstest-debug/dstest.html">ddd</a>
</body>
</html>
好了,这样就可以启动访问了。
blazeds使用remote访问的更多相关文章
- blazeDS集成spring的remote访问
		
欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3490037.html 上一篇我只是简单实用blazeds创建了一个实例,大多数开发中,都是结合 ...
 - 关于remote访问中的flex端配置问题
		
刚刚开始使用blazeds可能会有个疑问.tomcat服务器是必须配置的吗?如果前台后台分开,怎么开发. 其实服务器不是必须配置的,配置了那个服务器,就会在“附加编译参数”加入这样一句: -servi ...
 - Flex httpservice返回值类型和处理 (转)
		
这两天在考虑flex与后端java服务交互的问题.在采用BlazeDS的Remote Object方式,还是传统的http service方式之间徘徊了一段时间 采用BlazeDS的Remote Ob ...
 - 在本机搭建mycat 单机环境,使用mariadb 伪集群
		
首先搭建mairadb的集群 master 使用端口3306 slave 使用端口3406 master 相关配置 在my.ini 文件的[mysqld] 节点中添加或修改如下配置 #允许其他机器re ...
 - Ubuntu14.04安装PowerDNS踩坑实录
		
公司要使用PowerDNS,作为内网域名解析的工具.让我和另一组的同事学一下如何配置及调优.所以先找了两台服务器试着安装一下.这一装就是一个礼拜,经历了大大小小的坑,记下来以后可能需要参考.安装过程如 ...
 - 【转帖】深挖NUMA
		
深挖NUMA http://www.litrin.net/2017/10/31/深挖numa/ 首先列出本站之前相关的几篇帖子: Linux的NUMA机制 NUMA对性能的影响 cgroup的cpus ...
 - 【转+自己研究】新姿势之Docker Remote API未授权访问漏洞分析和利用
		
0x00 概述 最近提交了一些关于 docker remote api 未授权访问导致代码泄露.获取服务器root权限的漏洞,造成的影响都比较严重,比如 新姿势之获取果壳全站代码和多台机器root权限 ...
 - 关于docker remote api未授权访问漏洞的学习与研究
		
漏洞介绍: 该未授权访问漏洞是因为docker remote api可以执行docker命令,从官方文档可以看出,该接口是目的是取代docker 命令界面,通过url操作docker. docker ...
 - Docker开启Remote API 访问 2375端口
		
Docker常见端口 我看到的常见docker端口包括: 2375:未加密的docker socket,远程root无密码访问主机2376:tls加密套接字,很可能这是您的CI服务器4243端口作为h ...
 
随机推荐
- delphi 中DLL的建立
			
Dll的创建与调用 File ->New->Other->Dll Wizard DLL的创建 //可以将本代码复制粘贴到项目中 library Project1; uses S ...
 - Tomcat以指定JDK运行
			
如果一台机器上有多个Tomcat,可能存在不同的Tomcat需要不同版本JDK才能运行的情况,这时候就需要指定JDK来同时运行多个Tomcat了. 在windows环境下以批处理文件方式启动tomca ...
 - 操作cookie
			
$.extend($, { setCookie: function(c_name, value, expiredays) { var exdate = new Date(); exdate.setDa ...
 - Shell脚本的安全性
			
Shell脚本给管理和使用系统都带来了巨大的便利,然后在多用户系统中,也带来了许多安全性问题.在脚本中可能存在的安全性问题如下: (1)在脚本中使用cd命令,切换到不安全的目录执行脚本. (2)在脚本 ...
 - C#开发---利用特性自定义数据导出到Excel
			
网上C#导出Excel的方法有很多.但用来用去感觉不够自动化.于是花了点时间,利用特性做了个比较通用的导出方法.只需要根据实体类,自动导出想要的数据 1.在NuGet上安装Aspose.Cells或 ...
 - Calendar Game
			
http://poj.org/problem?id=1082 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4820 A ...
 - cocos2dx新建android项目lib拷贝、访问权限等问题集
			
win7上面搭建cocos2dx的android项目,用create-android-project.bat新建一个项目时,出现了访问权限和项目无lib的问题. 解决方案: 1.项目无lib问题. 当 ...
 - Android(java)学习笔记114:LayoutInflater和findViewById
			
1. 在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById(). 不同点是LayoutInflater是用来找res/layout/下的xml布局文件, ...
 - Android(java)学习笔记80:UDP协议发送数据
			
UDP协议发送数据:我们总是先运行接收端,再运行发送端发送端: 1 package cn.itcast_02; import java.io.IOException; import java.net. ...
 - ResponseBody的使用
			
使用Spring的@ResponseBody有时还是挺方便的,在ajax调用返回纯字符串时有中文编码问题. @ResponseBody @RequestMapping(value="/dec ...