在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代理类):
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,并且在每次通信结束后,并不会关闭连接
本文介绍如何在Eclipse中使用Axis1.4插件生成的代码中,通过简单修改将HTTP版本从1.0升级到1.1,实现HTTP长连接,以减少大量请求时频繁创建和关闭连接所带来的性能损耗。
3830

被折叠的 条评论
为什么被折叠?



