如何以编程方式在共享中创建站点? [英] How to create site in share programmatically?

查看:17
本文介绍了如何以编程方式在共享中创建站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个话题在社区(论坛、博客文章等)中已经出现了很多次,结论是应该通过 REST Post 调用来共享和 url /service/modules/create-网站

This topic has been up quite some times in the community (forums, blog posts etc) and the conclusion is that this should be done making a REST Post call to share and the url /service/modules/create-site

原因是某些特定于冲浪的东西(例如站点仪表板)是从共享端创建的.

The reason is that some surf specific stuff like the site dashboard are created from the share side.

然而,我一整天都在从不同的角度尝试这种方法,结果总是以 HTTP 200 作为响应,并且没有创建共享站点.相当令人沮丧.

However, I have been trying this approach from different angles all day, always ending up with a HTTP 200 in the response and no share site created. Quite frustrating.

我在 Alfresco Enterprise 4.2.3.3 上运行这个(我怀疑我的问题是由于最近的变化)

I'm running this on Alfresco Enterprise 4.2.3.3 (I suspect my problems is due to a recent change)

为了将其简化为易于复制的内容,我正在关注 Martin Bergljungs 关于该主题的博客文章 (http://www.ixxus.com/blog201203creating-alfresco-share-sites-javascript/),从使用 curl 开始:

To strip this down to something that is easy to reproduce, I'm following Martin Bergljungs blog post on the subject (http://www.ixxus.com/blog201203creating-alfresco-share-sites-javascript/), starting with using curl like this:

  • 创建一个带有登录凭证 (login.txt) 的文本文件,内容如下(更改为适当的值):username=admin&password=admin

用json创建一个文本文件来创建一个站点(site_data.json){"visibility" : "PUBLIC","title" : "My Test Site","shortName" : "mytestsite","description" : "我的测试站点从命令行创建", "sitePreset" : "site-dashboard"}

create a text file with the json to create a site (site_data.json) {"visibility" : "PUBLIC","title" : "My Test Site","shortName" : "mytestsite", "description" : "My Test Site created from command line", "sitePreset" : "site-dashboard"}

通过请求票获取 JSESSIONID:curl -v -d @login.txt -H "Content-Type:application/x-www-form-urlencoded" http://localhost:8081/share/page/dologin

Get the JSESSIONID by requesting a ticket: curl -v -d @login.txt -H "Content-Type:application/x-www-form-urlencoded" http://localhost:8081/share/page/dologin

将生成的 JSESSIONID 值复制到以下 curl 调用中:curl -v -d @site_data.json -H "Cookie:JSESSIONID=<插入你的 jsessionid>"-H "Content-Type:application/json" -H "Accept:application/json" http://localhost:8081/share/service/modules/create-site

copy the resulting JSESSIONID value into the following curl call: curl -v -d @site_data.json -H "Cookie:JSESSIONID=<insert your jsessionid>" -H "Content-Type:application/json" -H "Accept:application/json" http://localhost:8081/share/service/modules/create-site

curl 的输出:

* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8081 (#0)
> POST /share/service/modules/create-site HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8081
> Cookie:JSESSIONID=5963B948684F562A278909AF466D2306
> Content-Type:application/json
> Accept:application/json
> Content-Length: 196
> 
* upload completely sent off: 196 out of 196 bytes
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Language: en-US
< Content-Length: 0
< Date: Tue, 02 Dec 2014 13:57:02 GMT
< 
* Connection #0 to host localhost left intact

后一个 curl 调用导致 HTTP 200,如上所示,但登录共享显示没有创建任何站点:(

The latter curl call results in a HTTP 200 as seen above, but a login to share reveals there have been no site created what so ever :(

顺便说一句.我已禁用 CSRF 令牌过滤器.

BTW. I have disabled the CSRF Token Filter.

更新:我已验证上述方法可用于在 Alfresco Enterprise 4.1.5 上创建站点我已经验证它在 Alfresco Community 4.2.e 上也失败了这被报告为一个错误:https://issues.alfresco.com/jira/browse/MNT-11706

UPDATE: I have verified that the above approach works to create a site on Alfresco Enterprise 4.1.5 I have verified that it also fails on Alfresco Community 4.2.e This is reported as a bug: https://issues.alfresco.com/jira/browse/MNT-11706

更新:由于读者不清楚问题,我现在重新表述

UPDATE: Since the question was not clear to a reader I have reformulated it now

更新:

按照 Dave Websters 的回答,我再次尝试使用以下步骤,仍然禁用 CSRF 令牌:

Following Dave Websters answer, I been trying again using the following steps, still with CSRF Token disabled:

登录:curl -v -d @login.txt -H "Content-Type:application/x-www-form-urlencoded" http://localhost:8081/share/page/dologin

回复:

POST/share/page/dologin HTTP/1.1用户代理:curl/7.35.0主机:本地主机:8081接受:/内容类型:应用程序/x-www-form-urlencoded内容长度:29

POST /share/page/dologin HTTP/1.1 User-Agent: curl/7.35.0 Host: localhost:8081 Accept: / Content-Type:application/x-www-form-urlencoded Content-Length: 29

* upload completely sent off: 29 out of 29 bytes
< HTTP/1.1 302 Found
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Set-Cookie: JSESSIONID=058A52486E4EB12F94D1F95302732616; Path=/share/; HttpOnly
< Set-Cookie: alfLogin=1417618589; Expires=Wed, 10-Dec-2014 14:56:29 GMT; Path=/share
< Set-Cookie: alfUsername3=admin; Expires=Wed, 10-Dec-2014 14:56:29 GMT; Path=/share
< Location: http://localhost:8081/share
< Content-Length: 0
< Date: Wed, 03 Dec 2014 14:56:29 GMT

获取 cookie 值并插入到 Daves 代码中(去掉 csrf 的东西):

Took the cookie values and inserted into Daves code (with the csrf-stuff stripped out):

curl 'http://localhost:8081/share/service/modules/create-site' -H 'Cookie: JSESSIONID=058A52486E4EB12F94D1F95302732616;alf登录=1417618589;alfUsername3=admin;'-H 'Origin: http://localhost:8081' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*'-H 'Referer: http://localhost:8081/share/page/site/erik/dashboard' -H 'X-Requested-With: application/json' -H 'Connection: keep-alive' --data-binary$'{"visibility":"PUBLIC","title":"erik'","shortName":"erik'","description":"这个站点是自动生成的","sitePreset":"site-dashboard"}' --压缩

仍然没有生成共享站点,仍然是 HTTP 200 响应.日志中也没有错误.这让我发疯:(

Still no share site generated though, and still a HTTP 200 Response. No errors in the logs either. This is driving me nuts :(

新更新(有效!):

我现在发现您需要在进行登录调用后触摸"共享网页脚本,然后再通过帖子调用 create-site.我通过在两者之间发出一个 get 请求来做到这一点.这需要以某种方式初始化共享会话.

I have now found out that you will need to "touch" a share webscript after making the login call before calling create-site with a post. I do this by making a get request in between. This somehow needs to be done to initialize the share session.

推荐答案

这是我用来以编程方式生成站点的 curl 命令.我手动插入了 JSESSIONID、LOGINCOOKIECONTENTS 和 CSRFTOKEN(两次)内容,但以编程方式获取它们应该可行.

This is the curl command I use to generate sites programatically. I insert the JSESSIONID, LOGINCOOKIECONTENTS and CSRFTOKEN (twice) contents manually, but getting them programatically should work.

curl 'http://localhost:8081/share/service/modules/create-site' -H 'Cookie: JSESSIONID={JSESSIONID}; alfLogin={LOGINCOOKIECONTENTS}; alfUsername3=admin; Alfresco-CSRFToken={CSRFTOKEN};' -H 'Origin: http://localhost:8081' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Referer: http://localhost:8081/share/page/site/auto-gen-0/dashboard' -H 'X-Requested-With: application/json' -H 'Connection: keep-alive' -H 'Alfresco-CSRFToken: {CSRFTOKEN}' --data-binary $'{"visibility":"PUBLIC","title":"auto-gen'$I'","shortName":"auto-gen-'$I'","description":"This site is auto generated","sitePreset":"site-dashboard"}' --compressed

预期的响应是:

{
   "success": true
}

这篇关于如何以编程方式在共享中创建站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆