Having created a space in Part Three, we now want to access it from our web application. The Alfresco web-client provides some servlets to allow URL-based access to pages within the client. To use these servlets without having to log in you have to request an authentication ticket via a web services call and append it to the url.
We want to access the node 066a443a-a43f-4911-9ef2-56cd96a3392e in this example which is the reference for the space we created. The url is
http://localhost:8080/alfresco/n/browse/workspace/SpacesStore/066a443a-a43f-4911-9ef2-56cd96a3392e
We will be using the browse outcome of the ExternalAccessServlet which takes a node reference of the folder to display.
First we get an authentication ticket:
String userName = "admin";
String password = "admin";
String ticket = "";
// Start the session and get a ticket
try {
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub) new AuthenticationServiceLocator().getAuthenticationService();
AuthenticationResult result = authenticationService.startSession(userName, password);
ticket = result.getTicket();
}
catch (ServiceException serviceEx) {
System.out.println("javax.xml.rpc.ServiceException: " + serviceEx);
}
catch (RemoteException remoteEx) {
System.out.println("java.rmi.RemoteException: " + remoteEx);
}
System.out.println("Ticket is: " + ticket);
Now we append the ticket to the url:
String BROWSE_SPACE = "http://localhost:8080/alfresco/n/browse/workspace/SpacesStore/";
String nodeReference = "066a443a-a43f-4911-9ef2-56cd96a3392e";
String APPEND_TICKET = "?ticket=";
String url = BROWSE_SPACE + nodeReference + APPEND_TICKET + ticket;
You can then access the workspace page directly by opening up a url similar to this:
http://localhost:8080/alfresco/n/browse/workspace/SpacesStore/066a443a-a43f-4911-9ef2-56cd96a3392e?ticket=TICKET_c02f49a5cb8db3f59e4b538d25deaa202f4de493
You can get more information about accessing the web client using urls here.
Very good post. Thank you very much, helped me for my web development.
A greeting from Spain.
Incidentally, I agree theme and blog post, because it also talks about Alfresco.
I have been working with Alfresco for some weeks and I have a problem related how to give back the ticket to Alfresco after getting logged.
Suppose that I’m already logged and I stored the ticket, now I want to upload a file onto Alfresco, I get a repository with the instruction:
WebServiceClient.getRepository()
Shall I sent back the ticket to Alfresco with the instruction WebServiceClient.getRepository(SERVERURL+ticket)?
Hi,
The trick you gave worked the user created successfully. This link is really become good tutorial for starting AlFresco Web Sercive API. I dint found any link to create group using AlFresco it will be helpful if you post something related to creating group.
Thanks,
shankar
Thanks a lot Sheila…
This was a very helpful article. I was actually looking for code on getting a ticket. This is exactly the code I needed.
Keep up the good work…
Hope to see some more articles from your side..
Thanks for the comment Dino. I’ve actually changed jobs since so I don’t think I’ll be doing any more work with Alfresco going forward unfortunately.