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 是相同的。

  • 相关阅读:
    uiwebview的基本使用
    当你在浏览器地址栏输入一个URL后回车,将会发生的事情?
    开车误闯红灯的补救方法 (以及由此引发的一些思考)
    Android源码剖析之Framework层基础版(窗口、linux、token、Binder)
    Android项目框架之图片加载框架的选择
    通过runtime替换系统类实现的代码(从github开源库fdstackview中摘录)
    awakeFromNib相关知识详解
    推送服务推荐
    由微博图床挂掉之后想到的
    Mac下如何配置环境变量
  • 原文地址:https://www.cnblogs.com/chenying99/p/2555626.html
Copyright © 2011-2022 走看看