This is my first Play project after I graduated from college. Yes, I am overwhelmed. I am learning day by day by tweaking the existing project. But I do not understand why they do this.
Play project (Equipment Order Site) calls the internal SOA service to get product detail information.
- Controller: ProductController.java
- Model: ProductModel.java
getProduct() in ProductController.java
public CompletionStage< Result > getProduct(final String barcode) {
return CompletableFuture.supplyAsync( () -> {
Product product = new Product();
try {
product = product.getProduct(barcode);
} catch (WebServiceException e) {
return internalServerError();
}
if (product.getNumber() != null && !product.getNumber().equals("")) {
return ok(product.asJSON()).as( "application/json; charset=utf-8" );
} else {
return noContent();
}
}, ec.current());
}getProduct() in ProductModel.java
public Product getProduct(String barcode) throws WebServiceException {
Product product = new Product();
URL serviceURL;
try {
serviceURL = new URL("http://soaurl");
} catch (MalformedURLException e) {
throw new WebServiceException(e);
}
try {
com.xyz.webservice.ProductWebService_Service port = new com.xyz.webservice.ProductWebService_Service(serviceURL);
com.xyz.webservice.ProductWebService client = port.getProductPort();
ProductObj productObj = client.getProduct(barcode);
if (productObj != null) {
product.setDescription(productObj.getDescription());
product.setNumber(productObj.getNumber());
product.setType(productObj.getType());
product.setName(productObj.getName());
}
} catch (Exception e) {
Logger.error("Error during web service: ", e);
throw new WebServiceException();
}
return product;
}We call a SOA call from Model. Not from Controller. Why do we have a block in Controller? Shouldn't we have a block in Model because Model actually makes a SOA service call?