From 19ca87d12655a57713802130f2e3fe173526d6a9 Mon Sep 17 00:00:00 2001 From: Michal Badin <xbadin@fi.muni.cz> Date: Sun, 16 Apr 2023 20:35:45 +0200 Subject: [PATCH] fix(Sending notification): Problem with sending request do not failed whole func --- .../cz/muni/pa165/service/CarComponentService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 e25b9e4..c993139 100644 --- a/core/src/main/java/cz/muni/pa165/service/CarComponentService.java +++ b/core/src/main/java/cz/muni/pa165/service/CarComponentService.java @@ -14,7 +14,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.client.RestTemplate; +import org.springframework.web.client.*; import java.io.IOException; import java.util.*; @@ -22,11 +22,11 @@ import java.util.*; @Service public class CarComponentService extends DomainService<CarComponent> { - private static final Logger log = LoggerFactory.getLogger(CarComponentController.class); + private static final Logger log = LoggerFactory.getLogger(CarComponentService.class); private final CarComponentRepository componentRepository; private final RestTemplate restTemplate; - @Value("${http://localhost:8083/notification/notify}") + @Value("${http://localhost:8083/notification}") private String notificationServiceUrl; @Autowired @@ -40,13 +40,13 @@ public class CarComponentService extends DomainService<CarComponent> { CarComponent savedComponent = repository.save(component); try { sendPostRequest(savedComponent); - } catch (IOException e) { + } catch (RestClientException | IllegalArgumentException e) { log.debug(String.format("The notification module is not reachable on the URL: %s", notificationServiceUrl)); } - return component; + return savedComponent; } - private void sendPostRequest(CarComponent component) throws IOException { + private void sendPostRequest(CarComponent component) { Map<String, Object> notification = new HashMap<>(); notification.put("subject", "New CarComponent added"); notification.put("message", "A new CarComponent with ID " + component.getId() + " has been added."); -- GitLab