Catch failing delivery server
This commit is contained in:
parent
e5332a3348
commit
8fdfe9cc69
|
@ -23,8 +23,7 @@ public class RestServiceForDelivery {
|
||||||
private final String DELIVERY_IP_ADDRESS = "http://[::1]:8082";
|
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";
|
String url = DELIVERY_IP_ADDRESS + "/newDelivery";
|
||||||
|
|
||||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||||
|
@ -34,15 +33,14 @@ public class RestServiceForDelivery {
|
||||||
|
|
||||||
Map<String, String> requestBody = new HashMap<>();
|
Map<String, String> requestBody = new HashMap<>();
|
||||||
|
|
||||||
requestBody.put("name",customerOrder.destination.name);
|
requestBody.put("name", customerOrder.destination.name);
|
||||||
requestBody.put("address",customerOrder.destination.addressString);
|
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();
|
return response.getBody();
|
||||||
} else {
|
} else {
|
||||||
throw new ResourceAccessException("Http Status wrong");
|
throw new ResourceAccessException("Http Status wrong");
|
||||||
|
@ -64,20 +62,16 @@ public class RestServiceForDelivery {
|
||||||
|
|
||||||
ResponseEntity<DeliveryData> response;
|
ResponseEntity<DeliveryData> response;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, DeliveryData.class);
|
response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, DeliveryData.class);
|
||||||
if (response.getStatusCode() == HttpStatus.OK)
|
if (response.getStatusCode() == HttpStatus.OK) {
|
||||||
{
|
|
||||||
return response.getBody();
|
return response.getBody();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
return new DeliveryData("","",DeliveryDataEnum.NO_DATA);
|
return new DeliveryData("", "", DeliveryDataEnum.NO_DATA);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (ResourceAccessException e)
|
return new DeliveryData("", "", DeliveryDataEnum.NO_DATA);
|
||||||
{
|
|
||||||
return new DeliveryData("","",DeliveryDataEnum.NO_DATA);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue