在Axis1中使用HTTP长连接
2015-06-28 12:41
639 查看
在eclipse中用Axis1.4的插件生成的代码默认使用HTTP/1.0版本,并且在请求头中不包含Connection:keep-Alive
每次通信前都要新建连接,通信结束后关闭连接
当请求量很大时,将频繁的创建、关闭连接,十分消耗性能,所以考虑使用HTTP长连接
HTTP/1.1默认使用持久连接(HTTP/1.1逐渐停止了对Keep-Alive的支持,用一种名为持久连接的改进型设计取代了它,持久连接与Keep-Alive的目的相同,但工作机制更优),并且只修改HTTP版本比较简单,所以只需将HTTP的版本从1.0升级至1.1即可
原代码(自动生成的Proxy代理类):
修改后的代码:
使用CommonsHTTPSender代理默认的HTTPSender,该类包含在axis-1.4.jar中,不需要添加额外的jar包
可以看到HTTP的版本已经变为1.1,并且在每次通信结束后,并不会关闭连接
每次通信前都要新建连接,通信结束后关闭连接
当请求量很大时,将频繁的创建、关闭连接,十分消耗性能,所以考虑使用HTTP长连接
HTTP/1.1默认使用持久连接(HTTP/1.1逐渐停止了对Keep-Alive的支持,用一种名为持久连接的改进型设计取代了它,持久连接与Keep-Alive的目的相同,但工作机制更优),并且只修改HTTP版本比较简单,所以只需将HTTP的版本从1.0升级至1.1即可
原代码(自动生成的Proxy代理类):
private void _initSPSSubscriberProvisioningServiceProxy() { try { sPSSubscriberProvisioningService_PortType = new SPSSubscriberProvisioningService_ServiceLocator() .getSPSSubscriberProvisioningService(); if (sPSSubscriberProvisioningService_PortType != null) { if (_endpoint != null)
修改后的代码:
private void _initSPSSubscriberProvisioningServiceProxy() { try { EngineConfiguration defaultConfig = EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig(); SimpleProvider config = new SimpleProvider(defaultConfig); config.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME,new CommonsHTTPSender()); serviceLocator = new SPSSubscriberProvisioningService_ServiceLocator(config); sPSSubscriberProvisioningService_PortType = serviceLocator.getSPSSubscriberProvisioningService();
使用CommonsHTTPSender代理默认的HTTPSender,该类包含在axis-1.4.jar中,不需要添加额外的jar包
可以看到HTTP的版本已经变为1.1,并且在每次通信结束后,并不会关闭连接
相关文章推荐
- QTcpSocket 发送和接收数据的几种方法
- AJAX——核心XMLHttpRequest对象
- TCP/IP三次握手、四次挥手总结
- 使用Node.js配合Nginx实现高负载网络
- 推送消息 相关公司 手机端分享http://mob.com/
- dubbo 启动:无法读取方案文档 'http://code.alibabatech.com/sch,原因为 1) 无法找到文档; 2) 无法读取文档; 3) ...
- TCP协议的三次握手和四次挥手
- Android实现网络图片app
- Android 学习笔记之网络通信基础+WebView....
- 记一次TcpListenOverflows报警解决过程
- puppet介绍及基于httpd实例部署
- Android 通过WebService进行网络编程,使用工具类轻松实现
- google picasa 网络相册帮助
- 网络编程
- Linux网络编程综合运用之MiniFtp实现(八)
- java网络编程
- 访问网络共享
- cocos2d-x的TestCpp分析
- 使用Node.js配合Nginx实现高负载网络
- Jetty 9.3庆祝20周年生日快乐,并增加HTTP/2支持