Hello All - We have extended the PDF viewer core component into our app : /apps/app-name/ by following the below medium article and also created the "Content Aware configuration" under /conf/app-name/ and added the property "sling:configRef" that points to Context Aware Config path under /content/site/.
https://medium.com/adobetech/pdfs-in-aem-embed-pdfs-into-your-pages-with-pdf-viewer-7115c60b3c34
After we made all the requirement changes and specify the PDF path in the dialog, the component is not rendering the PDF. The component is not editable and we are able to open the dialog only from Side Panel -> Content Tree. Please see the attached screenshot. Can someone tell me what could be the issue?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @aemninja,
One of the possible cause would be the clientId used in sling:configs. Can you confirm if it is the valid one generated for your application.
If yes, you can cross check directly by placing the markup(code snippet available in below link) in any component or in base page component. (by hardcoding the clientId and specific document instead of via PDF viewer component. Based on this result, we can narrow down the issue)
More details related to this in this documentation - https://medium.com/adobetech/easily-embed-pdf-into-your-website-using-adobe-document-cloud-view-sdk-...
Hi @aemninja,
One of the possible cause would be the clientId used in sling:configs. Can you confirm if it is the valid one generated for your application.
If yes, you can cross check directly by placing the markup(code snippet available in below link) in any component or in base page component. (by hardcoding the clientId and specific document instead of via PDF viewer component. Based on this result, we can narrow down the issue)
More details related to this in this documentation - https://medium.com/adobetech/easily-embed-pdf-into-your-website-using-adobe-document-cloud-view-sdk-...
Views
Replies
Total Likes
Hi @aemninja,
In general, content aware configuration(CA-config) are specific to paths or tenants and not specific to run modes.
Since PDF viewer component works based on CA-config, there exist an open issue highlighting this concern.
https://github.com/adobe/aem-core-wcm-components/issues/1144
The workaround suggested there is to use "Apache Sling Context-Aware Configuration - Override"
Details about this from Sling docs - https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati...
Example :
One of the ways for override is to use OSGI Factory configuration (as mentioned in above Sling doc)
Create OSGI Factory config specific to run mode and override the CA-config accordingly.
Views
Replies
Total Likes
@Vijayalakshmi_S- I have created a new runmode for author and override the configuration but it is not picking it up. Screenshot attached. is there an issue with the syntax? if I specify the configs directly under /conf/ it is working but I wanted to specify different clientId based on runmodes. Can you advise/
Views
Replies
Total Likes
Yes, the value for "overrides" is incorrect.(it is a string property so no need to enclose within quotes explicitly) Please use like the below and make sure enabled[Boolean] is set to true
For how many ever environments/runmodes you have different clientId, create this OSGI factory config for respective runmode and override clientId accordingly as above.
You can cross verify which clientId/CA-config value is picked in an environment by navigating to OSGI console -> Sling -> Context-Aware Configuration (http://localhost:4502/system/console/slingcaconfig) of that instance -> fulfil the fields and hit "Resolve".
Views
Replies
Total Likes
@Vijayalakshimi_S - I have added the below said entry in author run mode but it is still not working. I am not sure why it is still failing.
If I put back the configs in /conf/site, it is working and if I remove the entries, it stopped working. Basically I don't want to keep the configs under conf. We have different environments and wanted to keep different clientIds for different instances.
If I verify it under "/system/console/slingcaconfig", it is pointing to /conf/ setup only. Can you advise?
Views
Replies
Total Likes
There is still a small typo in your overrides value.(You have added "/" before config class name - before com.adobe...) I have attached your screenshot highlighting the same. Please remove that and check, It should work.
Attaching my working screenshot for reference:
Views
Replies
Total Likes
Views
Replies
Total Likes
Thanks for the confirmation.
Views
Replies
Total Likes
Views
Replies
Total Likes
Hi, @aemninja,
With the existing OOTB implementation of PDFViewer core component, clientID from CA-Config is picked from com.adobe.cq.wcm.core.components.internal.services.pdfviewer.PdfViewerCaConfig and given that overriding this config value is feasible via OSGI config(that works based on run modes), we can't restrict things specific to domains here.
However, getClientId() method in PDFViewer core component can be overridden (custom implementation of Core PDFViewer component can be written using Sling Model Delegation Pattern) considering your project specific use case.
Views
Replies
Total Likes
@Vijayalakshmi_S- Thank you so much for your suggestion. I was trying to override getClientId() method by using sling model delegation pattern. I am getting any error with the bundle activation. Can you advise what could be the issue?
<core.wcm.components.version>2.10.0</core.wcm.components.version>
---------------------
import com.adobe.cq.wcm.core.components.internal.services.pdfviewer.PdfViewerCaConfig;
import com.adobe.cq.wcm.core.components.models.PdfViewer;
import lombok.experimental.Delegate;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@Model(
adaptables = {Resource.class, SlingHttpServletRequest.class},
adapters = PdfViewer.class,
resourceType = "test/components/content/pdfviewer",
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class CustomPdfViewer implements PdfViewer {
private static final Logger LOG = LoggerFactory.getLogger(CustomPdfViewer.class);
@Self
@Via(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)
private PdfViewer delegate;
@Inject
private Resource resource;
private PdfViewerCaConfig caConfig;
@PostConstruct
protected void initModel() {
ConfigurationBuilder cb = (ConfigurationBuilder)this.resource.adaptTo(ConfigurationBuilder.class);
if (cb != null)
this.caConfig = (PdfViewerCaConfig)cb.as(PdfViewerCaConfig.class);
}
@Override
public String getClientId() {
LOG.info("~~~~~~~~~~~~~ CustomPdfViewer ~~~~~~~~~~~~~");
return this.caConfig.clientId();
}
private interface DelegationExclusion {
String getClientId();
}
}
Views
Replies
Total Likes
Hi @aemninja,
Let me quickly reproduce this in my local and update this thread.
Views
Replies
Total Likes
Views
Replies
Total Likes
Hi @aemninja,
Cross check the core component bundle in your instance, it should be 2.10.0 (PDF viewer component is introduced in 2.10.0. Perhaps your instance core bundle is referring to old version of core and hence PDFViewer related class is not resolvable)
You can also cross check the ui.apps package from being in Package Manager -> Expand the package -> Dependencies section should have 2.10.0
From the code base standpoint, If you are using Adobe Maven Archetype project, then below should be suffice.
Views
Replies
Total Likes
@Vijayalakshmi_S- I have already tried those steps. The installed bundle (core bundle) is also 2.10.0. Also the dependency entry is also same as what you have given below. Not sure why it is still not resolvable?
27.04.2021 08:28:19.710 *ERROR* [qtp439185624-5343] org.apache.felix.http.jetty %bundles.pluginTitle: Cannot start (org.osgi.framework.BundleException: Unable to resolve portfolio-content-bundle [641](R 641.11): missing requirement [test-content-bundle [641](R 641.11)] osgi.wiring.package; (osgi.wiring.package=com.adobe.cq.wcm.core.components.internal.services.pdfviewer) Unresolved requirements: [[test-content-bundle [641](R 641.11)] osgi.wiring.package; (osgi.wiring.package=com.adobe.cq.wcm.core.components.internal.services.pdfviewer)]) org.osgi.framework.BundleException: Unable to resolve test-content-bundle [641](R 641.11): missing requirement [test-content-bundle [641](R 641.11)] osgi.wiring.package; (osgi.wiring.package=com.adobe.cq.wcm.core.components.internal.services.pdfviewer) Unresolved requirements: [[test-content-bundle [641](R 641.11)] osgi.wiring.package; (osgi.wiring.package=com.adobe.cq.wcm.core.components.internal.services.pdfviewer)]
Views
Replies
Total Likes
Got the issue. In the code snippet you have pasted, you are using "com.adobe.cq.wcm.core.components.internal.services.pdfviewer.PdfViewerCaConfig" which is internal to Core Bundle and is not available for use by our bundle or custom project.
Only the PdfViewer Model interface (com.adobe.cq.wcm.core.components.models.PdfViewer is exposed or available for us to provide custom implementation). Remove the usage of the same(PdfViewerCaConfig) completely from your custom model and build project -> Your bundle should be active.
If you are to follow CA-config approach, you can create your own config and use the same in your custom model Or if you are following OSGI approach, create your own OSGI config/Service and use the same to retrieve ClientId.
Views
Replies
Total Likes
Views
Replies
Total Likes
You can create OSGI Factory Config (with config having properties like clientId and site specific identifier, say hostname or header value or any related from request Object) and in the custom model, you need to retrieve this factory config(all instances of factory config while referencing it) and fetch clientId based on the sitespecific identifier.
I have sample implementation for OSGI factory config in my blog. Check if you need for reference - https://myaemlearnings.blogspot.com/2020/04/osgi-factory-configuration.html
Views
Replies
Total Likes
@Vijayalakshmi_S- Thank you for the information. I have followed he blog and created the OSGi config for my usecase and fetching the config details in custom model for the pdf viewer. For some reason, the configmap value is coming as Null, even though I have created the sling:OsgiConfig for the required runmodes for the relevant PID. Can you shed some light on this please?
package com.test.proj.aem.core.models;
import com.adobe.cq.wcm.core.components.models.PdfViewer;
import lombok.experimental.Delegate;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.caconfig.ConfigurationBuilder;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Optional;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.RequestAttribute;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.via.ResourceSuperType;
import org.jsoup.helper.StringUtil;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import com.test.proj.aem.core.services.OSGIFactoryConfigPDFViewer;
import com.test.proj.aem.core.servicesconfig.OSGIFactoryConfigPDFViewerOCD;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Model(
adaptables = {Resource.class, SlingHttpServletRequest.class},
adapters = PdfViewer.class,
resourceType = "test/components/content/pdfviewer",
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class CustomPdfViewer implements PdfViewer {
private static final Logger LOG = LoggerFactory.getLogger(CustomPdfViewer.class);
@Inject
private Resource resource;
@Optional
@Inject
private String resourcePath;
@Reference(target="(testName=TEST)")
private OSGIFactoryConfigPDFViewer osgiPDFViewer;
private Map<String,OSGIFactoryConfigPDFViewer> configMap;
@Self
@Via(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)
private PdfViewer delegate;
String environmentKey;
@Reference(name = "configurationFactory", cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
protected synchronized void bindConfigurationFactory(final OSGIFactoryConfigPDFViewer config) {
if (configMap == null) {
configMap = new HashMap<>();
}
configMap.put(config.getApiEnvironmentName(), config);
}
protected synchronized void unbindConfigurationFactory(final OSGIFactoryConfigPDFViewer config) {
configMap.remove(config.getApiEnvironmentName());
}
@PostConstruct
protected void initModel() {
environmentKey = "TESTABC";
}
@Override
public String getClientId() {
try {
if(configMap.containsKey(environmentKey)) {
OSGIFactoryConfigPDFViewer configValues = configMap.get(environmentKey);
String apiId = configValues.getAPIId();
String apiTestId = configValues.getTestId();
String apiCertId = configValues.getCertId();
LOG.info("Config values ====>{} {} {}", apiID, apiTestId, apiCertId);
}
} catch (Exception e) {
LOG.error("Exception occurred in getClientId()");
}
return "262c9f22f289633c8499";
}
private interface DelegationExclusion {
String getClientId();
}
}
Views
Replies
Total Likes
Views
Likes
Replies