Merge branch 'master' into cloud-interface
[platform/upstream/iotivity.git] / cloud / account / src / main / java / org / iotivity / cloud / accountserver / AccountServer.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2016 Samsung Electronics All Rights Reserved.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
8  * // Licensed under the Apache License, Version 2.0 (the "License");
9  * // you may not use this file except in compliance with the License.
10  * // You may obtain a copy of the License at
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
14  * // Unless required by applicable law or agreed to in writing, software
15  * // distributed under the License is distributed on an "AS IS" BASIS,
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * // See the License for the specific language governing permissions and
18  * // limitations under the License.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22 package org.iotivity.cloud.accountserver;
23
24 import java.net.InetSocketAddress;
25 import java.util.Scanner;
26
27 import org.iotivity.cloud.accountserver.resources.account.AccountResource;
28 import org.iotivity.cloud.accountserver.resources.account.session.SessionResource;
29 import org.iotivity.cloud.accountserver.resources.account.tokenrefresh.TokenRefreshResource;
30 import org.iotivity.cloud.accountserver.resources.acl.group.GroupResource;
31 import org.iotivity.cloud.accountserver.resources.acl.id.AclResource;
32 import org.iotivity.cloud.accountserver.resources.acl.invite.InviteResource;
33 import org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateResource;
34 import org.iotivity.cloud.accountserver.resources.credprov.crl.CrlResource;
35 import org.iotivity.cloud.base.ServerSystem;
36 import org.iotivity.cloud.base.server.CoapServer;
37 import org.iotivity.cloud.util.Log;
38
39 /**
40  *
41  * This class is in charge of running of account server.
42  *
43  */
44 public class AccountServer {
45
46     public static void main(String[] args) throws Exception {
47         Log.Init();
48
49         System.out.println("-----Account SERVER-----");
50
51         if (args.length != 2) {
52             Log.e("coap server port and TLS mode required\n" + "ex) 5685 0\n");
53             return;
54         }
55
56         ServerSystem serverSystem = new ServerSystem();
57
58         serverSystem.addResource(new AccountResource());
59
60         serverSystem.addResource(new SessionResource());
61
62         serverSystem.addResource(new TokenRefreshResource());
63
64         serverSystem.addResource(new GroupResource());
65
66         serverSystem.addResource(new AclResource());
67
68         serverSystem.addResource(new CertificateResource());
69
70         serverSystem.addResource(new CrlResource());
71
72         serverSystem.addResource(new AclResource());
73
74         serverSystem.addResource(new InviteResource());
75
76         serverSystem.addServer(new CoapServer(
77                 new InetSocketAddress(Integer.parseInt(args[0]))));
78
79         boolean tlsMode = Integer.parseInt(args[1]) == 1;
80
81         serverSystem.startSystem(tlsMode);
82
83         Scanner in = new Scanner(System.in, "UTF-8");
84
85         System.out.println("press 'q' to terminate");
86
87         while (!in.nextLine().equals("q"));
88
89         in.close();
90
91         System.out.println("Terminating...");
92
93         serverSystem.stopSystem();
94
95         System.out.println("Terminated");
96     }
97 }