2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
18 import java.io.IOException;
19 import javax.servlet.http.HttpServletResponse;
20 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
21 import org.slf4j.Logger;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.RequestMapping;
25 import org.springframework.web.bind.annotation.ResponseBody;
27 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
28 import static org.slf4j.LoggerFactory.getLogger;
29 import static org.springframework.http.HttpHeaders.CONTENT_LENGTH;
30 import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
31 import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
32 import static org.springframework.web.bind.annotation.RequestMethod.GET;
35 * Responsible for providing the Nokia S-VNFM REST APIs for accessing the swagger definitions
38 @RequestMapping(value = BASE_URL)
39 public class SwaggerApi {
40 private static Logger logger = getLogger(SwaggerApi.class);
41 private final SelfRegistrationManager selfRegistrationManager;
44 SwaggerApi(SelfRegistrationManager selfRegistrationManager) {
45 this.selfRegistrationManager = selfRegistrationManager;
49 * Return the swagger definition
51 * @param httpResponse the HTTP response
52 * @return the job representing the healing operation
54 @RequestMapping(value = "/swagger.json", method = GET)
56 public void getSwaggerApiDefinition(HttpServletResponse httpResponse) throws IOException {
57 logger.info("REST: get swagger definition");
58 httpResponse.addHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE);
59 byte[] bytes = selfRegistrationManager.getSwaggerApiDefinition();
60 httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length));
61 httpResponse.getOutputStream().write(bytes);