AEM custom logs creation from scripts - aem

we are automating the AEM configurations, we have a requirement for creating a custom log file. current Manual step followed is
login to AEM Felix console -> Sling -> log support ->Add new logger
parameters updated are log level, log file and logger.
is there a way to automate this log creation ? Please share your inputs.
Thanks in advance,

You can do this by configuring OSGI content nodes or by creating OSGI config files. For instance, I created an OSGI config node at this location:
/apps/cq/config.publish/org.apache.sling.commons.log.LogManager.factory.config-util.xml
That file has contents such as this:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
org.apache.sling.commons.log.file="logs/util.log"
org.apache.sling.commons.log.level="debug"
org.apache.sling.commons.log.names="[com.myorg.commons.util.MyUtil,com.myorg.commons.util.OtherUtil]"
org.apache.sling.commons.log.pattern="\{0,date,dd.MM.yyyy HH:mm:ss.SSS} *{4}* [{2}] {3} {5}"/>
Similarly, you can also do this for
/apps/cq/config.publish/org.apache.sling.commons.log.LogManager.factory.writer-util.xml
With contents such as
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:OsgiConfig"
org.apache.sling.commons.log.file="logs/util.log"
org.apache.sling.commons.log.file.buffered="{Boolean}false"
org.apache.sling.commons.log.file.number="5"
org.apache.sling.commons.log.file.size="20MB"/>
See https://helpx.adobe.com/experience-manager/6-3/sites/deploying/using/configuring-osgi.html for more details on how these files can be made specific to run modes.
When you install the package containing these nodes, since they are jcr:primaryType of sling:OsgiConfig they will automatically be picked up and configured in your environment (per run mode matching).

Related

URL Mapping for Digital Assets in AEM

I want to give URL mappings to DAM/Digital Assets of My sites. Especially for PDFs. Whenever I give a Download link to PDF it's Showing the full folder structure to the PDF. I want to shorten this.
I am Using AEM 6.2 .
You can also do the mapping in Sling resource resolver factory configuration
1. Go to system config manager and search for Sling resource resolver factory.
2. Add new entry "/content/dam/you-project-structure/>/" and "/content/dam/you-project-structure/</"
You can define URL mappings under the /etc/map location. Take a look at https://sling.apache.org/documentation/the-sling-engine/mappings-for-resource-resolution.html, which includes this example:
Under /etc/map you can create a folder, and then within that folder create a .content.xml file that contains properties such as these:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="sling:Mapping"
sling:internalRedirect="/content/dam/the/full/path/to/your/file.pdf"
sling:match=".+/content/short-url.pdf"/>

SELF_REFRESH not working in AEM 6.1

I working on touch UI component development and my cq:editConfig seems not to be working. The problem I am facing is Once I edit the dialog in component, its not getting reflect automatically but I have to refersh the page manually to see the effective changes.
Any idea if it is related to specific version? Here is the xml file I am using:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:EditConfig">
<cq:listeners
jcr:primaryType="cq:EditListenersConfig"
afteredit="REFRESH_SELF"/>
</jcr:root>
I just added this line to my header lib to make it work:
<!--/* Initialize the Authoring UI */-->
<sly data-sly-include="author.html" />

Disable scanning of CDI beans in WAR

I have WAR package with CDI beans. Deployment of the package is very slow because every time during deployment the package is scanned for CDI beans. Is there any option to disable this process?
The correct way is to disable discovery in the beans.xml of the relevant archive:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="none">
</beans>
According to the CDI specification this removes the archive from the list of bean-archives.
I have a feeling that what you're looking for is more of a tool. As mentioned, Weld uses class scanning to find annotations. There are ways to speed this up. One that works pretty well is Jandex, an annotation processor that can be used at compile time to create an index (easier to read database) of your classes and annotations. This does dramatically boost deployment times.

Components Checked in Design, But Not Displaying in Sidekick

We're running Adobe CQ, Version 5.5.0.20120220 Service Pack 2, and I've been tasked with creating some new templates and restricting the components available to those templates without having to manually configure them in design mode. I've followed the advice of the top-voted answer from Restrict the components in AEM 5.6.1. We already had this .content.xml file under our design node, so I simply copied an existing section from the file that is working fine and modified to match my new template.
The problem I'm having is that when I create a new page with the new template, the sidekick is empty. I can see in CRXDE that my configuration is live on the server. I can also see the configured components as checked when I go into design mode. But the sidekick remains empty. If I uncheck a component and re-check it, stuff will start showing up in the sidekick. I've done this and exported the design node via package manager, and the resulting file matches exactly (except whitespace) what I'm deploying from source control. Is there some gotcha that I'm missing here? Our other templates that are configured this way show the specified components in the sidekick just fine, so I'm guessing the difference lies in my template or the resourceType specified by my template, but I just can't seem to figure it out. Thanks in advance.
Edit -- Added snippet from .content.xml. The whole file is a bit long. If it's helpful, I can link to the full file instead.
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<clientlibs/>
<jcr:content
cq:doctype="html_5"
cq:lastModified="{Date}2013-05-08T14:25:15.588-04:00"
cq:lastModifiedBy="admin"
jcr:primaryType="nt:unstructured"
jcr:title="My Site"
sling:resourceType="wcm/core/components/designer">
<department-resources-main jcr:primaryType="nt:unstructured">
<par
jcr:primaryType="nt:unstructured"
sling:resourceType="foundation/components/parsys"
components="[/apps/aau-42/components/components/lms-user-media]">
</par>
</department-resources-main>
</jcr:content>
<images/>
</jcr:root>
Template data, located at /apps/aau-42/templates/department-resources-main:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:description="Template for AAU Main Department Resources Pages"
jcr:primaryType="cq:Template"
allowedParents="[/apps/aau-42/templates/department]"
jcr:title="AAU Main Department Resources Page">
<jcr:content
cq:allowedTemplates="[/apps/aau-42/templates/department_resources_detail]"
jcr:primaryType="cq:PageContent"
sling:resourceType="aau-42/components/pages/department-resources-main" />
</jcr:root>
Page component data, located at /apps/aau-42/components/pages/department-resources-main:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:description="Main Department Resources Page"
jcr:primaryType="cq:Component"
jcr:title="Main Department Resources Page"
sling:resourceSuperType="aau-42/components/pages/base"/>
For anyone seeing this in the future, see the comment from #anotherdave. Cached stuff has bitten me before; I should have known. As a general rule, if something you think should be working is not working in CQ, ALWAYS clear cache or try in a fresh browser!

Liquibase autocompletion in eclipse (maven project)

I'm trying to have autocompletion for liquibase.
My project works fine with liquibase, but completion doesn't work.
I'm pretty sure it did work last week, after downloading javadoc/sources from liquibase.
Now, whenever I try to have eclipse autocomplete a changelog xml, I can see this:
Loading reference grammars (sleeping).
It then disappears, and autocompletion doesn't work.
Here is an example changeset header:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<!-- This changelog is used to validate that liquibase works -->
<changeSet id="1" author="majoros" >
</changeSet>
</databaseChangeLog>
EDIT: could very well be a proxy issue. I was briefly fully connected to the internet (don't ask...), and it's working now. Still, my coworkers should have it working, too (and I'd like to understand).
Eclipse should be able to use autocomplete on XML files that have a descriptor (or whatever it's called).
Liquibase's wiki has some examples for database change sets. These all include references to xsd files. These provide information on the structure of the XML.
Sample XML for 1.9:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
</databaseChangeLog>
Sample XML for 2.0:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
</databaseChangeLog>
Eclipse fetches the xsd files from the web so an Internet connection is required. If you're behind a proxy you have to configure Eclipse to use a proxy. This might explain why it didn't work at first.
To configure a proxy in Eclipse:
Window > Preferences > General > Network connections