管理員通常需要自動化或簡化任何系統內的常見工作。 例如,在AEM中,管理使用者、安裝套件和管理OSGi套件組合是必須經常進行的工作。
由於AEM建置所在Sling架構的RESTful性質,大部分工作都可使用URL呼叫來完成。 cURL可用來執行這類URL呼叫,可做為AEM管理員的實用工具。
cURL是用來執行URL操作的開放原始碼命令列工具。 它支援廣泛的網際網路通訊協定,包括HTTP、HTTPS、FTP、FTPS、SCP、SFTP、TFTP、LDAP、DAP、DICT、TELNET、檔案、IMAP、POP3、SMTP和RTSP。
cURL是使用URL語法取得或傳送資料的成熟且廣泛使用的工具,最初於1997年發行。 cURL這個名稱原本的意思是「參閱URL」。
由於AEM建置所在之Sling架構的RESTful性質,大部分工作可以簡化為URL呼叫,透過cURL執行。 內容操作任務 例如啟用頁面,以及開始工作流程和 作業任務 例如套件管理及管理使用者等,可使用cURL來自動化。 此外,您可以 建立您自己的cURL AEM中大部分工作的命令。
透過cURL執行的任何AEM命令,必須如同AEM的任何使用者一樣獲得授權。 使用cURL執行AEM命令時,會考量所有ACL和存取許可權。
cURL是macOS的標準部分,有些Linux有問題。 不過,它適用於大多數的作業系統。 您可在以下網址找到最新下載內容: https://curl.haxx.se/download.html.
cURL的來源存放庫也可在GitHub上找到。
cURL命令可建置供AEM中的大部分作業使用,例如觸發工作流程、檢查OSGi設定、觸發JMX命令、建立復寫代理等等。
若要尋找特定操作所需的確切命令,您必須在執行AEM命令時,使用瀏覽器中的開發人員工具來擷取伺服器的POST呼叫。
以下步驟說明如何在Chrome瀏覽器內建立新頁面,以作為範例。
準備您要在AEM中叫用的動作。 在此案例中,我們繼續到 建立頁面 精靈,但尚未點選 建立.
啟動開發人員工具並選取 網路 標籤。 按一下 保留記錄 選項。
按一下 建立 在 建立頁面 以實際建立工作流程。
以滑鼠右鍵按一下產生的POST動作,然後選取 複製 -> 復製為cURL.
將cURL命令複製到文字編輯器並從命令中移除所有標題,其開頭為 -H
(下圖以藍色顯示)並新增適當的驗證引數,例如 -u <user>:<password>
.
透過命令列執行cURL命令並檢視回應。
以下是常見管理和操作工作的AEM cURL命令清單。
以下範例假設AEM執行於 localhost
在連線埠 4502
並使用使用者 admin
使用密碼 admin
. 其他的命令預留位置設定在角括弧中。
curl -u <user>:<password> http://<host>:<port>/crx/packmgr/service.jsp?cmd=ls
curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=create -d packageName=<name> -d groupName=<name>
curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=preview
curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/console.html/etc/packages/mycontent.zip?cmd=contents
curl -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=build
curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/mycontent.zip?cmd=rewrap
curl -u <user>:<password> -X POST -Fname=<New Name> http://localhost:4502/etc/packages/<Group Name>/<Package Name>.zip/jcr:content/vlt:definition
curl -u <user>:<password> -F cmd=upload -F force=true -F package=@test.zip http://localhost:4502/crx/packmgr/service/.json
curl -u <user>:<password> -F cmd=install http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip
curl -u <user>:<password> -F cmd=uninstall http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip
curl -u <user>:<password> -F cmd=delete http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip
curl -u <user>:<password> http://localhost:4502/etc/packages/my_packages/test.zip
curl -u <user>:<password> -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/test.zip?cmd=replicate
curl -u <user>:<password> -FcreateUser= -FauthorizableId=hashim -Frep:password=hashim http://localhost:4502/libs/granite/security/post/authorizables
curl -u <user>:<password> -FcreateGroup=group1 -FauthorizableId=testGroup1 http://localhost:4502/libs/granite/security/post/authorizables
curl -u <user>:<password> -Fprofile/age=25 http://localhost:4502/home/users/h/hashim.rw.html
curl -u <user>:<password> -FcreateUser=testuser -FauthorizableId=hashimkhan -Frep:password=hashimkhan -Fprofile/gender=male http://localhost:4502/libs/granite/security/post/authorizables
curl -u <user>:<password> -FcreateUser=testuser -FauthorizableId=testuser -Frep:password=abc123 -Fmembership=contributor http://localhost:4502/libs/granite/security/post/authorizables
curl -u <user>:<password> -FaddMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html
curl -u <user>:<password> -FremoveMembers=testuser1 http://localhost:4502/home/groups/t/testGroup.rw.html
curl -u <user>:<password> -Fmembership=contributor -Fmembership=testgroup http://localhost:4502/home/users/t/testuser.rw.html
curl -u <user>:<password> -FdeleteAuthorizable= http://localhost:4502/home/users/t/testuser
curl -u <user>:<password> -FdeleteAuthorizable= http://localhost:4502/home/groups/t/testGroup
另請參閱 備份和還原 以取得詳細資訊。
curl -u <user>:<password> -Faction=start http://localhost:4502/system/console/bundles/<bundle-name>
curl -u <user>:<password> -Faction=stop http://localhost:4502/system/console/bundles/<bundle-name>
curl -H "CQ-Action: Activate" -H "CQ-Handle: /content/test-site/" -H "CQ-Path: /content/test-site/" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://localhost:4502/dispatcher/invalidate.cache
curl -H "CQ-Action: Deactivate" -H "CQ-Handle: /content/test-site/" -H "CQ-Path: /content/test-site/" -H "Content-Length: 0" -H "Content-Type: application/octet-stream" http://localhost:4502/dispatcher/invalidate.cache
curl -u <user>:<password> "http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json?agent=publish"
http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json?agent=publish
curl -X DELETE http://localhost:4502/etc/replication/agents.author/replication99 -u <user>:<password>
curl -u <user>:<password> -F "jcr:primaryType=cq:Page" -F "jcr:content/jcr:title=new-replication" -F "jcr:content/sling:resourceType=/libs/cq/replication/components/agent" -F "jcr:content/template=/libs/cq/replication/templates/agent" -F "jcr:content/transportUri=http://localhost:4503/bin/receive?sling:authRequestLogin=1" -F "jcr:content/transportUser=admin" -F "jcr:content/transportPassword={DES}8aadb625ced91ac483390ebc10640cdf"http://localhost:4502/etc/replication/agents.author/replication99
curl -u <user>:<password> -F "cmd=pause" -F "name=publish" http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json
curl -u <user>:<password> -F "cmd=clear" -F "name=publish" http://localhost:4502/etc/replication/agents.author/publish/jcr:content.queue.json
另請參閱 社群評分和預算 以取得詳細資訊。
另請參閱 評分和徽章要點 以取得詳細資訊。
另請參閱 MSRP - MongoDB儲存資源提供者 以取得詳細資訊。
另請參閱 在AEM中啟用CRXDE Lite 以取得詳細資訊。
另請參閱 資料存放區記憶體回收 以取得詳細資訊。
另請參閱 選擇使用Adobe Analytics和Adobe Target 以取得詳細資訊。
另請參閱 單一登入 以取得詳細資訊。
以下是內容操作的AEM cURL命令清單。
以下範例假設AEM執行於 localhost
在連線埠 4502
並使用使用者 admin
使用密碼 admin
. 其他的命令預留位置設定在角括弧中。
curl -u <user>:<password> -X POST -F path="/content/path/to/page" -F cmd="activate" http://localhost:4502/bin/replicate.json
curl -u <user>:<password> -X POST -F path="/content/path/to/page" -F cmd="deactivate" http://localhost:4502/bin/replicate.json
curl -u <user>:<password> -F cmd=activate -F ignoredeactivated=true -F onlymodified=true -F path=/content/geometrixx http://localhost:4502/etc/replication/treeactivation.html
curl -u <user>:<password> -X POST -F cmd="lockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand
curl -u <user>:<password> -X POST -F cmd="unlockPage" -F path="/content/path/to/page" -F "_charset_"="utf-8" http://localhost:4502/bin/wcmcommand
curl -u <user>:<password> -F cmd=copyPage -F destParentPath=/path/to/destination/parent -F srcPath=/path/to/source/location http://localhost:4502/bin/wcmcommand
另請參閱 以程式設計方式與工作流程互動 以取得詳細資訊。
curl -u <user>:<password> -F jcr:primaryType=sling:Folder http://localhost:4502/etc/test
curl -u <user>:<password> -F :operation=delete http://localhost:4502/etc/test/test.properties
curl -u <user>:<password> -F":operation=move" -F":applyTo=/sourceurl" -F":dest=/target/parenturl/" https://localhost:4502/content
curl -u <user>:<password> -F":operation=copy" -F":applyTo=/sourceurl" -F":dest=/target/parenturl/" https://localhost:4502/content
curl -u <user>:<password> -F"*=@test.properties" http://localhost:4502/etc/test
curl -u <user>:<password> -F"test2.properties=@test.properties" http://localhost:4502/etc/test
curl -u <user>:<password> -F "*=@test.properties;type=text/plain" http://localhost:4502/etc/test
另請參閱 Assets HTTP API 以取得詳細資訊。