2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
12 * // http://www.apache.org/licenses/LICENSE-2.0
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.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.ciserver;
24 import java.net.InetSocketAddress;
25 import java.util.Scanner;
27 import org.iotivity.cloud.base.connector.ConnectorPool;
28 import org.iotivity.cloud.base.server.CoapServer;
29 import org.iotivity.cloud.base.server.HttpServer;
30 import org.iotivity.cloud.base.server.WebSocketServer;
31 import org.iotivity.cloud.ciserver.DeviceServerSystem.CoapDevicePool;
32 import org.iotivity.cloud.ciserver.resources.KeepAliveResource;
33 import org.iotivity.cloud.ciserver.resources.RouteResource;
34 import org.iotivity.cloud.ciserver.resources.proxy.account.Account;
35 import org.iotivity.cloud.ciserver.resources.proxy.account.AccountSession;
36 import org.iotivity.cloud.ciserver.resources.proxy.account.Acl;
37 import org.iotivity.cloud.ciserver.resources.proxy.account.AclGroup;
38 import org.iotivity.cloud.ciserver.resources.proxy.account.AclInvite;
39 import org.iotivity.cloud.ciserver.resources.proxy.account.Certificate;
40 import org.iotivity.cloud.ciserver.resources.proxy.account.Crl;
41 import org.iotivity.cloud.ciserver.resources.proxy.mq.MessageQueue;
42 import org.iotivity.cloud.ciserver.resources.proxy.rd.DevicePresence;
43 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourceDirectory;
44 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourceFind;
45 import org.iotivity.cloud.ciserver.resources.proxy.rd.ResourcePresence;
46 import org.iotivity.cloud.util.Log;
48 public class CloudInterfaceServer {
50 public static void main(String[] args) throws Exception {
54 System.out.println("-----CI SERVER-------");
56 if (args.length < 8 || args.length > 12) {
57 Log.e("\nCoAP-server <Port> and RD-server <Address> <Port> Account-server <Address> <Port> "
58 + "MQ-broker <Address> <Port> HC-proxy <HTTP-port> Websocket-server <Port> and TLS-mode <0|1> are required.\n"
59 + "and WebSocketLog-Server <Address> <Port> (optional)\n"
60 + "ex) 5683 127.0.0.1 5684 127.0.0.1 5685 127.0.0.1 5686 80 8000 0 127.0.0.1 8080\n");
64 // CoAP-TCP server port
65 int coapPort = Integer.parseInt(args[0]);
66 // HTTP-CoAP proxy server port
67 int hcProxyPort = Integer.parseInt(args[7]);
68 // CoAP-Websocket server port
69 int websocketPort = Integer.parseInt(args[8]);
71 boolean hcProxyMode = hcProxyPort > 0;
72 boolean websocketMode = websocketPort > 0;
74 boolean tlsMode = Integer.parseInt(args[9]) == 1;
76 if (args.length >= 11) {
77 Log.InitWebLog(args[10], args[11], CloudInterfaceServer.class
78 .getSimpleName().toString());
81 ConnectorPool.addConnection("rd", new InetSocketAddress(args[1],
82 Integer.parseInt(args[2])), tlsMode);
83 ConnectorPool.addConnection("account", new InetSocketAddress(args[3],
84 Integer.parseInt(args[4])), tlsMode);
85 ConnectorPool.addConnection("mq", new InetSocketAddress(args[5],
86 Integer.parseInt(args[6])), tlsMode);
88 DeviceServerSystem deviceServer = new DeviceServerSystem();
90 Account acHandler = new Account();
91 AccountSession acSessionHandler = new AccountSession();
92 ResourceDirectory rdHandler = new ResourceDirectory();
93 ResourceFind resHandler = new ResourceFind();
94 ResourcePresence adHandler = new ResourcePresence();
95 DevicePresence prsHandler = new DevicePresence();
96 MessageQueue mqHandler = new MessageQueue();
97 Acl aclHandler = new Acl();
98 AclGroup aclGroupHandler = new AclGroup();
99 Certificate certHandler = new Certificate();
100 AclInvite aclInviteHandler = new AclInvite();
101 Crl crlHandler = new Crl();
102 CoapDevicePool devicePool = deviceServer.getDevicePool();
104 deviceServer.addResource(acHandler);
106 deviceServer.addResource(acSessionHandler);
108 deviceServer.addResource(rdHandler);
110 deviceServer.addResource(resHandler);
112 deviceServer.addResource(adHandler);
114 deviceServer.addResource(prsHandler);
116 deviceServer.addResource(mqHandler);
118 deviceServer.addResource(aclHandler);
120 deviceServer.addResource(aclGroupHandler);
122 deviceServer.addResource(certHandler);
124 deviceServer.addResource(aclInviteHandler);
126 deviceServer.addResource(crlHandler);
128 KeepAliveResource resKeepAlive = new KeepAliveResource(
129 new int[] { 1, 2, 4, 8 });
131 deviceServer.addResource(resKeepAlive);
133 deviceServer.addResource(new RouteResource(devicePool));
135 deviceServer.addServer(new CoapServer(new InetSocketAddress(coapPort)));
137 // Add HTTP Server for HTTP-to-CoAP Proxy
139 deviceServer.addServer(new HttpServer(new InetSocketAddress(
144 deviceServer.addServer(new WebSocketServer(new InetSocketAddress(
148 deviceServer.startSystem(tlsMode);
150 resKeepAlive.startSessionChecker(3000, 6000);
152 Scanner in = new Scanner(System.in);
154 System.out.println("press 'q' to terminate");
156 while (!in.nextLine().equals("q"));
160 System.out.println("Terminating...");
162 resKeepAlive.stopSessionChecker();
164 deviceServer.stopSystem();
166 System.out.println("Terminated");