Wednesday, May 2, 2012

How to use dispatcher to serve cache content if render is unavailable in CQ / WEM

Use Case: You want to serve cached content if all the renderer in dispatcher.any is unavailable

Prerequisite: You need dispatcher version 4.1.0. You can download latest dispatcher from package share. You can also connect to Day Care to get latest dispatcher release.

Problem: Currently If all renderer is unavailable, You get "502 Bad response code". It might possible that all your pages are already cached before render went down. It will make sense to serve cached content in that case.

Solution: You can use following parameter in dispatcher.any for this,

/ServeStaleOnError "1"

You have to restart apache after making changes. You can add this tag any where at /website level. So it should be,

  # first farm entry (label is not important, just for your convenience)
/ServeStaleOnError "1"

If you want to serve custom error page if pages are not cached. Feel free to modify httpd.conf and add following line to it,

ErrorDocument 502 <Path for custom 502 page>

This is true for any error page. More information can be found here

If you are using this make sure that DispatcherPassError is set to 0. More information about this can be found here, 

You can also handle 5XX error effectively by adjusting following params in dispatcher.any
      # Page gets contacted when an instance returns a 500
    /retryDelay "1"
    /numberOfRetries "5"
    /unavailablePenalty "1"
Again You can find more information about it on Day Doc. 

Another cool thing you can do with latest dispatcher is, You can use * for client header section, So that you don't have to add all entry. Something like

 /clientheaders {*}

Feel free to comment if something is not clear.

How to Associate Digital Right Management (DRM) with a asset in CQ5.5

Use Case: You want to to associate licensing information to an Asset in DAM before serving it to user.

Solution: With CQ5.5, Now you can associate Licensing information to any Asset before serving this to user.

To do this, You have to add additional metadata to Asset called xmpRights:WebStatement that will internally point to any resource that you want to show before actual Image. CQ OOTB has one example under /content/dam/geometrixx/drm

You can also use Adobe Drive Integration with PS or Bridge to make these changes as well. Information about Adobe drive and Bridge can be found here

You can also modify asset editor page to add external metadata as well.

First, we need to create the necessary folder structure:

curl -u admin:admin -Fjcr:primaryType=sling:Folder http://localhost:4502/apps/dam

curl -u admin:admin -Fjcr:primaryType=sling:Folder http://localhost:4502/apps/dam/content/asseteditors/application/pdf

curl -u admin:admin -Fjcr:primaryType=sling:Folder http://localhost:4502/apps/dam/content/asseteditors/image/jpeg

curl -u admin:admin -Fjcr:primaryType=sling:Folder http://localhost:4502/apps/dam/content/asseteditors/image/tiff

Then we can copy the nodes from libs:

curl -u admin:admin -F:operation=copy -F:dest=/apps/dam/content/asseteditors/ http://localhost:4502/libs/dam/content/asseteditors/formitems

curl -u admin:admin -F:operation=copy -F:dest=/apps/dam/content/asseteditors/application/pdf/ http://localhost:4502/libs/dam/content/asseteditors/application/pdf/formitems

curl -u admin:admin -F:operation=copy -F:dest=/apps/dam/content/asseteditors/image/ http://localhost:4502/libs/dam/content/asseteditors/image/formitems

curl -u admin:admin -F:operation=copy -F:dest=/apps/dam/content/asseteditors/image/jpeg/ http://localhost:4502/libs/dam/content/asseteditors/image/jpeg/formitems

curl -u admin:admin -F:operation=copy -F:dest=/apps/dam/content/asseteditors/image/tiff/ http://localhost:4502/libs/dam/content/asseteditors/image/tiff/formitems

 curl commands to create the fields for the image editor:

curl -u admin:admin "-FfieldLabel=Right Management URL" -Fjcr:primaryType=cq:Widget -Fname=./xmpRights:WebStatement -Fxtype=textfield

curl -u admin:admin "-FfieldLabel=Right Management URL" -Fjcr:primaryType=cq:Widget -Fname=./xmpRights:WebStatement -Fxtype=textfield

curl -u admin:admin "-FfieldLabel=Right Management URL" -Fjcr:primaryType=cq:Widget -Fname=./xmpRights:WebStatement -Fxtype=textfield http://localhost:4502/libs/dam/content/asseteditors/image/formitems

curl -u admin:admin "-FfieldLabel=Right Management URL" -Fjcr:primaryType=cq:Widget -Fname=./xmpRights:WebStatement -Fxtype=textfield http://localhost:4502/libs/dam/content/asseteditors/image/jpeg/formitems

curl -u admin:admin "-FfieldLabel=Right Management URL" -Fjcr:primaryType=cq:Widget -Fname=./xmpRights:WebStatement -Fxtype=textfield http://localhost:4502/libs/dam/content/asseteditors/image/tiff/formitems

You can also create your own page under dam/components/drm/pages/license, But any location is fine as long as you have right URL.

After correct URL you might see your License agreement file before Image is served

You might also have to change configuration to accept license agreement. For that please do following

·         Got to http://<host>:<port>/system/console/configMgr
·         Search for “DAM Event Recorder”, click it to change the configuration
·         Click “Enable this service”.
·         Save and try accepting the license again.

After User Agree with License, They should be able to view page


This is still work in progress and might change in future releases.

How to reduce downtime for consistency check and fix CQ5.4 / WEM

Use case: Consistency check and fix takes days to complete some time, We can not afford this much down time.

Approach:  There are different kind of inconsistencies like,

Orphaned child
Error message : NodeState CHILD_UUID references inexistent parent uuid PARENT_UUID
Current solution : restore entire backup

Parent referencing inexistent child
Error message : NodeState PARENT_UUID references inexistent child {}CHILD_NAME with id CHILD_UUID
Current solution : consistency check/fix should repair such issue Or if you know UUID then slective UUID check
and fix should resolve this issue.

Child referencing invalid parent
Error message : ChildNode has invalid parent uuid: INVALID_PARENT_UUID (instead of VALID_PARENT_UUID)
Current solution : Use CRX Console

Parent not referencing existing child
Error message : javax.jcr.ItemNotFoundException: failed to build path of CHILD_UUID: PARENT_UUID has no child
entry for CHILD_UUID
Current solution : Use CRX Console

Node already exists
Error message : javax.jcr.ItemExistsException: at
org.apache.jackrabbit.core.NodeImpl.internalAddChildNode( solution : consistency check/fix should repair such issueSearch index inconsistencyError message : WARN NodeIteratorImpl: Exception retrieving Node with UUID:
003171fe-e2e8-457b-a3af-f74eed12c1b9: javax.jcr.ItemNotFoundException:
003171fe-e2e8-457b-a3af-f74eed12c1b9Current solution : recreate search index or use redo.log

More information can be found here,
Problem with full consistency check and fix is it even traverse nodes which are not corrupted. And key to do fast consistency check and fix is finding all problematic entry in advance and then doing selective consistency check and fix. Another problem is corruption will not be revealed unless node is accessed.
CRX already provide way to do consistency check and fix using UI, But it does not resolve all inconsistency, though you can use this feature to touch each node and find inconsistencies 

For CQ5.4 or CQ5.5

Or use following CURL command

Phase 1: Finding all entry.
rm login.txt
curl -c login.txt "http://<host>:<port>/crx/login.jsp?UserId=admin&Password=admin"
rm progress.txt
curl -b login.txt -f -o progress.txt -d "type=traversal&traversalLogEach=true&fixInconsistencies=true&rootNode=/" "http://<host>:<port>/crx/config/check_frame.jsp"

Phase 2: Then You can use following program to find out all inconsistencies in log
  • You can use attached file (Unzip files) to monitor your crx log (/logs/crx/error.log in CQ5.4 and /logs/error.log in CQ5.5) file and send an email in case something is wrong. To use this application
  • Compile java file using javac -classpath .:mail.jar:activation.jar
  • Create a cron Job that runs every hour to monitor your log file (For windows you can use service)
  • Use following command to run command java -classpath .:mail.jar:activation.jar FindCorruption
  • Make sure that You put all the files attached in same location Or change PROPERTY_FILE_LOCATION property in
  • Configure your mail server and output folder location information in For configuring email server please check
  • What you expect is an email when program find corruption pattern in log. This also send you location of all files you need to quickly fix inconsistencies "that can be fixed by consistency check and fix"

You can modify this program to just scan logs and output instruction some where else.

Simple Java Program to find pattern can be found here

Note: This is just an example, You can write your own version using powerful parsing scripting languages to do same task. Again this is not supported by Adobe or by Me, Feel free to add your comment though of how it can be improved.