Reputation: 825
Does anybody know how to create an alfresco site from java? I found two api calls that are supposed to create a site:
1) POST /alfresco/service/api/sites. This successfully created a site but when i try to go to the site on alfresco it gives me this error:
A server error has occured.
There are a number of reasons why this could have happened: You have attempted to access a page that does not exist - check the URL in the address bar. You have attempted to access a page that is not accessible to you, such as a private Site dashboard. A valid page has been requested but the server was unable to render it due to an internal error - contact your administrator.
Return to your dashboard page
Alfresco Software Inc. © 2005-2013 All rights reserved.
2) POST /share/service/modules/create-site which gives me a 401 unauthorized. I am passing in the correct alfresco authentication ticket. Does anybody have any experience creating a site programmatically? Preferably with java.
Upvotes: 0
Views: 1543
Reputation:
This works for me in python. Maybe it helps you also in Java.
First make a Post to the DoLogin Page of Share to get the JSESSIONID Cookie, the alflogin and the alfusername
h1 = httplib.HTTPConnection(127.0.0.1,8080)
headers = {"Content-type": "application/x-www-form-urlencoded"}
pa = "username="+username+"&password="+password
h1.request("POST","/share/page/dologin",pa,headers)
response = h1.getresponse().getheaders()
Now split the response for JSESSION ID, alfusername and alflogin
cookie = jsessionid +"; "+alflogin+"; "alfusername+";"
value = {"title": "Test Side", "visibility":"PUBLIC", "description":"Add descripton here","sitePreset": "MySitePreset", "shortName": "test_side"}
headers2 = {"Content-type":"application/json", "Accept":"application/json", "Cookie": cookie}
# Get Request on any Share Page to get in touch with Share
request.get("http://127.0.0.1:8080/share/page/user/admin/dashboard", auth=(username,password), headers=headers2)
request.post("http://127.0.0.1:8080/share/service/modules/create-site", auth=(username,password), data=json.dumps(value), headers=headers2)
That creates an Alfresco Site that also can be accessed
Upvotes: 1
Reputation: 5850
If you use Alfresco version 4.1.4 or above the problem could be in CSRF policy, introduced in that version. More information you can find here: http://blogs.alfresco.com/wp/ewinlof/2013/03/11/introducing-the-new-csrf-filter-in-alfresco-share/
Also here: http://ecmstuff.blogspot.ch/2012/03/creating-alfresco-share-sites-with.html you can find a very good tutorial which worked for me. You can find working project on github: https://github.com/streetturtle/Alfresco/tree/master/AutomaticSiteCreation
Upvotes: 0