package com.ofs.fsgbu.analytics.runcmd;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import com.ofs.fsgbu.analytics.runcmd.utility.AAIRestUtil;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.ofs.fsgbu.analytics.runcmd.interceptor.UserPreferencesInterceptor;
@Configuration
@EnableAsync
@ComponentScan(basePackages = {"com.ofs.aai","com.ofs.fsgbu.analytics.commonlib"})
public class AppConfig implements WebMvcConfigurer{
@Autowired
UserPreferencesInterceptor userPreferencesInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
List\ patterns = new ArrayList\();
patterns.add("/rest-api/v1/run-cmd/oracle/sqlplus/");
registry.addInterceptor(userPreferencesInterceptor);
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
SSLConnectionSocketFactory socketFactory = null;
try {
socketFactory = new SSLConnectionSocketFactory(AAIRestUtil.getSSLContext());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(socketFactory)
.build();
return builder
.requestFactory(() -\> new HttpComponentsClientHttpRequestFactory(httpClient))
.setConnectTimeout(Duration.ofMillis(3000))
.setReadTimeout(Duration.ofMillis(3000))
.build();
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... -java-file
Переход с httpclient на httpclient5, ошибки в файле Java [закрыто] ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1764190023
Anonymous
package com.ofs.fsgbu.analytics.runcmd;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import com.ofs.fsgbu.analytics.runcmd.utility.AAIRestUtil;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.ofs.fsgbu.analytics.runcmd.interceptor.UserPreferencesInterceptor;
@Configuration
@EnableAsync
@ComponentScan(basePackages = {"com.ofs.aai","com.ofs.fsgbu.analytics.commonlib"})
public class AppConfig implements WebMvcConfigurer{
@Autowired
UserPreferencesInterceptor userPreferencesInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
List\ patterns = new ArrayList\();
patterns.add("/rest-api/v1/run-cmd/oracle/sqlplus/");
registry.addInterceptor(userPreferencesInterceptor);
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
SSLConnectionSocketFactory socketFactory = null;
try {
socketFactory = new SSLConnectionSocketFactory(AAIRestUtil.getSSLContext());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(socketFactory)
.build();
return builder
.requestFactory(() -\> new HttpComponentsClientHttpRequestFactory(httpClient))
.setConnectTimeout(Duration.ofMillis(3000))
.setReadTimeout(Duration.ofMillis(3000))
.build();
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79830986/changing-from-httpclient-to-httpclient5-errors-in-java-file[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия