Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Accessing Cloud Services Configurations using HTL

Avatar

Level 2

Hi Guys,

Is it possible to access a page property on a could services configuration page using HTL or do you have to use Java to create an object first?

Cheers Jeff

1 Accepted Solution

Avatar

Correct answer by
Employee

Most of the Java-code must indeed placed into a Java-class (WcmUsePojo / Sling Model)

View solution in original post

11 Replies

Avatar

Level 10

There is no API that returns cloud information. Also - to configure AEM to use Cloud information, you configure AEM using Cloud Services. See these articles:

Scott's Digital Community: Integrating Adobe Experience Manager with with Adobe Analytics, Target an...

Scott's Digital Community: Integrating Adobe Experience Manager 6.2 with Activation - Dynamic Tag Ma...

Also - watch this Ask the AEM Community Experts:

ATACE March 28 2017

Avatar

Level 2

Thanks Scott, we are already using AEM cloud services configurations, we are just wanting to redevelop some components that are currently coded using Java scriptlets into HTL components and I was wondering if there was a way to pull the data directly from cloud services.

Avatar

Employee

What APIs do you use here? Also are you using 6.2 or 6.3?

Avatar

Level 2

Hi Feike,

Using 6.1 but I understand we are upgrading to 6.2 or 6.3 in the near future.

I have found that there was an HTL component that does what we want but the Java tag providing the data needs some updating so hopefully this will be the simplest solution.

Cheers Jeff

Avatar

Employee

Do you have a more concrete example what you are try to do?

Normally you do a lot with pageProperties or resourcePage.

Avatar

Level 2

Hi Feike,

I am a front end dev and have a few years CQ/AEM experience, I've just started working with 6.1 and am new to HTL.

We are storing API keys as a property on a Cloud Services Configurations pages for a service that we use across multiple websites in our AEM stack, each website has it's own unique key for the service.

We then configure the correct cloud service from each website home page properties we have a JSP component that uses Java Scriptlet code to pull the API key into the site for the service to use.

We would like to change this JSP to an HTL component and as I'm new to HTL I wasn't sure if we could access the cloud services configuration directly in HTL or still needed a Java tag to create the object needed.

Cheers Jeff

Avatar

Employee

Do have some code that I can look at?

OSGi services can be consumed in HTL, only limitation is that can't invoke methods with parameters.

Avatar

Level 2

Hi Feike,

Here is the contents of the JSP component that we are looking to replace with an HTL component.

Cheers Jeff

<%@page session="false"
   import="org.apache.sling.api.resource.Resource,
  org.apache.sling.api.resource.ValueMap,
  org.apache.sling.api.resource.ResourceUtil,
   com.day.cq.wcm.webservicesupport.Configuration,
   com.day.cq.wcm.webservicesupport.ConfigurationManager" %><%
%><%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %><%
%><cq:defineObjects/><%
   String[] services = pageProperties.getInherited("cq:cloudserviceconfigs", new String[]{});
  ConfigurationManager cfgMgr = resource.getResourceResolver().adaptTo(ConfigurationManager.class);
   if(cfgMgr != null) {
  String api_key = null;
  Configuration cfg = cfgMgr.getConfiguration("servicename", services);
   if(cfg != null) {
  api_key = cfg.get("api_key", null);
  }
%>
<!-- API Key -->
<script type="text/javascript">

   var apikey = '<%= api_key %>';

</script>

<%
   }
%>

Avatar

Correct answer by
Employee

Most of the Java-code must indeed placed into a Java-class (WcmUsePojo / Sling Model)

Avatar

Level 3

Is the Cloud Service Configuration for something that's OOTB (like Analytics etc), or is it a custom API service?

If it's custom, I would suggest moving from Cloud Service Configuration to a more simple OSGI service with a configuration.  Doing this would allow you to load the configuration much easier using a WCMUsePojo (or in 6.1, WCMUse) class and give access to the view.

Avatar

Employee Advisor

Just be aware, that you don't need special privileges to create/change Cloud Configuration settings, a regular author (with properly training) can do that. When you store it in an OSGI configuration, it's job for the admin user.

So prefer a CloudConfiguration if an author is supposed to change that.