加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

BlazeDS配置文件说明

发布时间:2020-12-15 03:53:35 所属栏目:百科 来源:网络整理
导读:默认的配置有四个文件,都在WEB-INF/Flex目录下,分别为:web.xml,services.xml和remoting-config.xml.配置文件加载的顺序为web.xml - service-config.xml - remoting-config.xml. 1).web.xml配置文件 web.xml是部署描述文件,Web应用服务器(Tomcat or Websphere

默认的配置有四个文件,都在WEB-INF/Flex目录下,分别为:web.xml,services.xml和remoting-config.xml.配置文件加载的顺序为web.xml -> service-config.xml -> remoting-config.xml.

1).web.xml配置文件

web.xml是部署描述文件,Web应用服务器(Tomcat or Websphere)启动后首先加载该文件.关键代码如下:

<listener>        <listener-class>flex.messaging.HttpFlexSession</listener-class>    </listener>

配置项<listener>用于将HttpFlexSession类作为监听器注册到web.xml中,这样系统就可以检测到J2EE HttpSession属性和代理属性的变化,进而通知FlexSession属性和目前绑定的listener做相应处理.

<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>

BlazeDS提供了一个Servlet作为它和Servlet容器之间的桥.MessageBrokerServlet的Servlet将负责对对所有URL符合/messagebroker/*模式的请求进行处理,它会在Servlet容器启动时启动,并在启动时读取配置文件/WEB-INF/flex/services-config.xml.

?

2). 服务配置文件services-config.xml

MessgaeBrokerServlet在启动时需要services-config.xml提供的信息对BlazeDS的组件进行配置,services-config.xml包含BlazedDS引用的服务文件,安全设置,通道定义,系统参数.

<logging>        <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>

其中<target class>为日志信息的目标,默认的目标是控制台输出,即System.out(Java).若要使用Servlet日志文件作为目标,将class属性改为"flex.messaging.log.ServletLogTarget".

其中level="Error"为日志的记录级别.有None,Error,Warn,Info,Debug,All六种选择.

其中<properties>为日志信息的显示格式.包括信息前缀(prefix)以及是否包含时间(includeTime),日期(includeDate),级别(includeLevel)或者类别.

其中<filters>为信息的过滤条件,只有匹配的类别才会被记录到指定的目标中.

<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>


?

其中redeployservices-config.xml配置成重新部署的模式,即当BlazeDS发现配置文件被修改后,会通知web应用容器重新部署Web应用.由于这样会降低应用的性能,建议开发时使用.

其中watch-interval为每隔20秒检测watch-file标签包含的文件的状态.

<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>


?

其中security为配置安全性选项,然而,为remoting-config.xml或message-config.xml中的service添加安全性选项也是可以的.目的是只有通过身份验证,并具有某些role的用户才可以访问相应的destination.

其中security-constraint为安全约束.可以为destination应用安全约束.定义的方式有两种:一种是引用,一种是在destination定义的内部声明安全约束.

<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>


?

其中channel-definition定义了Channel的标识及其实现类.

其中endpoint定义了endpoint的实现类和Channel和Endpoint通信的url.

Channel的作用就是帮助我们传输消息.Channel使用URL与Endpoint通信.Endpoint就是消息传输的接收器,它并不真正处理消息,它将处理过程委托给service.这样就分离了协议和消息类型这两个正交的关注点.Endpoint在接收到消息时会根据消息的destination获得合适的service,然后调用service.service.Message方法处理消息.BlazeDS定义了RemotingService,HttpProxyService,MessageService三类service,分别处理前端RemoteObject,HTTPService和WebService等组件发起的请求.

<services>        <service-include file-path="remoting-config.xml" />        <service-include file-path="proxy-config.xml" />        <service-include file-path="messaging-config.xml" />        </services>


?

Service有两种配置方式,第一种是在service-config.xml的services标签下,即内部配置;另一种是将service配置如上,配置独立文件的方式,并使用service-include将此文件包含进来.

3). 远程服务配置文件remoting-config.xml

<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="com.flex.users.EmployeeFacade"><properties><source>com.flex.users.EmployeeFacade</source></properties></destination></service>


?

其中根元素service指定远程服务的id和对应的类.

其中adapters为用户设置设配器.

其中子标签channel的ref属性表明引用了信息通道.

其中destination设置服务终端的目的地,属性id为客户端组件RemoteObject的destination

?

总结:BlazeDS需要配置有,MessageBrokerServlet,service-config.xml,Channel和Endpoint,Service,Adaper和Destination,Logging,Security.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读