Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jul 3, 2024
1 parent b1a85a3 commit b329bcc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@
import java.net.URI;
import java.util.Arrays;

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

Expand All @@ -41,15 +36,9 @@ public class MovieDbRestClientBean implements MovieDbRestClient {
private final ObjectMapper objectMapper;
private final RestClient restClient;

public MovieDbRestClientBean(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;

RequestConfig requestConfig = RequestConfig.custom().setResponseTimeout(Timeout.ofMilliseconds(5000)).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
var factory = new HttpComponentsClientHttpRequestFactory(httpClient);
factory.setConnectTimeout(2000);
factory.setConnectionRequestTimeout(2000);
this.restClient = RestClient.builder().requestFactory(factory).build();
public MovieDbRestClientBean(ObjectMapper objectMapper, RestClient restClient) {
this.objectMapper = objectMapper;
this.restClient = restClient;
}

public WrapperGenereDto fetchAllGeneres(String moviedbkey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2019 Sven Loesekann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package ch.xxx.moviemanager.adapter.config;

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.util.Timeout;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestClient;

@Configuration
public class ApplicationConfig {
@Bean
public RestClient createRestClient() {
RequestConfig requestConfig = RequestConfig.custom().setResponseTimeout(Timeout.ofMilliseconds(5000)).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
var factory = new HttpComponentsClientHttpRequestFactory(httpClient);
factory.setConnectTimeout(2000);
factory.setConnectionRequestTimeout(2000);
return RestClient.builder().requestFactory(factory).build();
}
}

0 comments on commit b329bcc

Please sign in to comment.