Introduction
Tickets are a way to transfer read and write privileges to other users. Any user that knows a ticket's ID can use it. They can be limited in time valid, number of uses, and may also specify which privileges the ticket grants. NOTE: Cosmo does not support number of uses, it is always defaulted to infinity. See
CosmoTickets for more information. To see a higher level Description of the API please see:
HighLevelAPIforTicketsInCalDAV.
Tickets can be used in 2 ways:
- The first is appending it to the URI as a parameter:
- The second is in the request header:
GET /MyCalendar.ics HTTP/1.1
Host: www.mysweeturl.com
Ticket: AJFHS847573
|
Methods
Making Tickets
Tickets are made using MkTicketMethod. The user must specify the resource's URI to make the ticket on and which privileges to set. The user may also specify the time and the number of visits the ticket is valid for. Note: See
CalDAV4jTutorial for information on how to further use CalDAV4j.
To make a ticket on
http://www.mysweeturl.com/MyCalendar.ics, with Read and Write Privileges, 5 uses and a 3600 second timeout:
// Create Ticket to Make
TicketRequest ticketRequest = new TicketRequest();
ticketRequest.setVisits(5);
// You can set Visits, but Cosmo will always return infinity.
// To Request infinity set visits to CalDAVConstants.INFINITY
ticketRequest.setTimeout(3600);
ticketRequest.setRead(true);
ticketRequest.setWrite(true);
// Make the ticket
MkTicketMethod mk = new MkTicketMethod("MyCalendar.ics", ticketRequest);
HttpClient http = createHttpClient();
HostConfiguration hostConfig = createHostConfiguration();
http.executeMethod(hostConfig, mk);
|
If the response status code is 200, the ticket was successfully made. In order to see the final status of the ticket you then call getResponseBodyAsTicketResponse:
TicketResponse ticketResponse = mk.getResponseBodyAsTicketResponse();
|
The returned TicketResponse will hold the new tickets id, owner, priviliges, timeout and visits. You can access these using simple getters:
String id = ticketResponse.getID();
|
Using Tickets
Once you have the tickets ID you can begin using the ticket. This is an example of getting your calendar:
GetMethod get = methodFactory.createGetMethod();
get.setPath("MyCalendar.ics");
HttpClient http = createHttpClient();
http.setTicket(id);
http.executeMethod(hostConfig, get);
|
Note: The default way to use the ticket is in the request header and not in the URI. In order to change this, before the method is executed:
//Default is HttpClient.TICKET_LOCATION.HEADERS
http.setTicketLocation(HttpClient.TICKET_LOCATION.QUERY_PARAM);
|
Deleting Tickets
Now that you have used the ticket, you can Delete it:
DelTicketMethod del = new DelTicketMethod("MyCalendar.ics",
ticketResponse.getID());
http.executeMethod(hostConfig, del);
|
A 204 No Content Status code indicates a successful delete.
PropFind
If you want to query all the valid tickets on a resource you can use PropFindMethod. Note: any tickets the user does not have access to will not be found.
Vector<PropertyName> properties = new Vector<PropertyName>();
PropertyName propertyName = new PropertyName("http://www.xythos.com/namespaces/StorageServer",
"ticketdiscovery");
propFindMethod = new PropFindMethod("MyCalendar.ics",
properties.elements());
http = createHttpClient();
hostConfig = createHostConfiguration();
http.executeMethod(hostConfig, propFindMethod);
|
Once the method is executed you can access the reponses. Note: You can propfind for more than one properties at a time. Tickets are found by doing a propfind on the ticketdiscovery property. The code below will fill the list ticketResponseList with all tickets (the user has access to) on the calendar.
responses = propFindMethod.getResponseProperties("http://www.mysweeturl.com/MyCalendar.ics");
List<TicketResponse> ticketResponseList = new ArrayList<TicketResponse>();
while (responses.hasMoreElements()) {
Property item = (Property) responses.nextElement();
if (item.getLocalName()
.equals("ticketdiscovery")) {
TicketDiscoveryProperty ticketDiscoveryProp = (TicketDiscoveryProperty) item;
ticketResponseList.addAll(ticketDiscoveryProp.getTickets());
}
}
|
--
EdBindl - 26 Jun 2006