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.

%d bloggers like this: