MagentoGraphlClient not getting initialized(injected)
- December 28, 2023
- 1 reply
- 930 views
I am using adobe CIF add-on on AEM cloud and created a cutomproduct(resource super type - core/cif/components/commerce/product/v3/product) component which has its own CustomProductImpl and CustomProduct.
CustomProductImpl tries to make use MagentoGraphQLClient. However, this object never gets initialized or injected. Any help here in resolving this issue is highly appreciated.
Some observations,
1. When we try to work on vanilla instance on top of venia project using this custom component. Everything works fine. However, when we add CustomProductImp in our project codebase, it starts giving null value on debugging MagentoGraphQLClient.
2. Under OSGI component list, I see some instances of GraphQLClientImpl in active state and some in satisfies state. Active state OSGI component's are used by adobe bundles and satisfied state by OSGI components of the project bundles. I am suspecting some problem here. Screenshot attached.
3. The issue is intermittent in local, but in AEM cloud dev, this issue occurs consistently.
4. Exception in logs are mostly around
Caused by: java.lang.ClassCastException: class com.adobe.cq.commerce.core.components.internal.client.MagentoGraphqlClientImpl cannot be cast to class com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient (com.adobe.cq.commerce.core.components.internal.client.MagentoGraphqlClientImpl is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @55cfca83; com.adobe.cq.commerce.core.components.client.MagentoGraphqlClient is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @6f97aac3)
Some checks which we already did.
1. GraphQL OSGI configuration is correct.
2. Added all dependencies in main pom.xml and embedded everything in all/pom.xmlcorrectly as mentioned in venia project.
3. GraphQL url is public, so all good.
4. COMMERCE_ENDPOINT variable is configured correctly in cloud manager.
P.S. we are not looking for product picker or catalog picker functionality to work, just focusing on showing product detail page to end users, however custom product ends up giving null value for MagentoGraphQLClient.
Sample code base for CustomProductImpl
adaptables = {SlingHttpServletRequest.class},
adapters = {CustomProduct.class},
resourceType = {"venia/components/commerce/product"}
)
public class CustomProductImpl implements CustomProduct{
@Self(
injectionStrategy = InjectionStrategy.OPTIONAL
)
private MagentoGraphqlClient magentoGraphqlClient;
private AbstractProductRetriever productRetriever;
@PostConstruct
protected void initModel() {
if (this.magentoGraphqlClient != null) {
System.out.println("Product model initiated");
}
