您的位置:首页 > 理论基础 > 计算机网络

在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代理类):

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,并且在每次通信结束后,并不会关闭连接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: