* Fix for Issue##549 Catch ClientProtocolException and Update Error Logs * Fix indentation, checkstyle errors * Fix for Issue #549 Add fallbacks in Aggregator service when other microservices fail * Make ProductInventoryClientImpl return null instead of zero in case of failure
This commit is contained in:
parent
55b0341c8d
commit
1d4a7681e2
@ -51,9 +51,23 @@ public class Aggregator {
|
||||
*/
|
||||
@RequestMapping(path = "/product", method = RequestMethod.GET)
|
||||
public Product getProduct() {
|
||||
|
||||
var product = new Product();
|
||||
product.setTitle(informationClient.getProductTitle());
|
||||
product.setProductInventories(inventoryClient.getProductInventories());
|
||||
String productTitle = informationClient.getProductTitle();
|
||||
Integer productInventory = inventoryClient.getProductInventories();
|
||||
|
||||
if (productTitle != null) {
|
||||
product.setTitle(productTitle);
|
||||
} else {
|
||||
product.setTitle("Error: Fetching Product Title Failed"); //Fallback to error message
|
||||
}
|
||||
|
||||
if (productInventory != null) {
|
||||
product.setProductInventories(productInventory);
|
||||
} else {
|
||||
product.setProductInventories(-1); //Fallback to default error inventory
|
||||
}
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
|
@ -28,5 +28,5 @@ package com.iluwatar.aggregator.microservices;
|
||||
*/
|
||||
public interface ProductInventoryClient {
|
||||
|
||||
int getProductInventories();
|
||||
Integer getProductInventories();
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
|
||||
|
||||
@Override
|
||||
public int getProductInventories() {
|
||||
var response = "0";
|
||||
public Integer getProductInventories() {
|
||||
var response = "";
|
||||
|
||||
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories")).build();
|
||||
var client = HttpClient.newHttpClient();
|
||||
@ -55,6 +55,10 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
} catch (InterruptedException ie) {
|
||||
LOGGER.error("InterruptedException Occurred", ie);
|
||||
}
|
||||
return Integer.parseInt(response);
|
||||
if("".equalsIgnoreCase(response)) {
|
||||
return null;
|
||||
} else {
|
||||
return Integer.parseInt(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user