Accessing Cloud Services Configurations using HTL | Community
Skip to main content
MavicNZ
New Participant
June 19, 2017
Solved

Accessing Cloud Services Configurations using HTL

  • June 19, 2017
  • 11 replies
  • 3764 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

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

11 replies

joerghoh
Employee
June 24, 2017

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.

New Participant
June 23, 2017

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.

Feike_Visser1
Feike_Visser1Accepted solution
Employee
June 22, 2017

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

MavicNZ
MavicNZAuthor
New Participant
June 21, 2017

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>

<%
   }
%>

Feike_Visser1
Employee
June 21, 2017

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.

MavicNZ
MavicNZAuthor
New Participant
June 20, 2017

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

Feike_Visser1
Employee
June 20, 2017

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

Normally you do a lot with pageProperties or resourcePage.

MavicNZ
MavicNZAuthor
New Participant
June 20, 2017

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

Feike_Visser1
Employee
June 20, 2017

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

MavicNZ
MavicNZAuthor
New Participant
June 19, 2017

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.