Spring 遠程調用 HTTP invoker

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章