ImageVerifierCode 换一换
格式:DOCX , 页数:9 ,大小:38.42KB ,
资源ID:8973037      下载积分:10 金币
验证码下载
登录下载
邮箱/手机:
图形码:
验证码: 获取验证码
温馨提示:
支付成功后,系统会自动生成账号(用户名为邮箱或者手机号,密码是验证码),方便下次登录下载和查询订单;
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/8973037.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请。


权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4009-655-100;投诉/维权电话:18658249818。

注意事项

本文(http接口.docx)为本站上传会员【xrp****65】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

http接口.docx

1、Spring HTTP invoker 简介 Spring HTTP invoker 是 spring 框架中的一个远程调用模型,执行基于 HTTP 的远程调用(意味着可以通过防火墙),并使用 java 的序列化机制在网络间传递对象。客户端可以很轻松的像调用本地对象一样调用远程服务器上的对象,这有点类似于 webservice ,但又不同于 webservice ,区别如下: webservice HTTP invoker 跨平台,跨语言 只支持 java 语言 支持 SOAP ,提供 wsdl 不支持 结构庞大,依赖特定的 webservice 实现,如 xfire等 结构

2、简单,只依赖于 spring 框架本身 项目中使用哪种远程调用机制取决于项目本身的要求。 ² HTTP invoker 服务模式   说明: 1. 服务器端:通过 HTTP invoker 服务将服务接口的某个实现类提供为远程服务 2. 客户端:通过 HTTP invoker 代理向服务器端发送请求,远程调用服务接口的方法 3. 服务器端与客户端通信的数据需要序列化     配置服务器端和客户端的步骤 配置服务器端 1. 添加 springJAR 文件 建议使用 spring2+.jar 版本 2. 创建服务接口 3. 创建服务接口的具体实现类 4. 公开服

3、务   配置客户端 1. 添加 springJAR 文件 建议使用 spring2+.jar 版本 2. 创建服务接口 3. 访问服务   实例讲解 服务器端 1. 服务接口: UcService.java 它提供两项服务,查询用户信息和记录日志,如下: public interface UcService { public UserInfo getUserInfobyName(String userName); public int recordLog(String username, String point, String operate, String de

4、sc); } 说明:举这个列子是因为其比较有代表性,它将展示普通数据类型( int,long 等)和复杂数据类型( DTO 等)的远程调用方式。 UserInfo 是一个普通的 DTO ,代码如下: public class UserInfo implements Serializable { private static final long serialVersionUID = -6970967506712260305L; /** 用户名 */ private String userName ; /** 电子邮箱 */ private String email ; /**

5、 注册日期 */ private Date registDate ;   public String getUserName() { return userName ; } public void setUserName(String userName) { this . userName = userName; } public String getEmail() { return email ; } public void setEmail(String email) { this . email = email; } public Date getRegis

6、tDate() { return registDate ; } public void setRegistDate(Date registDate) { this . registDate = registDate; } } 注意:因为是在网络间传输对象,所以需要将 UserInfo 实现 Serializable 接口,并指定一个 serialVersionUID (任意值即可,同时客户端也要有这个类,否则在客户端接收对象时会因为 serialVersionUID 不匹配而出现异常) 回到UcService.java ,它提供了两个服务(在这里一个方法代表一个服务功能),我们

7、需要具体的实现类来实现真正的服务   2. 实现类是 UCServiceImpl.java public class UCServiceImpl implements UcService { private static Logger pointrecordlog = Logger.getLogger ( "pointrecordlog" ); private static Logger logger = Logger.getLogger (UCServiceImpl. class ); private UcFacade ucFacade ; public void setUcF

8、acade(UcFacade ucFacade) { this . ucFacade = ucFacade; } public UserInfo getUserInfobyName(String userName) { UserInfo user = null ; try { user = ucFacade .getUserInfoDetail(userName); logger .debug( "get userinfo success by username:" + userName); } catch (Throwable t) { logger .error( "ge

9、t userinfo fail by username:" + userName, t); } return user; } public int recordLog(String username, String point, String operate, String desc) { int result = 0; try { pointrecordlog .info(username + " - " + point + " - " + operate + " - " + desc); } catch (Throwable t) { result = -1; logg

10、er .error(t); } return result; } } 说明: ucFacade 是通过 spring 注入的一个数据查询类,因为它与 http invoker 没有直接关系,所以不进行介绍。 3. 公开服务 UcService.java ² WEB-INF/application-context.xml :将接口声明为 HTTP invoker 服务 < bean id = "httpService" class = "org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" >

11、 < property name = "service" > < ref bean = "ucService" /> < property name = "serviceInterface" value = "qin.baike.service.UcService" > < bean id = "ucService" class = "qin.baike.service.impl.UCServiceImpl" /> 说明: HttpInvokerServiceExporter 实际上是一个 spring

12、 mvc 控制器,它处理客户端的请求并调用服务实现。 ² WEB-INF/service-servlet.xml : HttpInvokerServiceExporter 实际上是一个 spring mvc 控制器,所以需要为其 提供 spring URL 处理器,这里我们使用 SimpleUrlHandlerMapping < bean class = "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > < property name = "mappings" > < props > < prop

13、 key = "/httpService" > httpService  ² WEB-INF/web.xml :配置 spring 监听及 DispatcherServlet < context-param > < param-name > contextConfigLocation  < param-value > /WEB-INF/application-context.xml  

14、 < listener > < listener-class > org.springframework.web.context.ContextLoaderListener   < servlet > < servlet-name > service < servlet-class >             org.springframework.web.servlet.DispatcherServlet              

15、    < load-on-startup > 1             < servlet-mapping >         < servlet-name > service          < url-pattern > /service/*       说明:不了解为什么这么配置的可以去看看 spring mvc 方面的资料。   好了,经过以上配置,一个基于 spring HTTP invoke

16、r 的远程服务就完成了,服务的地址为: http://${serviceName}:${port}/${contextPath}/service/httpService   客户端 1.        创建服务接口及网络间传输的 DTO 类 为了方便,可以将服务器端创建好的的 UcService.java 和 UserInfo.java 拷贝到客户端 , 或打个 jar 包放到 lib 下。 2.        配置访问服务 ²       WEB-INF/application-context.xml :如果项目中已经存在 spring 配置文件,则不需要创建该文件,需要配置 

17、HTTP invoker 的代理 < bean id = "httpService" class = "org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean" >         < property name = "serviceUrl" >             < value > http://${serviceName}:${port}/${contextPath}/service/httpService                  

18、< property name = "serviceInterface"             value = "qin.baike.service.UcService" >          说明:客户端使用 HttpInvokerProxyFactoryBean 代理客户端向服务器端发送请求,请求接口为 UcService 的服务 注意:需要修改 serviceUrl 为实际的服务器地址 ²         WEB-INF/web.xml :配置 spring 监听 如果项目没有 spring 环境,则需要在 web.xml 中

19、加入对 spring 的支持 < context-param >         < param-name > contextConfigLocation          < param-value >             /WEB-INF/application-context.xml                     < listener >         < listener-class >             org.springframework.w

20、eb.context.ContextLoaderListener            3.        访问服务方法 u         读取 spring 上下文,以远程调用 getUserInfobyName 方法为例 ²         在 jsp,servlet,action 等等文件中 UcService service = (UcService) WebApplicationContextUtils         .getRequiredWebApplicationContext(      

21、       request.getSession().getServletContext()).getBean(             "httpService" ); UserInfo user = service .getUserInfobyName( "hanqunfeng" );   ²         如果不想配置 spring 运行环境,可以使用如下方式: ApplicationContext applicationContext = new FileSystemXmlApplicationContext( "classpath:application-contex

22、t.xml" ); service = (UcService) applicationContext.getBean( "httpService" ); u         依赖注入,远程调用 recordLog 方法为例 ²         在 WEB-INF/application-context.xml 中加入如下配置: < bean id = "abc" class = "qin.test.abc" >         < property name = "service" >             < ref bean = "httpService" />      

23、    ²         为 qin.test.abc 中加入对 service 的 set 方法: private UcService service ;     public void setService(UcService service){         this . service = service;     }       public String recordUserLog(String username,String point,String operate,String desc){         S

24、tring result = service .recordLog(username, point, operate, desc);         return result; }       关于服务器端配置的补充说明:  有一个误区:有些关于springMVC的书 上说,如果没有明确声明一个处理适配器,默认会使用 org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,这个适配器 专门负责处理所有实现了 org.springframework.web.servlet.mvc.Controller

25、 接口的处理器,我就是受其影响,认为 org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter实现的是 org.springframework.web.HttpRequestHandler接口,所以按理说应该使用的处理适配器是 org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,但实际上并不会出现异 常。 其实,原因是因为spring默认会使用四个处理适配器(参看DispatcherServlet.properties,spring2.5,sp

26、ring2.0只默认三个,2.5增加注解方式): org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,/  org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,/  org.springframework.web.servlet.mvc.throwaway.ThrowawayControllerHandlerAdapter,/  org.springframework.web.servlet.mvc.annotation.Annota

27、tionMethodHandlerAdapter  关于DispatcherServlet.properties的详细信息可以参看: 但是,如果明确声明了其它的处理适配器,比如 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter, 等等,则默认规则则会覆盖,需要明确声明 org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter这个处理适配器,否则系 统会抛异常: javax.servlet.ServletExcept

28、ion: No adapter for handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter@179bd14]: Does your handler implement a supported interface like Controller? 所以,建议在使用spring invoker时,最好明确声明org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter这个处理适配器 补充: 默认情况下,客户端的HttpInvo

29、kerProxy使用J2SE的HTTP Client来建立连接,即org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor,可以通过设置httpInvokerRequestExecutor属性来改变默认配置,spring提供了另外一种HttpClient,org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor。 修改配置如下: :4080/ucs/service/httpService 需要在项目中引入两个jar包: commons-codec-x.x.jar commons-httpclient-x.x.x.jar CommonsHttpInvokerRequestExecutor具有HTTP connection pooling,不过通过使用jmeter进行压力测试发现,SimpleHttpInvokerRequestExecutor性能高于CommonsHttpInvokerRequestExecutor

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服