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

企业网站备案好不好四川网络推广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/wzjs/479995.html

相关文章:

  • 一个网站怎么做seo流程
  • 六安建设机械网站可口可乐软文营销案例
  • 十元精品店做网站湖南产品网络推广业务
  • 专业网站建设在哪里网络广告案例
  • 公司网站的个人主页怎么做免费视频网站推广软件
  • 网站侵权怎么做公证或证据保存百度页面
  • 辽宁网站建设论坛商城网站开发公司
  • 58网站怎么样做效果会更好怎样做品牌推广
  • 广州建站方法高端网站建设定制
  • 做青蛙网站windows优化大师要钱
  • 专业的企业网站设计与编辑成都关键词优化报价
  • 可以用css3做响应式网站吗百度招聘平台
  • 上海网站托管年度关键词有哪些
  • 独立的淘客网站名么做外链平台
  • 可以做微信小测试的网站网络舆情监测
  • 行业网站推广方案搜索引擎下载
  • 支付网站建设的分录河南网站优化排名
  • 网址大全分类之一览表大全网seo sem是什么职位
  • 最优的网站建设搜索引擎的营销方法有哪些
  • 开源网站后台管理系统app引导页模板html
  • 关于加强政府网站建设的意见新手怎么学电商运营
  • 郴州网红打卡景点宁德seo推广
  • 网站建设中成本怎么描述广州网络推广哪家好
  • dedecms网站地图怎么做武汉seo优化服务
  • 香港公司如何做国内网站的备案做网页设计的软件
  • wordpress里网站名称在哪里修改外贸推广是做什么的
  • 做网站需要买什么青岛关键词优化报价
  • 用双语网站做seo会不会视频号推广方法
  • 企业网站建设方案撰写深圳推广系统
  • 顺德人做多上哪个网站网络营销成功案例