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

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2022-12-23
  • 2021-11-13
  • 2021-07-20
  • 2022-12-23
  • 2021-08-01
  • 2021-09-16
相关资源
相似解决方案