replace grizzly server with policy common endpoint

Issue-ID: POLICY-1915
Change-Id: I8702a8b54e158dfd0ac08140ca083f14f23963a2
Signed-off-by: Henry.Sun <henry.a.sun@est.tech>
diff --git a/examples/examples-onap-vcpe/pom.xml b/examples/examples-onap-vcpe/pom.xml
index fd59094..b9a992e 100644
--- a/examples/examples-onap-vcpe/pom.xml
+++ b/examples/examples-onap-vcpe/pom.xml
@@ -50,12 +50,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.glassfish.jersey.containers</groupId>
-            <artifactId>jersey-container-grizzly2-http</artifactId>
-            <version>${version.jersey}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.glassfish.jersey.inject</groupId>
             <artifactId>jersey-hk2</artifactId>
             <version>${version.jersey}</version>
@@ -96,6 +90,12 @@
             <artifactId>events</artifactId>
             <version>${version.policy.models}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>policy-endpoints</artifactId>
+            <version>${version.policy.common}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
index 671f333..2a6a2e8 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,31 +21,33 @@
 
 package org.onap.policy.apex.domains.onap.vcpe;
 
-import java.net.URI;
-
-import org.glassfish.grizzly.http.server.HttpServer;
-import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
-import org.glassfish.jersey.server.ResourceConfig;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.utils.network.NetworkUtil;
 
 /**
- * The Class AaiAndGuardSim.
+ * The Class OnapVCpeSim.
  */
 public class OnapVCpeSim {
     private static final int MAX_LOOPS = 100000;
-    private HttpServer server;
+    private static HttpServletServer server;
 
     /**
      * Instantiates a new aai and guard sim.
      */
-    public OnapVCpeSim(final String[] args) {
-        final String baseUri = "http://" + args[0] + ':' + args[1] + "/OnapVCpeSim";
+    public OnapVCpeSim(final String[] args) throws Exception {
+        server = HttpServletServerFactoryInstance.getServerFactory().build(
+            "OnapVCpeSimEndpoint", false, args[0], Integer.valueOf(args[1]).intValue(), "/OnapVCpeSim", false, false);
 
-        final ResourceConfig rc = new ResourceConfig(OnapVCpeSimEndpoint.class);
-        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), rc);
+        server.addServletClass(null, OnapVCpeSimEndpoint.class.getName());
+        server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
 
-        while (!server.isStarted()) {
-            ThreadUtilities.sleep(50);
+        server.start();
+
+        if (!NetworkUtil.isTcpPortOpen(args[0], Integer.valueOf(args[1]).intValue(), 2000, 1L)) {
+            throw new IllegalStateException("port " + args[1] + " is still not in use");
         }
     }
 
@@ -54,7 +57,9 @@
      * @throws Exception the exception
      */
     public void tearDown() throws Exception {
-        server.shutdown();
+        if (server != null) {
+            server.stop();
+        }
     }
 
     /**