Catch failing delivery server

This commit is contained in:
CodeSteak 2020-06-20 22:51:18 +02:00
parent e5332a3348
commit 8fdfe9cc69
1 changed files with 11 additions and 17 deletions

View File

@ -23,8 +23,7 @@ public class RestServiceForDelivery {
private final String DELIVERY_IP_ADDRESS = "http://[::1]:8082";
public String getDeliveryID(CustomerOrder customerOrder) throws ResourceAccessException
{
public String getDeliveryID(CustomerOrder customerOrder) throws ResourceAccessException {
String url = DELIVERY_IP_ADDRESS + "/newDelivery";
RestTemplate restTemplate = restTemplateBuilder.build();
@ -34,15 +33,14 @@ public class RestServiceForDelivery {
Map<String, String> requestBody = new HashMap<>();
requestBody.put("name",customerOrder.destination.name);
requestBody.put("address",customerOrder.destination.addressString);
requestBody.put("name", customerOrder.destination.name);
requestBody.put("address", customerOrder.destination.addressString);
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody,headers);
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST,entity, String.class);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
if (response.getStatusCode() == HttpStatus.OK)
{
if (response.getStatusCode() == HttpStatus.OK) {
return response.getBody();
} else {
throw new ResourceAccessException("Http Status wrong");
@ -64,20 +62,16 @@ public class RestServiceForDelivery {
ResponseEntity<DeliveryData> response;
try
{
try {
response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, DeliveryData.class);
if (response.getStatusCode() == HttpStatus.OK)
{
if (response.getStatusCode() == HttpStatus.OK) {
return response.getBody();
} else {
return new DeliveryData("","",DeliveryDataEnum.NO_DATA);
return new DeliveryData("", "", DeliveryDataEnum.NO_DATA);
}
}
catch (ResourceAccessException e)
{
return new DeliveryData("","",DeliveryDataEnum.NO_DATA);
} catch (Exception e) {
return new DeliveryData("", "", DeliveryDataEnum.NO_DATA);
}
}
}