a5d3f1c93236f54a001fd0cfb3e9417051ce4678
[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.acl.verify.AclVerifyResource;
34 import org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateResource;
35 import org.iotivity.cloud.accountserver.resources.credprov.crl.CrlResource;
36 import org.iotivity.cloud.base.ServerSystem;
37 import org.iotivity.cloud.base.server.CoapServer;
38 import org.iotivity.cloud.util.Log;
39
40 /**
41  *
42  * This class is in charge of running of account server.
43  *
44  */
45 public class AccountServer {
46
47     public static void main(String[] args) throws Exception {
48         System.out.println("-----Account SERVER-----");
49
50         Log.Init();
51
52         if (!(args.length == 2 || args.length == 4)) {
53             Log.e("coap server <Port> and TLS mode required\n"
54                     + "and WebSocketLog-Server <Address> <Port> (optional)\n"
55                     + "ex) 5685 0 127.0.0.1 8080\n");
56             return;
57         }
58
59         if (args.length == 4) {
60             Log.InitWebLog(args[2], args[3],
61                     AccountServer.class.getSimpleName().toString());
62         }
63
64         ServerSystem serverSystem = new ServerSystem();
65
66         serverSystem.addResource(new AccountResource());
67
68         serverSystem.addResource(new SessionResource());
69
70         serverSystem.addResource(new TokenRefreshResource());
71
72         serverSystem.addResource(new GroupResource());
73
74         serverSystem.addResource(new AclResource());
75
76         serverSystem.addResource(new AclVerifyResource());
77
78         serverSystem.addResource(new CertificateResource());
79
80         serverSystem.addResource(new CrlResource());
81
82         serverSystem.addResource(new AclResource());
83
84         serverSystem.addResource(new InviteResource());
85
86         serverSystem.addServer(new CoapServer(
87                 new InetSocketAddress(Integer.parseInt(args[0]))));
88
89         boolean tlsMode = Integer.parseInt(args[1]) == 1;
90
91         serverSystem.startSystem(tlsMode);
92
93         Scanner in = new Scanner(System.in, "UTF-8");
94
95         System.out.println("press 'q' to terminate");
96
97         while (!in.nextLine().equals("q"));
98
99         in.close();
100
101         System.out.println("Terminating...");
102
103         serverSystem.stopSystem();
104
105         System.out.println("Terminated");
106     }
107 }