Spring HTTP invoker是spring框架中的一个远程调用模型,执行基于HTTP的远程调用(意味着可以通过防火墙),并使用java的序列化机制在网络间传递对象。
所以所有的pojo类必须实现序列化接口
webservice | HTTP invoker |
跨平台,跨语言 | 只支持java语言 |
支持SOAP,提供wsdl | 不支持 |
结构庞大,依赖特定的webservice实现,如xfire等 | 结构简单,只依赖于spring框架本身 |
client:
<bean id="rciClientService"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="serviceUrl">
<value>
${rci.service.url}/oprisk/kor/servlet/rciHttpService
</value>
</property>
<property name="serviceInterface">
<value>
com.citi.oprisk.kor.service.IRCIClientService
</value>
</property>
</bean>
build.xml:
<path id="compileClasspath">
<pathelement path="${ejbclient.dir}/RCI_client.jar" />
</path>
*-remote-call.properties:
rci.service.url=http://localhost:9080
sever:
<bean id="rciHttpService"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" >
<property name="service">
<ref bean="rciClientService" />
</property>
<property name="serviceInterface"
value="com.citi.oprisk.kor.service.IRCIClientService">
</property>
</bean>
<bean id="rciClientService"
class="com.citi.oprisk.kor.service.RCIClientService">
<property name="korMaintainService">
<ref bean="korMaintainService" />
</property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true" />
<property name="mappings">
<props>
<prop key="/servlet/rciHttpService">rciHttpService</prop>
</props>
</property>
</bean>
build.xml:
<target name="rciClientJar" depends="init,compile">
<jar jarfile="${distDir}/RCI_client.jar"
basedir="${javaClassDir}">
<include name="com/citi/oprisk/kor/service/IRCIClientService.class"/>
......
</jar>
</target>
步骤:
1. 创建一个HTTP invoker服务输出者类(HttpInvokerServiceExporter)
2. 创建一个HTTP代理(使用HttpInvokerProxyFactoryBean)。你要细化这个类里的参数像serviceUrl和serviceInterface。
3. 为客户端调用远程HTTP服务定义一个URL映射。
4. 配置Spring beans。
5. 在web。xml文件里配置Spring Web层(DispatcherServlet)。
6. 写客户类(使用HTTP或者Commons HttpClient)。