* 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)
|
@RequestMapping(path = "/product", method = RequestMethod.GET)
|
||||||
public Product getProduct() {
|
public Product getProduct() {
|
||||||
|
|
||||||
var product = new Product();
|
var product = new Product();
|
||||||
product.setTitle(informationClient.getProductTitle());
|
String productTitle = informationClient.getProductTitle();
|
||||||
product.setProductInventories(inventoryClient.getProductInventories());
|
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;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,5 +28,5 @@ package com.iluwatar.aggregator.microservices;
|
|||||||
*/
|
*/
|
||||||
public interface ProductInventoryClient {
|
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);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProductInventories() {
|
public Integer getProductInventories() {
|
||||||
var response = "0";
|
var response = "";
|
||||||
|
|
||||||
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories")).build();
|
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories")).build();
|
||||||
var client = HttpClient.newHttpClient();
|
var client = HttpClient.newHttpClient();
|
||||||
@ -55,6 +55,10 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
|||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
LOGGER.error("InterruptedException Occurred", 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