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

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

问题描述

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

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:我的测试站点, 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"}

获取JSESS通过请求票证而获得IONID:
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内容类型:应用程序/ json -H接受:应用程序/ 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 :(

BTW。我已禁用CSRF令牌过滤器。

BTW. I have disabled the CSRF Token Filter.

更新:
我已验证上述方法可在Alfresco Enterprise 4.1.5上创建站点。
我已验证其在Alfresco社区上也失败4.2.e
这被报告为一个错误: 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内容类型:应用程序/ x-www-form-urlencoded H ttp:// localhost:8081 / share / page / dologin

响应:

POST / share / page / dologin HTTP / 1.1
用户代理:curl / 7.35.0
主机:localhost: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-stuff):

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

curl'http:// localhost:8081 /共享/服务/模块/创建站点'-H'Cookie:JSESSIONID = 058A52486E4EB12F94D1F95302732616; alfLogin = 1417618589; alfUsername3 = admin;'-H'来源:http:// localhost:8081'-H'接受编码:gzip,deflate,sdch'-H'接受语言:en-US,en; q = 0.8'-H '用户代理:Mozilla / 5.0(Macintosh; Intel Mac OS X 10_9_1)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 32.0.1700.107 Safari / 537.36'-H'内容类型:application / json'-H'接受:* / *'-H'推荐人: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}'--compressed

虽然仍然没有生成共享站点,但仍然是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天全站免登陆