Category: Sling Models

Handling Http Requests, HttpClient, in AEM

When integrating with external services or APIs from Adobe Experience Manager (AEM), utilizing the HttpClient for outbound HTTP requests is a common requirement. It’s crucial to handle these connections efficiently, securely, and in a way that is compatible with AEM’s architecture to ensure optimal performance and maintainability of your code. AEM provides a specialized factory, […]

AEM Style System Component Information with Code Sling Models

As an AEM full-stack web developer who frequently works with AEM components, it’s not uncommon to require access to the AEM Style System configuration of a specific component. This information can prove invaluable when writing conditional algorithms to manipulate data output. However, the question remains: how can one retrieve the necessary AEM Style System information […]

Get Cookie Example of AEM Servlet and Sling Model

In this short article, we will show two code examples; for example, one will be showcasing how cookies values can be accessed for an AEM Servlet, and for example two, Sling Model. 1. AEM Servlet Get Cookie Example 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465package com.sourcedcode.core.servlet; import com.cat.wcm.core.util.JSONObject; import org.apache.commons.lang.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.osgi.service.component.annotations.Component; import javax.servlet.Servlet; import […]

Set Cookie Example of AEM Servlet and Sling Model

In this short article, we will show two code examples; for example, one will be showcasing how cookies values can be set for an AEM Servlet, and for example two, Sling Model. 1. AEM Servlet Set Cookie Example 12345678910111213141516171819202122232425262728293031323334353637package com.sourcedcode.core.servlets; import com.cat.wcm.core.util.JSONObject; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.osgi.service.component.annotations.Component; import javax.servlet.Servlet; import javax.servlet.http.Cookie; import […]

How to Pass Data Parameters to Sling Modal from Sightly HTL Component

You can pass data parameters from Sightly HTL component to the Sling Model backend by request attributes. For implementation, utilising the org.apache.sling.models.annotations.Model, we will add required options parameter, adaptable, with the value of SlingHttpServletRequest.class. Next, we can utilize the annotation, org.apache.sling.models.annotations.injectorspecific.RequestAttribute (@RequestAttribute), which will find the matching name of the attribute that is being passed […]

AEM Sling Model Field Injection vs Constructor Injection Memory Consumption

Article was last updated on June 7th, 2020. Sling Models field injectors are used to support injection of AEM Library-specific context objects. For example, @ScriptVariable SightlyWCMMode will inject the WCMMode object, @ScriptVariable Resource will inject the current resource object, and @ScriptVariable Style will inject the Style object. These objects are typically stored within the object, […]

AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide

The Apache Sling Model enables injector specific annotations which aggregate the standard annotations for each of the available injector, which are: Script Bindings, Value Map, Resource Path, Child Resources, Request Attributes, OSGI Services, Self, and the Sling Object. Sure we can invoke injectors by the @inject, followed by the @source annotation (with an injector name) […]

JUnit 4: AEM Sling Servlet Unit Test Example Using wcm.io AEM Mocks, Servlet by Resource Type

This article will demonstrate how to write AEM Unit tests for @SlingServletResourceTypes (OSGi DS 1.4 (R7) component property type annotations) using the Junit4 testing framework. With developers being more visual, the source code is posted below. Technologies here used are: AEM project archetype 19 (link) Mockito 2.27.0 (link) AEM Mocks JUnit 4 2.7.2 (link) This […]

Back To Top