在AEM中使用cURL

上次更新: 2023-11-07
  • 创建对象:
  • Admin

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

由于构建AEM所基于的Sling框架具有RESTful特性,因此大多数任务可以通过URL调用来完成。 cURL可用于执行此类URL调用,可以是AEM管理员的有用工具。

什么是cURL

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

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

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

注意

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

正在下载cURL

cURL是macOS和一些Linux调试程序的标准部分。 但是,它适用于大多数操作系统。 有关最新下载信息,请访问 https://curl.haxx.se/download.html.

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

构建cURL就绪的AEM命令

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

要找到特定操作所需的确切命令,您需要在执行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> -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

备份

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

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 以了解详细信息。

在此页面上