Hi all,
I have made a java component that’s used to feed models to the request.
I added dummy data to show a list of products on de page which worked nicely.
But now I’ve added a request to CommerceTools to get an access token, which I succesfully retrieve.
And afterwards I try to do a second request to CommerceTools to do a product search.
But the page is shown while de code isn’t even done, it even seems as if the request isn’t made.
It stops while calling the function that makes the request. And I don’t see the logs in that function.
It’s difficult to explain, so here is a snippet of my doBeforeRender method.
@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) {
System.out.println("ProductListComponent.doBeforeRender()");
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();
final EssentialsListComponentInfo paramInfo = getComponentParametersInfo(request);
// Get the requested products.
System.out.println("doSearch");
ProductDto[] products = this.doSearch(request);
System.out.println("doSearchForPageable");
ProductDocument[] productsForPageable = this.doSearchForPageable();
System.out.println("ProductIterator: " + productsForPageable.length);
ProductIterator productIterator = new ProductIterator(productsForPageable);
And here is the doSearch method.
protected ProductDto[] doSearch(HstRequest request) {
String keyword = getPublicRequestParameter(request, "keyword");
String limit = getPublicRequestParameter(request, "limit");
if (keyword == null || keyword.length() == 0) {
return null;
}
CommerceToolsApiService commerceToolsApiService = new io.commercetools.CommerceToolsApiService(
"https://api.europe-west1.gcp.commercetools.com/", "https://auth.europe-west1.gcp.commercetools.com/",
"xxx", "xxx", "xxx");
String accessToken;
try {
accessToken = commerceToolsApiService.GetAccessToken("view_products");
System.out.println("Access Token: "+accessToken);
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
System.out.println(e.getMessage());
return null;
}
System.out.println("Done getting access token.");
Search search = new Search();
System.out.println("1");
search.SearchTerm = keyword;
System.out.println("2");
search.Limit = 10;// limit != null && limit != "" ? 10 : Integer.parseInt(limit);
System.out.println("3");
search.CategoryId = null;
System.out.println("Created search object. " + search.SearchTerm + " - " + search.Limit);
PagedQueryResult productResponse;
try {
System.out.println("Start search: " + search);
productResponse = commerceToolsApiService.GetProductsBySearchTerms(accessToken, search);
System.out.println(productResponse.Count);
} catch (IOException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
System.out.println(e.getMessage());
return null;
}
System.out.println("Done getting products by search term.");
I see the logs “Done getting access token” and the 1, 2, 3 all the way to the “Start Search…”.
But no logs after that. Does someone have a suggestion why this would happen?
Thanks in advance.