Flash 與后臺交互方式包括了:
1. LoadVars(xml) 實際上就是flash里面一個對象,類似一個連接器。新建之后,通過sendAndLoad獲取、設置值。和httpposter一樣
var data_lv = new LoadVars();
2. flash remoting. flash需要安裝components;后臺服務器需要OpenAMF。
gateway_conn = NetServices.createGatewayConnection(); myService = gateway_conn.getService("myservice", this);
3. webservice 也是在flash里面初始化一個ws的對象,然后調用。var ws:WebService = new WebService(ws_url);
4. XMLSocket 主要是即時通訊 var socket:XMLSocket = new XMLSocket();
5. 直接開flash的socket
http://androider.javaeye.com/blog/268933
在一個AMF交互的例子中,服務器建立一個MAP對象,例如:
HashMap map=new HashMap();
map.put("Event", "人物移動");
map.put("user", "閃刀浪子");
map.put("x", 100);
map.put("y", 100);
這樣flash就可以獲取這個對象:var obj:Object=new Object();
posted @
2010-06-17 14:15 張辰 閱讀(423) |
評論 (2) |
編輯 收藏
1. Spring IoC容器的意義
使用BeanFactory,根據制定的xml, 動態生成對象然后加載。
只要是從BeanFactory獲取的對象,都會根據xml進行裝配。
2. Spring MVC
在web.xml配置了DispatcherServlet,讓所有請求都被這個servlet攔截。同時配置了這個servlet的初始化對象。
。init-param = /WEB-INF/Config.xml ->
。viewResolver::org.springframework.web.servlet.view.InternalResourceViewResolver
。urlMapping::org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
這個urlMapping的目標,可能是被spring接管的對象,例如SimpleFormController
當配置了DispactcherServlet之后,通過設置合適的初始化對象,能夠實現某種MVC模式。
3. spring + blazeds 集成
http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/ch02s02.html
在web.xml配置了2個dispatcherservlet
。*.service === /WEB-INF/remoting-servlet.xml
。/messagebroker/* === /WEB-INF/flex-config.xml 表示把blazeds的請求映射到messagebroker
。第一個servlet繼續配置了urlMapping
==HessianServiceExporter可將一個普通bean導出成遠程服務 這樣這些被映射出來的service可以通過url訪問。
問題:這些service有固定的方法,比如execute,那么這些方法如何被調用了?代碼上看,是被command調用了。
回答:見第二個配置
。第二個servlet同樣配置了urlMapping;還包括
..MessageBrokerHandlerAdapter
..RemotingDestinationExporter -> callDisptacherService -> CallDispatcher -> Command.execute
問題:那么CallDispatcher的Call是如何調用的?
回答:在Flash的xml文件里面指定調用了。
這樣故事就全部被串起來了。
首先blazeds是個servlet,被封裝過后,能夠解析flash傳輸的amf格式。
通過spring的配置,flash的請求被轉移到了messagebroker = blazeds,同時這個messagebroker依賴了特定的bean,例如callHandler. 這些handler又依賴了service 的屬性,這個屬性就是我可以控制的,同時被flash調用的。
例如
what is web.xml :: listener
它能捕捉到服務器的啟動和停止! 在啟動和停止觸發里面的方法做相應的操作!
一定是httpServlet
http://zhidao.baidu.com/question/39980900
如何加載services-config.xml
MessageBrokerFactoryBean將會去尋找BlazeDS的配置文件(默認位置為/WEB-INF/flex/services-config.xml)
posted @
2010-06-17 09:33 張辰 閱讀(449) |
評論 (2) |
編輯 收藏
本文講解一個不規范的spring quick start.
1. 下載spring的插件包,什么版本之類的不用管了。反正能用。
spring.jar
http://www.boxcn.net/shared/yg306zac1h
common-logging.jar
http://www.boxcn.net/shared/ix93ziqljv
2. 進入eclipse,File - New - Java Project.
projectname = spring001 ===> Next
在新建導向的第二頁,是Java Settings, 選擇Libraries -> Add External JARS -> 添加上面2個jar
finish
3. 進入Package Explorer, 在src下新建一個class.
Package = com.java114.spring.test
Name = HelloWordSpring
再復選框:public static void main(String[] args) 鉤上
4. 在HelloWordSpring.java 輸入以下的代碼
package com.java114.spring.test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class HelloWordSpring
{
private String msg;
public void setMsg(String msg)
{
this.msg = msg;
}
public void sayHello()
{
System.out.println(msg);
}
public static void main(String[] args)
{
Resource res = new ClassPathResource("com/java114/spring/test/bean.xml");
BeanFactory factory = new XmlBeanFactory(res);
HelloWordSpring hello = (HelloWordSpring) factory.getBean("helloBean");
hello.sayHello();
}
}
5. 在和HelloWordSpring.java 相同目錄下面,再新建一個xml文件,名字是bean.xml, 內容如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="helloBean" class="com.java114.spring.test.HelloWordSpring">
<property name="msg" value="simple spring demo"/>
</bean>
</beans>
為什么這樣寫,我也不知道,不管他。
6. 鼠標右鍵選擇HelloWordSpring.java, 選擇Run As - Java Applications, 得到結果:
2010-6-16 21:39:47 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [com/java114/spring/test/bean.xml]
simple spring demo
posted @
2010-06-16 20:13 張辰 閱讀(251) |
評論 (0) |
編輯 收藏
比較難的一部分
前提條件:
axis安裝路徑 C:\ericsson\javaextend\axis-1_4
項目名稱:axisdemo
已經有的類:com.service.myService.java
配置文件:server-config.wsdd
1. 在項目添加java2wsdl目錄
2.目錄下面添加build.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project name="Generate WSDL from JavaBeans as Web Services" default="j2w-all" basedir=".">
<property name="build.dir" value="../build/classes" />
<property name="axis.dir" location="C:\ericsson\javaextend\axis-1_4" />
<path id="classpath.id">
<fileset dir="${axis.dir}/lib">
<include name="*.jar" />
</fileset>
<pathelement location="${build.dir}" />
</path>
<taskdef name="axis-java2wsdl" classname="org.apache.axis.tools.ant.wsdl.Java2WsdlAntTask" loaderref="axis">
<classpath refid="classpath.id" />
</taskdef>
<target name="j2w-all">
<antcall target="j2w-JavaBeanWS" />
</target>
<target name="j2w-JavaBeanWS">
<axis-java2wsdl classname="com.service.myService" classpath="${build.dir}" methods="getusername" output="myService.wsdl" location="http://localhost:8080/axisdemo/services/myService" namespace="http://localhost:8080/axisdemo/services/myService" namespaceImpl="http://localhost:8080/axisdemo/services/myService">
</axis-java2wsdl>
</target>
</project>
注意:build.dir / axis.dir / j2w-javabeanws幾個地方的內容要修改。
3. 右鍵點擊build.xml,運行ant,就可以看到生成了myService.wsdl
4.現在要把這個wsdl轉化成為java,新建目錄:wsdl2java
5. 新建一個build.xml,內容:
<?xml version="1.0" encoding="UTF-8"?>
<project name="wsclient" default="all" basedir=".">
<property name="axis.home" location="C:\ericsson\javaextend\axis-1_4" />
<property name="options.output" location="../wsdl2java" />
<path id="axis.classpath">
<fileset dir="${axis.home}/lib">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath" />
<target name="-WSDL2Axis" depends="init">
<mkdir dir="${options.output}" />
<axis-wsdl2java output="${options.output}" url="${options.WSDL-URI}" verbose="true" />
</target>
<target name="init">
<echo>Warning: please update the associated WSDL file(s) in the folder wsdl before running the target!</echo>
<echo>Warning: Just run the target(s) related with your developing work!</echo>
<echo>
</echo>
</target>
<target name="all">
<antcall target="myService" />
</target>
<target name="myService">
<antcall target="-WSDL2Axis">
<param name="options.WSDL-URI" location="../java2wsdl/myService.wsdl" />
</antcall>
</target>
</project>
注意修改的地方:axis.home
6.build ant,在wsdl2java目錄下面多出來了4個類:
myService.java
MyServiceService.java
myServiceServiceLocator.java
MyServiceSoapBindingStub.java
全部拷貝到src目錄下面
7.在src目錄下面添加類:
package com.axistest;
import localhost.axisdemo.services.myService.MyService;
import localhost.axisdemo.services.myService.MyServiceServiceLocator;
public class myServiceTestorByStubs
{
public static void main(String[] args) throws Exception
{
MyServiceServiceLocator Service = new MyServiceServiceLocator();
MyService port = Service.getmyService();
String response port.getusername(鄒萍");
System.out.println(response);
}
}
8.最后運行java application就完成了
posted @
2008-12-18 11:03 張辰 閱讀(385) |
評論 (0) |
編輯 收藏