spring 整合WebService 设置超时

2024-08-21 13:32

本文主要是介绍spring 整合WebService 设置超时,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前段时间在用spring 整合WebService 设置超时时有个问题一直解决不了

最后不在spring配置文件里写直接获取代理类,对代理类进行设置。

例子:

package test;


import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import com.cxf.server.HolloWrold;


public class TestMessage {
public static void main(String[] args) {
ApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml");
HolloWrold a =(HolloWrold) factory.getBean("holloWrold");
Client proxy = ClientProxy.getClient(a);
HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setConnectionTimeout(3000); // 连接超时时间 30
policy.setReceiveTimeout(2400);// 请求超时时间. 4分钟240秒
//policy.setContentType("text/xml;charset=UTF-8");
//policy.setElementType(type);
conduit.setClient(policy);
System.out.println(a.sayHi("aaa"));
}
}




事后经过百度得知错误原因:

name 的不是wsdl上面的name (不知道什么原因,官方文档说的就是 等于 WSDL中的 port name和".http-conduit"组成

而是客户端接口的targetNamespace和name + Prot    

name="{targetNamespace }name+Port.http-conduit"

例如我客户端接口:  @WebService(targetNamespace = "http://server.cxf.com/", name = "HolloWrold")

name="{http://server.cxf.com/}HolloWroldPort.http-conduit"


<http-conf:conduit name="{http://server.cxf.com/}HolloWroldPort.http-conduit">   

          <http-conf:client ConnectionTimeout="3000" ReceiveTimeout="3000"  ContentType="text/xml;charset=UTF-8"/>  
</http-conf:conduit> 


例子:

一、在spring的配置文件中进行设置(客户端)。

<?xml version="1.0" encoding="UTF-8"?>    
<beans xmlns="http://www.springframework.org/schema/beans"    
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns:jee="http://www.springframework.org/schema/jee"    
    xmlns:jaxws="http://cxf.apache.org/jaxws"    
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"     
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd    
           http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd    
           http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd    
           http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd ">    
   
<http-conf:conduit name="{http://server.cxf.com/}HolloWroldPort.http-conduit">   
          <http-conf:client ConnectionTimeout="3000" ReceiveTimeout="3000"  ContentType="text/xml;charset=UTF-8"/>  
    </http-conf:conduit> 
    
</beans>    

  1. 这里需要注意的有几个地方:  
  2. 需要指定http-conf名称空间 xmlns:http-conf=http://cxf.apache.org/transports/http/configuration  
  3. 指定模式位置: http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd  
  4. http-conf:conduit中的name属性,指定设置生效的服务,如例子中,只对服务名为{http://impl.service.product.sww.com/}ProjectService的服务生效.  
  5. 使用下面的设置则会对所有服务生效  
  6. <http-conf:conduit name="*.http-conduit">       
  7. </http-conf:conduit>  


还有一种方法:

就是name = " WebService 路径"  只对这个 WebService 起作用(ContentType是设置编码格式)

例子:

<http-conf:conduit name="http://localhost:8080/WSSSpring/webservice/hollo">   
          <http-conf:client ConnectionTimeout="3000" ReceiveTimeout="3000"  ContentType="text/xml;charset=UTF-8"/>  
    </http-conf:conduit>  




这篇关于spring 整合WebService 设置超时的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1093294

相关文章

Java中ArrayList和LinkedList有什么区别举例详解

《Java中ArrayList和LinkedList有什么区别举例详解》:本文主要介绍Java中ArrayList和LinkedList区别的相关资料,包括数据结构特性、核心操作性能、内存与GC影... 目录一、底层数据结构二、核心操作性能对比三、内存与 GC 影响四、扩容机制五、线程安全与并发方案六、工程

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

如何使用Java实现请求deepseek

《如何使用Java实现请求deepseek》这篇文章主要为大家详细介绍了如何使用Java实现请求deepseek功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1.deepseek的api创建2.Java实现请求deepseek2.1 pom文件2.2 json转化文件2.2

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

Spring AI集成DeepSeek的详细步骤

《SpringAI集成DeepSeek的详细步骤》DeepSeek作为一款卓越的国产AI模型,越来越多的公司考虑在自己的应用中集成,对于Java应用来说,我们可以借助SpringAI集成DeepSe... 目录DeepSeek 介绍Spring AI 是什么?1、环境准备2、构建项目2.1、pom依赖2.2

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

Spring Cloud LoadBalancer 负载均衡详解

《SpringCloudLoadBalancer负载均衡详解》本文介绍了如何在SpringCloud中使用SpringCloudLoadBalancer实现客户端负载均衡,并详细讲解了轮询策略和... 目录1. 在 idea 上运行多个服务2. 问题引入3. 负载均衡4. Spring Cloud Load

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为