posts - 32,comments - 8,trackbacks - 0
          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 張辰 閱讀(253) | 評論 (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 張辰 閱讀(386) | 評論 (0)編輯 收藏
          reference:
           part1


          1. in package explorer, change myService.java:
          package com.service;
          public class myService {
          public String getusername(String name){
                  
          return "Hello "+name+",this is an Axis Web Service";
              }
          }
          and ctrl+1 to solve the package problem( or you can create dir and move file yourself)

          2.in WebContent/WEB-INF/, create server-config.wsdd
          <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
          <handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>    
             
          <service name="myService" provider="java:RPC">
                  
          <parameter name="className" value="com.service.myService"/>
                  
          <parameter name="allowedMethods" value="getusername"/>
              
          </service> 
          <transport name="http">
           
          <requestFlow>
              
          <handler type="URLMapper"/>
           
          </requestFlow>
          </transport>
          </deployment>

          3. in src/, create myServiceTestorByWSDD.java
          import java.net.MalformedURLException;
          import java.rmi.RemoteException;
          import javax.xml.rpc.ServiceException;
          import org.apache.axis.client.Call;
          import org.apache.axis.client.Service;
          public class myServiceTestorByWSDD {
          public tatic void main(String[] args) throws ServiceException,MalformedURLException, RemoteException {
                  String endpoint 
          = http://localhost:8080/oopsaxis1/services/myService;
                  Service service 
          = new Service();                // 創建一個Service實例,注意是必須的!
                  Call call = (Call) service.createCall();   // 創建Call實例,也是必須的!
                  call.setTargetEndpointAddress(new java.net.URL(endpoint));// 為Call設置服務的位置
                  call.setOperationName("getusername");              // 注意方法名與JavaBeanWS.java中一樣!!
                  String res = (String) call.invoke(new Object[] { "pixysoft" });       // 返回String,傳入參數
                  System.out.println(res);
          }
          }

          4. open tomcat, and :http://localhost:8080/oopsaxis1/servlet/AxisServlet,you can see:
          And now Some Services
          myService (wsdl) 
          getusername 

          5. right click myServiceTestorByWSDD.java, run as java application.


          done!

          posted @ 2008-12-17 13:51 張辰 閱讀(264) | 評論 (0)編輯 收藏

          reference:

          http://www.cnblogs.com/cy163/archive/2008/11/28/1343516.html

          pre-condition:
          1.install eclipse
          2.install tomcat plugin

          process:
          1.download axis lib: http://ws.apache.org/axis

          2. set classpath:
          1.AXIS_HOME
          D:\Java\axis-1_4(這是我的Axis路徑)
          2.AXIS_LIB
          %AXIS_HOME%\lib
          3.AXIS_CLASSPATH
          %AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar;%AXIS_LIB%\wsdl4j-1.5.1.jar;%AXIS_LIB%\activation.jar;%AXIS_LIB%\xmlrpc-2.0.jar
          4.CLASSPATH
          .;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar; %AXIS_CLASSPATH%;
          5.在你的%TOMCAT_HOME%\common\lib下需要加入三個包 activation.jar、mail.jar、tools.jar,注意這三個包是必須的,盡管tools.jar很常見,但這也是運行Axis所必須的包。


          3.FIle - new - dynamic web project
          projectname: oopsaxis1
          target runtime: apache tomcat V5.5


          4. oopsaxis1/WebContent/WEB-INF/lib,add lib from %AXIS_HOME%\lib
          axis.jar/axis-ant.jar/commons-log.jar...

          5.oopsaxis1/WebContent/WEB-INF/web.xml,  replace by %AXIS_HOME%\webapps\axis\WEB-INF\web.xml

          6.oopsaxis1/src, add java file:
          public class myService
          {
              
          public String getusername(String name)
              {
                  
          return "Hello " + name + ",this is an Axis DII Web Service";
              }
          }


          7.copy myService to oopsaxis1/WebContent, and rename to myService.jws

          8. right click myService.jws, run as - run on server, you can see:
          http://localhost:8080/oopsaxis1/myService.jws
          There is a Web Service here
          Click to see the WSDL 
          click the link, you can see the wsdl


          9. in eclipse - package explorer - src, new class:
          package com.oopsaxis;

          import java.net.MalformedURLException;
          import java.rmi.RemoteException;

          import javax.xml.rpc.ParameterMode;
          import javax.xml.rpc.ServiceException;

          import org.apache.axis.client.Call;
          import org.apache.axis.client.Service;
          import org.apache.axis.encoding.XMLType;

          public class myServiceTestorByjws
          {
              
          public static void main(String[] args) throws ServiceException,
                      MalformedURLException, RemoteException
              {
                  String endpoint 
          = http://localhost:8080/oopsaxis1/myService.jws;
                  String name 
          = " pixysoft";
                  Service service 
          = new Service();
                  Call call 
          = (Call) service.createCall();

                  call.setTargetEndpointAddress(
          new java.net.URL(endpoint));
                  call.addParameter(
          "param1", XMLType.XSD_STRING, ParameterMode.IN);
                  call.setOperationName(
          "getusername");
                  call.setReturnType(XMLType.XSD_STRING);
                  String ret 
          = (String) call.invoke(new Object[] { name });
                  System.out.println(
          "返回結果:" + ret);
              }
          }

          10. right click myServiceTestorByjws, run as java application,you get:
          返回結果:Hello pixysoft,this is an Axis DII Web Service

          done!
          posted @ 2008-12-17 13:40 張辰 閱讀(269) | 評論 (0)編輯 收藏
          主站蜘蛛池模板: 拉萨市| 鄂尔多斯市| 旬阳县| 绵阳市| 富阳市| 阿瓦提县| 安丘市| 乌苏市| 都江堰市| 抚宁县| 房产| 习水县| 老河口市| 化州市| 新安县| 武邑县| 香格里拉县| 崇左市| 徐州市| 临高县| 阿拉尔市| 杨浦区| 紫金县| 文山县| 合作市| 萝北县| 京山县| 工布江达县| 保康县| 定远县| 台江县| 尖扎县| 独山县| 碌曲县| 巫溪县| 万州区| 平潭县| 舞钢市| 微博| 阳朔县| 罗定市|