将cURL与AEM结合使用

注意

AEM 6.4已结束扩展支持,本文档将不再更新。 有关更多详细信息,请参阅 技术支助期. 查找支持的版本 此处.

管理员通常需要自动执行或简化任何系统中的常见任务。 例如,在AEM中,管理用户、安装包和管理OSGi包都是通常必须完成的任务。

由于构建AEM的Sling框架具有RESTful性质,因此大多数任务都可以通过URL调用完成。 cURL可用于执行此类URL调用,并且对于AEM管理员而言,它也是一个有用的工具。

什么是cURL

cURL是用于执行URL操作的开源命令行工具。 它支持多种互联网协议,包括HTTP、HTTPS、FTP、FTPS、SCP、SFTP、TFTP、LDAP、DAP、DICT、TELNET、FILE、IMAP、POP3、SMTP和RTSP。

cURL是一款使用URL语法获取或发送数据的成熟且广泛使用的工具,最初于1997年发布。 名称cURL最初意为“see URL”。

由于构建AEM的Sling框架具有RESTful性质,因此大多数任务都可简化为URL调用,该调用可以使用cURL执行。 内容处理任务 例如激活页面、启动工作流以及 操作任务 使用cURL可以自动执行包管理和管理用户等操作。 此外,您还可以 创建您自己的cURL 中的大多数任务。

注意

任何通过cURL执行的AEM命令都必须像任何用户一样获得AEM的授权。 使用cURL执行AEM命令时,将遵守所有ACL和访问权限。

下载cURL

cURL是macOS和某些Linux Distros的标准部分。 但是,它适用于大多数操作系统。 最新下载可在 https://curl.haxx.se/download.html.

cURL的源存储库也可以在GitHub上找到。

构建cURL就绪AEM命令

可以为AEM中的大多数操作(如触发工作流、检查OSGi配置、触发JMX命令、创建复制代理等)构建cURL命令。

要查找特定操作所需的确切命令,您需要使用浏览器中的开发人员工具,在执行AEM命令时捕获对服务器的POST调用。

以下步骤描述如何以在Chrome浏览器中创建新页面为例执行此操作。

  1. 准备要在AEM中调用的操作。 在本例中,我们已进入 创建页面 向导,但尚未单击 创建.

    chlimage_1-66

  2. 启动开发人员工具并选择 网络 选项卡。 单击 保留日志 选项。

    chlimage_1-67

  3. 单击 创建创建页面 向导来实际创建工作流。

  4. 右键单击生成的POST操作,然后选择 复制 -> 复制为cURL.

    chlimage_1-68

  5. 将cURL命令复制到文本编辑器,并从命令中删除所有标题(以开头) -H (在下图中以蓝色突出显示),并添加正确的身份验证参数,例如 -u <user>:<password>.

    chlimage_1-69

  6. 通过命令行执行cURL命令并查看响应。

    chlimage_1-70

常见操作AEM 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> -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

备份

请参阅 备份和恢复 以了解详细信息。

OSGi

启动包

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>

Dispatcher

使缓存失效

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重新索引

请参阅 MSRP - MongoDB存储资源提供程序 以了解详细信息。

安全性

启用和禁用CRX DE Lite

请参阅 在AEM中启用CRXDE Lite 以了解详细信息。

数据存储垃圾收集

请参阅 数据存储垃圾收集 以了解详细信息。

Analytics与Target集成

请参阅 选择加入Adobe Analytics和Adobe Target 以了解详细信息。

单点登录

发送测试标题

请参阅 单点登录 以了解详细信息。

常见内容处理AEM cURL命令

以下是用于内容处理的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

工作流

请参阅 以编程方式与工作流交互 以了解详细信息。

Sling内容

创建文件夹

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

使用Sling PostServlet上传文件

curl -u <user>:<password> -F"*=@test.properties"  http://localhost:4502/etc/test

使用Sling PostServlet上传文件并指定节点名称

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

资产处理

请参阅 资产HTTP API 以了解详细信息。

在此页面上