~ubuntu-branches/ubuntu/saucy/restlet/saucy

« back to all changes in this revision

Viewing changes to org.restlet.example/src/org/restlet/example/book/restlet/ch04/sec6/client/MailClient.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 16:25:45 UTC
  • Revision ID: package-import@ubuntu.com-20120611162545-5w2o0resi5y3pybc
Tags: upstream-2.0.14
ImportĀ upstreamĀ versionĀ 2.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2005-2012 Restlet S.A.S.
 
3
 * 
 
4
 * The contents of this file are subject to the terms of one of the following
 
5
 * open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
 
6
 * 1.0 (the "Licenses"). You can select the license that you prefer but you may
 
7
 * not use this file except in compliance with one of these Licenses.
 
8
 * 
 
9
 * You can obtain a copy of the Apache 2.0 license at
 
10
 * http://www.opensource.org/licenses/apache-2.0
 
11
 * 
 
12
 * You can obtain a copy of the LGPL 3.0 license at
 
13
 * http://www.opensource.org/licenses/lgpl-3.0
 
14
 * 
 
15
 * You can obtain a copy of the LGPL 2.1 license at
 
16
 * http://www.opensource.org/licenses/lgpl-2.1
 
17
 * 
 
18
 * You can obtain a copy of the CDDL 1.0 license at
 
19
 * http://www.opensource.org/licenses/cddl1
 
20
 * 
 
21
 * You can obtain a copy of the EPL 1.0 license at
 
22
 * http://www.opensource.org/licenses/eclipse-1.0
 
23
 * 
 
24
 * See the Licenses for the specific language governing permissions and
 
25
 * limitations under the Licenses.
 
26
 * 
 
27
 * Alternatively, you can obtain a royalty free commercial license with less
 
28
 * limitations, transferable or non-transferable, directly at
 
29
 * http://www.restlet.com/products/restlet-framework
 
30
 * 
 
31
 * Restlet is a registered trademark of Restlet S.A.S.
 
32
 */
 
33
 
 
34
package org.restlet.example.book.restlet.ch04.sec6.client;
 
35
 
 
36
import org.restlet.Client;
 
37
import org.restlet.Context;
 
38
import org.restlet.data.Protocol;
 
39
import org.restlet.example.book.restlet.ch02.sect5.sub5.common.AccountResource;
 
40
import org.restlet.example.book.restlet.ch02.sect5.sub5.common.AccountsResource;
 
41
import org.restlet.example.book.restlet.ch02.sect5.sub5.common.RootResource;
 
42
import org.restlet.resource.ClientResource;
 
43
 
 
44
/**
 
45
 * Mail client.
 
46
 */
 
47
public class MailClient {
 
48
 
 
49
    /**
 
50
     * Mail client interacting with the RESTful mail server.
 
51
     * 
 
52
     * @param args
 
53
     *            The optional arguments.
 
54
     * @throws Exception
 
55
     */
 
56
    public static void main(String[] args) throws Exception {
 
57
        System.out.println("\n1) Set-up the service client resource\n");
 
58
        Client client = new Client(new Context(), Protocol.HTTP);
 
59
        ClientResource service = new ClientResource("http://localhost:8111");
 
60
        service.setNext(client);
 
61
 
 
62
        System.out.println("\n2) Display the root resource\n");
 
63
        RootResource mailRoot = service.getChild("/", RootResource.class);
 
64
        System.out.println(mailRoot.represent());
 
65
 
 
66
        System.out.println("\n3) Display the initial list of accounts\n");
 
67
        AccountsResource mailAccounts = service.getChild("/accounts/",
 
68
                AccountsResource.class);
 
69
        String list = mailAccounts.represent();
 
70
        System.out.println(list == null ? "<empty>\n" : list);
 
71
 
 
72
        System.out.println("4) Adds new accounts\n");
 
73
        mailAccounts.add("Tim Berners-Lee");
 
74
        mailAccounts.add("Roy Fielding");
 
75
        mailAccounts.add("Mark Baker");
 
76
        System.out.println("Three accounts added !");
 
77
 
 
78
        System.out.println("\n5) Display the updated list of accounts\n");
 
79
        System.out.println(mailAccounts.represent());
 
80
 
 
81
        System.out.println("6) Display the second account\n");
 
82
        AccountResource mailAccount = service.getChild("/accounts/2",
 
83
                AccountResource.class);
 
84
        System.out.println(mailAccount.represent());
 
85
 
 
86
        System.out
 
87
                .println("\n7) Update the individual account and display it again\n");
 
88
        mailAccount.store("Roy T. Fielding");
 
89
        System.out.println(mailAccount.represent());
 
90
 
 
91
        System.out
 
92
                .println("\n8) Delete the first account and display the list again\n");
 
93
        mailAccount = service.getChild("/accounts/1", AccountResource.class);
 
94
        mailAccount.remove();
 
95
        System.out.println(mailAccounts.represent());
 
96
    }
 
97
 
 
98
}