diff --git a/application/src/main/java/cz/muni/pa165/service/ApplicationService.java b/application/src/main/java/cz/muni/pa165/service/ApplicationService.java index 9706d53b8d0e96e34c45bb6033dd9c2a4df16414..1a1ce76547eb1c216d7a437814fd2800a7485495 100644 --- a/application/src/main/java/cz/muni/pa165/service/ApplicationService.java +++ b/application/src/main/java/cz/muni/pa165/service/ApplicationService.java @@ -8,11 +8,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestClientException; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientException; import java.time.LocalDate; import java.util.HashMap; @@ -62,7 +64,7 @@ public class ApplicationService { try { sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_NEW, List.of(savedApplication.getEmail())); - } catch (RestClientException | IllegalArgumentException e) { + } catch (WebClientException e) { log.debug(String.format("The notification module is not reachable on the URL: %s, exception %s", NOTIFICATION_MODULE_URL + NOTIFICATION_MODULE_URI_NEW, e)); } @@ -89,7 +91,7 @@ public class ApplicationService { if (savedApplication.getStatus() != ApplicationStatusEnum.PENDING) { try { sendPostRequest(savedApplication, NOTIFICATION_MODULE_URI_STATUS, NOTIFICATION_RECEIVERS); - } catch (RestClientException | IllegalArgumentException e) { + } catch (WebClientException e) { log.debug(String.format("The notification module is not reachable on the URL: %s, exception %s", NOTIFICATION_MODULE_URL + NOTIFICATION_MODULE_URI_STATUS, e)); } } @@ -107,10 +109,7 @@ public class ApplicationService { .contentType(MediaType.APPLICATION_JSON) .bodyValue(notification) .retrieve() - .bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() {}) - .doOnError(error -> { - throw new RestClientException("Failed to send POST request", error); - }) + .bodyToMono(Resource.class) .block(); } } diff --git a/core/src/main/java/cz/muni/pa165/service/CarComponentService.java b/core/src/main/java/cz/muni/pa165/service/CarComponentService.java index f7f6dfecb9cab9fde09c4f4663b5386bb64e0a66..f16c6749fd49cb521cc05ae19bfb1f5651c486de 100644 --- a/core/src/main/java/cz/muni/pa165/service/CarComponentService.java +++ b/core/src/main/java/cz/muni/pa165/service/CarComponentService.java @@ -8,11 +8,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.*; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientException; import java.util.*; @@ -48,7 +50,7 @@ public class CarComponentService extends DomainService<CarComponent> { CarComponent savedComponent = repository.save(component); try { sendPostRequest(savedComponent); - } catch (RestClientException | IllegalArgumentException e) { + } catch (WebClientException e) { log.debug(String.format("The notification module is not reachable on the URL: %s, exception %s", NOTIFICATION_MODULE_URL + NOTIFICATION_MODULE_URI, e)); } return savedComponent; @@ -88,10 +90,7 @@ public class CarComponentService extends DomainService<CarComponent> { .contentType(MediaType.APPLICATION_JSON) .bodyValue(notification) .retrieve() - .bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() {}) - .doOnError(error -> { - throw new RestClientException("Failed to send POST request", error); - }) + .bodyToMono(Resource.class) .block(); } } diff --git a/core/src/main/java/cz/muni/pa165/service/CarService.java b/core/src/main/java/cz/muni/pa165/service/CarService.java index 96d2646e073171faeafc4739ff27a862bd0245b6..7f4709aca3890bbd160351b04681cc6651121cda 100644 --- a/core/src/main/java/cz/muni/pa165/service/CarService.java +++ b/core/src/main/java/cz/muni/pa165/service/CarService.java @@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.core.io.Resource; import org.springframework.web.client.RestClientException; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientException; import java.util.HashMap; import java.util.List; @@ -122,7 +123,7 @@ public class CarService extends DomainService<Car> { try { sendPostRequest(savedCar); - } catch (Exception e) { + } catch (WebClientException e) { log.debug(String.format("The visualization module is not reachable on the URL: %s, exception %s", VISUALIZATION_MODULE_URL + VISUALIZATION_MODULE_URI, e)); }