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 张辰 阅读(413) |
评论 (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 张辰 阅读(441) |
评论 (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 张辰 阅读(244) |
评论 (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 张辰 阅读(376) |
评论 (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 张辰 阅读(256) |
评论 (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 张辰 阅读(258) |
评论 (0) |
编辑 收藏