一: 暴露服务(HttpRequestHandlerServlet 暴露服务)
package com.xx.service;
public interface ISayHelloService {
/**
* @param name
* @return
*/
String doSayHello(String name);
}
package com.xx.service.impl;
import com.xx.service.ISayHelloService;
public class DefaultSayHelloServiceImpl implements ISayHelloService {
public String doSayHello(String name) {
return "hello, " + name;
}
}
web.xml
<!-- ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/applicationContext-server.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- HttpRequestHandlerServlet -->
<!-- servlet-name 必须和暴露的seviceProxy bean id相同 -->
<servlet>
<servlet-name>sayHelloServiceExporter</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sayHelloServiceExporter</servlet-name>
<url-pattern>/sayHelloService.service</url-pattern>
</servlet-mapping>
applicationContext-server.xml
<bean id="defaultSayHelloService" class="com.xx.service.impl.DefaultSayHelloServiceImpl" />
<!-- 和web.xml servlet-name 一致 -->
<bean id="sayHelloServiceExporter" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" >
<property name="service" ref="defaultSayHelloService" />
<property name="serviceInterface" value="com.xx.service.ISayHelloService" />
</bean>
二:客户端
package com.xx.service;
public interface ISayHelloService {
/**
* @param name
* @return
*/
String doSayHello(String name);
}
applicationContext-client.xml
<bean id="sayHelloService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/httpInvoker2/sayHelloService.service" />
<property name="serviceInterface" value="com.xx.service.ISayHelloService"/>
</bean>
public class ClientMain {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext-client.xml");
ISayHelloService sayHelloService = applicationContext.getBean("sayHelloService", ISayHelloService.class);
System.out.println(sayHelloService.doSayHello("王五"));
}
}
分享到:
相关推荐
公司内部讲义,比较了SOA,RMI和Spring HttpInvoker。并介绍了Spring HttpInvoker的基本使用方法。
Spring HttpInvoker,是一套基于Maven+Spring+SpringMVC+MyBatis框架,还包含了Invoker的客户端及服务器端的demo实例
Spring httpInvoker使用标准java序列化机制,通过Http暴露业务服务。如果你的参数和返回值是比较复杂的,通过httpInvoker有巨大的优势。 1. 远程访问流程 1) 服务端定义服务接口 2) 服务端实现服务接口 3) 暴露服务...
org.springframework.remoting.httpinvoker最基本的实现例子,这是3个eclipse的JavaEE工程,全部导入即可,能运行。 初学可以轻松了解Spring HttpInvoker 的结构和使用。
NULL 博文链接:https://tou3921.iteye.com/blog/1729111
spring+httpInvoker 实例,含服务端和客户端代码,myEclipse工程,直接导入就可以测试,适合初学者. 提供 普通参数返回值和自定义对象返回值,两个方式.
Spring HTTP Invoker是spring框架中的一个远程调用模型,执行基于HTTP的远程调用,也就是说,可以通过防火墙,并使用java的序列化机制在网络间传递对象。客户端可以很轻松的像调用本地对象一样调用远程服务器上的...
NULL 博文链接:https://lggege.iteye.com/blog/369151
springboot-httpinvoker-demo.zip
和Hessian的轻量级传输协议不同的是,Spring HttpInvoker使用Java序列化来序列化参数和返回值,然后基于HTTP协议传输经序列化后的对象。当参数或返回值是复杂类型,并且不能通过Hessian的序列化机制序列化时,...
基于Spring的HttpInvoker实现改写服务器端调用: HttpInvoker.invoker 方法,设置InvokerProcess处理客户端调用: ProxyFactory.proxy 方法,生成接口的代理对象,直接调用方法客户端和服务器端的接口和实体类要...
NULL 博文链接:https://lggege.iteye.com/blog/404124
但当传递过来的RPC消息中包含序列化... Spring开发团队意识到RMI服务和基于HTTP的服务之前的空白,Spring的HttpInvoker应运而生。 Spring的HttpInvoker,它基于HTTP之上提供RPC,同时又使用了Java的对象序列化机
接口测试工具,不太好用,不建议使用,自己传着玩儿的
NULL 博文链接:https://lee79.iteye.com/blog/926647
NULL 博文链接:https://lee79.iteye.com/blog/943207
org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.class org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor.class org.springframework.remoting....
项目工程结构如下图所示,除了包含spring定义远程服务org.springframework.remoting.httpinvoker.*部分节点代码(红框框部分,具体设计代码部分参考相关代码示例说明文章),还包含springmvc等其他示例部分可以忽略...
使用 spring 的 httpinvoker 进行远程调用