zoukankan      html  css  js  c++  java
  • Http Invoker

    Http Invoker使用HTTP传送物件,传送时使用Java的序列化机制来传送,由于透过HTTP传送,所以 在使用它们时要搭配Spring Web框架来使用,也就是使用到DispatcherServlet,可以改写 Hessian、 Burlap,只要修改一下service‐config.xml就可以了:

    •      service‐config.xml
    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN""http://www.springframework.org/dtd/spring-beans.dtd"> <beans> 	<bean id="urlMapping" class="org.springframework.web.servlet. 		→ handler.SimpleUrlHandlerMapping"> 		<property name="mappings"> 			<props> 				<prop key="/some.service">serviceExporter</prop> 			</props> 		</property> 	</bean> 	<bean id="viewResolver" class="org.springframework.web.servlet. 		→ view.InternalResourceViewResolver"> 		<property name="prefix"> 			<value>/WEB-INF/jsp/</value> 		</property> 		<property name="suffix"> 			<value>.jsp</value> 		</property> 	</bean> 	<bean id="someService" class="onlyfun.caterpillar.SomeServiceImpl"/> 	<bean id="serviceExporter" class="org.springframework.remoting. 		→ httpinvoker.HttpInvokerServiceExporter"> 		<property name="service"> 			<ref bean="someService"/> 		</property> 		<property name="serviceInterface"> 			<value>onlyfun.caterpillar.ISomeService</value> 		</property> 	</bean> </beans>bsp;

    接下来客户端的部份,可以改写 Hessian、Burlap  的内容,修改一下Bean定义档的内容:

    •      invoker‐client.xml
    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN""http://www.springframework.org/dtd/spring-beans.dtd"> <beans> 	<bean id="someServiceProxy" class="org.springframework.remoting. 		→ httpinvoker.HttpInvokerProxyFactoryBean"> 		<property name="serviceUrl"> 			<value> 				http://localhost:8080/HttpInvokerDemo/some.service 			</value> 		</property> 		<property name="serviceInterface"> 			<value>onlyfun.caterpillar.ISomeService</value> 		</property> 	</bean> </beans>

    注意到"serviceUrl"属性的设定,它是个标准的 HTTP 请求位址,来撰写个简单的客户端程式以使 用 Http Invoker 伺服器上的服务:

    •      HessianClient.java
    package onlyfun.caterpillar; import org.springframework.context.ApplicationContext; import org.springframework.context. support.FileSystemXmlApplicationContext; public class HessianClient { 	public static void main(String[] args) {  		ApplicationContext context =new FileSystemXmlApplicationContext( "invoker-client.xml"); 		ISomeService service =(ISomeService) context.getBean("someServiceProxy"); 		String result1 = service.doSomeService("Some request");  		System.out.println(result1); 		int result2 = service.doOtherService(1);  		System.out.println(result2); 	} }

    执行的结果与 RMI 是相同的。

  • 相关阅读:
    设计模式之一(策略模式)
    电脑开机进入不了XP界面
    IBM X系列笔记本通过U盘安装系统方法全攻略
    DELPHI 访问其它电脑文件(局域网)
    笔记本维修小插曲 屏幕不亮处理方式
    delphi 笔记
    电脑小子的新婚夜
    如何得到动态链接库的输出函数(delphi tdump.exe)
    sql server重复数据处理
    如何使用jQuery向asp.net Mvc传递复杂json数据Filter篇
  • 原文地址:https://www.cnblogs.com/chenying99/p/2555626.html
Copyright © 2011-2022 走看看