Updating Nokia driver
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / restapi / SwaggerApi.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
17
18 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
19 import org.slf4j.Logger;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.http.HttpHeaders;
22 import org.springframework.http.MediaType;
23 import org.springframework.stereotype.Controller;
24 import org.springframework.web.bind.annotation.RequestMapping;
25 import org.springframework.web.bind.annotation.ResponseBody;
26
27 import javax.servlet.http.HttpServletResponse;
28
29 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL;
30 import static org.slf4j.LoggerFactory.getLogger;
31 import static org.springframework.web.bind.annotation.RequestMethod.GET;
32
33 /**
34  * Responsible for providing the Nokia S-VNFM REST APIs for accessing the swagger definitions
35  */
36 @Controller
37 @RequestMapping(value = BASE_URL)
38 public class SwaggerApi {
39     private static Logger logger = getLogger(SwaggerApi.class);
40     private final SelfRegistrationManager selfRegistrationManager;
41
42     @Autowired
43     SwaggerApi(SelfRegistrationManager selfRegistrationManager) {
44         this.selfRegistrationManager = selfRegistrationManager;
45     }
46
47     /**
48      * Return the swagger definition
49      *
50      * @param httpResponse the HTTP response
51      * @return the job representing the healing operation
52      */
53     @RequestMapping(value = "/swagger.json", method = GET)
54     @ResponseBody
55     public void getSwaggerApiDefinition(HttpServletResponse httpResponse) throws Exception {
56         logger.info("REST: get swagger definition");
57         httpResponse.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
58         byte[] bytes = selfRegistrationManager.getSwaggerApiDefinition();
59         httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
60         httpResponse.getOutputStream().write(bytes);
61     }
62 }