Кроме того, я использую HttpServiceProxyFactory для создания декларативного RestClient с использованием интерфейса с определениями. Похоже, у меня почти нет власти над SSLContext и HttpServiceProxyFactory.
Вот мой упрощенный сценарий:
Код: Выделить всё
@Slf4j
@Configuration
public class FooClientConfig {
@Bean
public FooClient buildNativeClient(RestClient.Builder builder, RestClientSsl ssl, NativeProperties properties) {
// construct the base URL, even with protocol (https/https based on ssl prop)
var baseUrl = buildBaseUrl(...);
builder.baseUrl(baseUrl)
.defaultHeaders(httpHeaders -> httpHeaders.setBasicAuth(properties.getBasicAuth().getUsername(), properties.getBasicAuth().getPassword()));
if (properties.getSsl().isEnabled()) {
builder.apply(ssl.fromBundle(properties.getSsl().getBundle()));
}
var requestFactory = buildRequestFactory(properties.getProxy());
var restClient = builder
.requestFactory(requestFactory)
.build();
return HttpServiceProxyFactory
.builderFor(RestClientAdapter.create(restClient))
.build()
.createClient(FooClient.class);
}
public static String buildBaseUrl(boolean sslEnabled, @NotNull String host, Integer hostPort, String baseUrl){
val protocol = sslEnabled ? "https" : "http";
val port = hostPort != null ? ":" + hostPort: "";
return String.format("%s://%s%s%s", protocol, host, port, baseUrl);
}
public static @NotNull ClientHttpRequestFactory buildRequestFactory(@NotNull ProxyConfig proxyConfig) {
final var requestFactory = new SimpleClientHttpRequestFactory();
// If proxying is enabled
if (proxyConfig.isEnabled()) {
val socketAdress = new InetSocketAddress(proxyConfig.getAddress(), proxyConfig.getPort());
val proxy = new Proxy(proxyConfig.getSchema(), socketAdress);
requestFactory.setProxy(proxy);
}
return requestFactory;
}
}
// Interface defining the API client operations
public interface FooClient {
@GetExchange()
ResponseEntity handshake();
}
/>Несмотря на эти шаги, мне не удалось настроить RestClient так, чтобы он доверял всем сертификатам для целей отладки. Кажется, нигде нет документации по этому шагу, поэтому я спрашиваю: как мне это сделать, не переписывая полностью клиент?
Подробнее здесь: https://stackoverflow.com/questions/786 ... rtificates