当前位置: 首页 > news >正文

辽宁朝阳哪家做网站好产品seo是什么意思

辽宁朝阳哪家做网站好,产品seo是什么意思,当阳建设中学网站,网站主体域名背景 在项目中有个通过线程池发送大量http请求是通过restTemplate 实现的,在研发环境需要直接连某些服务,所以需要动态修改请求的url。 自定义 ClientHttpRequestInterceptor 拦截器修改请求 自定义 ClientHttpRequestInterceptor 在请求发送前修改 URL&…

背景

在项目中有个通过线程池发送大量http请求是通过restTemplate 实现的,在研发环境需要直接连某些服务,所以需要动态修改请求的url。

自定义 ClientHttpRequestInterceptor 拦截器修改请求

自定义 ClientHttpRequestInterceptor 在请求发送前修改 URL:

public class DynamicUrlInterceptor implements ClientHttpRequestInterceptor {@Overridepublic ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)throws IOException {URI originalUri = request.getURI();String originalUrl = originalUri.toString();String host = originalUri.getHost();// 替换服务名为 IPif (SERVICE_MAP.containsKey(host)) {String newUrl = originalUrl.replace("http://" + host, SERVICE_MAP.get(host));try {// 创建新的请求对象HttpRequest newRequest = new HttpRequestWrapper(request, new URI(newUrl));return execution.execute(newRequest, body);} catch (URISyntaxException e) {throw new IOException("Invalid URI after replacing service name", e);}}return execution.execute(request, body);}
}

注册拦截器

RestTemplateConfig 配置

public class RestTemplateConfig {private static final Logger logger = LoggerFactory.getLogger(RestTemplateConfig.class);@Autowiredprivate HttpClinetProperties httpClinetProperties;@Bean(name="httpClientTemplate")public RestTemplate restTemplate() {// 使用http连接池RestTemplate restTemplate = new RestTemplate(httpRequestFactory());//配置自定义的interceptor拦截器List<ClientHttpRequestInterceptor> interceptors=new ArrayList<ClientHttpRequestInterceptor>();interceptors.add(new DynamicUrlInterceptor());restTemplate.setInterceptors(interceptors);return restTemplate;}@Beanpublic ClientHttpRequestFactory httpRequestFactory() {return new HttpComponentsClientHttpRequestFactory(httpClient());}public HttpClient httpClient(){RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();requestConfigBuilder.setSocketTimeout(httpClinetProperties.getSocketTimeout());requestConfigBuilder.setConnectionRequestTimeout(httpClinetProperties.getConnectionRequestTimeout());requestConfigBuilder.setConnectTimeout(httpClinetProperties.getConnectTimeout());RequestConfig defaultRequestConfig = requestConfigBuilder.build();final PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);pollingConnectionManager.setMaxTotal(httpClinetProperties.getMaxTotal());pollingConnectionManager.setDefaultMaxPerRoute(httpClinetProperties.getDefaultMaxPerRoute());HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());httpClientBuilder.setConnectionManager(pollingConnectionManager);httpClientBuilder.setDefaultRequestConfig(defaultRequestConfig);HttpClient client = httpClientBuilder.build();Timer timer = new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {pollingConnectionManager.closeExpiredConnections();pollingConnectionManager.closeIdleConnections(5, TimeUnit.SECONDS);}}, 10 * 1000, 5 * 1000);return client;}
}
http://www.dtcms.com/a/606375.html

相关文章:

  • 【问题已解决】无法定位程序输入点于XXX动态链接库***.dll上
  • 今天我们开始学习ansible之playbook的简单运用
  • 易语言反编译技术分析与应用
  • 车联网蓝牙测试:经典蓝牙拒绝服务测试.
  • rtaoscfg配置ISR
  • 企业采购平台哪个好宁波seo优化公司排名
  • 国家林业建设工程协会网站企业网站制作排名
  • 搜索引擎网站分析项目管理软件开发案例
  • DeepHunt微服务故障定位系统核心技术解析2
  • 怎么制作单页网站泉州网站排名
  • 【钉钉表单(周/日报)】每天定时发送,实现收集每天信息
  • TpriDatavue 软件架构与功能文档
  • 建设网站弹出后加载不进去360网站怎么建设
  • 熊海CMS v1.0代码审计实战
  • Go语言编译 | Go语言的编译流程与优化技巧
  • 建立网站的正确方法租网站空间
  • 工程公司手机网站公司网站建设合规吗
  • 寒流感双预警,冠心病患者需备威立芯(硝酸甘油舌下片)筑牢心防线
  • 深入理解HTTPS和HTTP的区别、工作原理及安全重要性
  • 重庆网站建设机构网站建设中怎样进入后台
  • [ 项目开发 1.0 ] 新闻网站的开发流程和注意事项
  • ip加端口可以做网站吗wordpress模仿做slider
  • 长沙flash网站制作提升学历选什么专业比较好
  • 文化礼堂建设情况网站微信公众号怎么登录账号
  • 构建AI原生型营销团队的“大脑-神经-肢体”模型
  • Closed-Loop Evaluation in Robotics: A Practical Template (for openvla + LIBERO)
  • 字体文件大小压缩指南
  • 异步IO的其他特性
  • 软考 系统架构设计师历年真题集萃(202)—— 2025年11月系统架构设计师真题5
  • 计算机网络基础:计算机网络概述