Update for SNI Chcecking
[policy/apex-pdp.git] / examples / examples-onap-vcpe / src / test / java / org / onap / policy / apex / domains / onap / vcpe / OnapVCpeSim.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019,2023 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.domains.onap.vcpe;
23
24 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
25 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
26 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
27 import org.onap.policy.common.gson.GsonMessageBodyHandler;
28 import org.onap.policy.common.utils.network.NetworkUtil;
29
30 /**
31  * The Class OnapVCpeSim.
32  */
33 public class OnapVCpeSim {
34     private static final int MAX_LOOPS = 100000;
35     private static HttpServletServer server;
36
37     /**
38      * Instantiates a new aai and guard sim.
39      */
40     public OnapVCpeSim(final String[] args) throws Exception {
41         server = HttpServletServerFactoryInstance.getServerFactory().build(
42             "OnapVCpeSimEndpoint", false, args[0], Integer.valueOf(args[1]).intValue(), false, "/OnapVCpeSim", false,
43             false);
44
45         server.addServletClass(null, OnapVCpeSimEndpoint.class.getName());
46         server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
47
48         server.start();
49
50         if (!NetworkUtil.isTcpPortOpen(args[0], Integer.valueOf(args[1]).intValue(), 2000, 1L)) {
51             throw new IllegalStateException("port " + args[1] + " is still not in use");
52         }
53     }
54
55     /**
56      * Tear down.
57      *
58      * @throws Exception the exception
59      */
60     public void tearDown() throws Exception {
61         if (server != null) {
62             server.stop();
63         }
64     }
65
66     /**
67      * The main method.
68      *
69      * @param args the arguments
70      * @throws Exception the exception
71      */
72     public static void main(final String[] args) throws Exception {
73         final OnapVCpeSim sim = new OnapVCpeSim(args);
74
75         for (int index = 0; index < MAX_LOOPS; index++) {
76             ThreadUtilities.sleep(100);
77         }
78
79         sim.tearDown();
80     }
81 }