|
1 | 1 | package com.spring.security.common.web.config; |
2 | 2 |
|
3 | 3 | import com.spring.security.domain.model.dto.PagedModel; |
4 | | -import java.net.InetSocketAddress; |
5 | | -import java.net.Proxy; |
6 | | -import java.util.Optional; |
7 | | -import org.springframework.boot.context.properties.ConfigurationProperties; |
8 | | -import org.springframework.boot.context.properties.EnableConfigurationProperties; |
9 | 4 | import org.springframework.context.annotation.Bean; |
10 | 5 | import org.springframework.context.annotation.Configuration; |
11 | 6 | import org.springframework.data.domain.Page; |
12 | 7 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; |
13 | | -import org.springframework.http.client.SimpleClientHttpRequestFactory; |
14 | | -import org.springframework.web.client.RestTemplate; |
15 | 8 | import tools.jackson.core.JacksonException; |
16 | 9 | import tools.jackson.core.JsonGenerator; |
17 | 10 | import tools.jackson.databind.JacksonModule; |
|
21 | 14 |
|
22 | 15 | @Configuration |
23 | 16 | @EnableJpaAuditing |
24 | | -@EnableConfigurationProperties(CommonWebConfig.ProxyProperties.class) |
25 | 17 | public class CommonWebConfig { |
26 | 18 |
|
27 | | - @Bean |
28 | | - public RestTemplate restTemplate(ProxyProperties proxyProperties) { |
29 | | - |
30 | | - SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); |
31 | | - factory.setConnectTimeout(5000); |
32 | | - factory.setReadTimeout(8000); |
33 | | - |
34 | | - Optional.of(proxyProperties) |
35 | | - .filter(ProxyProperties::enabled) |
36 | | - .ifPresent( |
37 | | - p -> factory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(p.host(), p.port())))); |
38 | | - |
39 | | - return new RestTemplate(factory); |
40 | | - } |
41 | | - |
42 | | - @ConfigurationProperties(prefix = "spring.proxy") |
43 | | - public record ProxyProperties(boolean enabled, String host, int port) {} |
44 | | - |
45 | 19 | @Bean |
46 | 20 | public JacksonModule jacksonModule() { |
47 | 21 | SimpleModule simpleModule = new SimpleModule(); |
|
0 commit comments