2 * Copyright 2017 ZTE 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.
17 package org.onap.holmes.engine.resources;
19 import io.swagger.annotations.Api;
20 import io.swagger.annotations.SwaggerDefinition;
21 import java.io.BufferedReader;
23 import java.io.FileNotFoundException;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.UnsupportedEncodingException;
28 import java.net.URLDecoder;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.Path;
31 import javax.ws.rs.Produces;
32 import javax.ws.rs.core.MediaType;
33 import lombok.extern.slf4j.Slf4j;
34 import org.jvnet.hk2.annotations.Service;
37 @Path("/swagger.json")
38 @Produces(MediaType.APPLICATION_JSON)
40 public class SwaggerResource {
43 @Produces(MediaType.APPLICATION_JSON)
44 public String getSwaggerJson() {
45 URL url = SwaggerResource.class.getResource("/swagger.json");
47 BufferedReader br = null;
49 System.out.println(URLDecoder.decode(url.getPath(), "UTF-8"));
50 File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
52 br = new BufferedReader(new FileReader(file));
53 StringBuffer buffer = new StringBuffer();
55 while ((line = br.readLine()) != null) {
58 ret = buffer.toString();
59 } catch (FileNotFoundException e) {
60 log.warn("Failed to read the API description file.");
61 } catch (IOException e) {
62 log.warn("An error occurred while reading swagger.json.");
67 } catch (IOException e) {
68 log.warn("Failed to close the file reader. This may cause memory leak.");