2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.client.deployment.rest;
24 import org.glassfish.grizzly.http.server.HttpServer;
25 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
26 import org.glassfish.jersey.media.multipart.MultiPartFeature;
27 import org.glassfish.jersey.server.ResourceConfig;
28 import org.onap.policy.common.utils.validation.Assertions;
29 import org.slf4j.ext.XLogger;
30 import org.slf4j.ext.XLoggerFactory;
33 * This class is used to launch the services. It creates a Grizzly embedded web server and runs the
36 public class ApexDeploymentRest {
37 // Logger for this class
38 private static final XLogger logger = XLoggerFactory.getXLogger(ApexDeploymentRest.class);
40 // The HTTP server exposing JAX-RS resources defined in this application.
41 private HttpServer server;
44 * Starts the HTTP server for the Apex services client on the default base URI and with the
45 * default REST packages.
47 public ApexDeploymentRest() {
48 this(new ApexDeploymentRestParameters());
52 * Starts the HTTP server for the Apex services client.
54 * @param parameters The Apex parameters to use to start the server
56 public ApexDeploymentRest(final ApexDeploymentRestParameters parameters) {
57 Assertions.argumentNotNull(parameters, "parameters may not be null");
59 logger.debug("Apex services RESTful client starting . . .");
61 // Create a resource configuration that scans for JAX-RS resources and providers
62 // in org.onap.policy.apex.client.deployment.rest package
63 final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
65 // Add MultiPartFeature class for jersey-media-multipart
66 rc.register(MultiPartFeature.class);
68 // create and start a new instance of grizzly http server
69 // exposing the Jersey application at BASE_URI
70 server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc);
73 server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
74 ApexDeploymentRestMain.class.getClassLoader(), "/webapp/"), parameters.getStaticPath());
76 logger.debug("Apex services RESTful client started");
80 * Shut down the web server.
82 public void shutdown() {
83 logger.debug("Apex services RESTful client shutting down . . .");
85 logger.debug("Apex services RESTful client shut down");