Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProductInventoryClientImpl does not return null but 0 when exception occurs. Perhaps returning null would be the correct way, so the change should be implemented in the client..

product.setProductInventories(productInventory);
} else {
product.setProductInventories(-1); //Fallback to default error inventory
}

return product;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
*/
public interface ProductInventoryClient {

int getProductInventories();
Integer getProductInventories();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -55,6 +55,10 @@ public int getProductInventories() {
} catch (InterruptedException ie) {
LOGGER.error("InterruptedException Occurred", ie);
}
return Integer.parseInt(response);
if("".equalsIgnoreCase(response)) {
return null;
} else {
return Integer.parseInt(response);
}
}
}