1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. 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 distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.odlux;
20 import java.io.IOException;
21 import java.io.OutputStream;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServlet;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 import org.onap.ccsdk.features.sdnr.wt.odlux.IndexOdluxBundle;
31 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle;
32 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleList;
33 import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoaderImpl;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class ResFilesServlet extends HttpServlet {
42 private static final long serialVersionUID = -6807215213921798293L;
43 private static Logger LOG = LoggerFactory.getLogger(ResFilesServlet.class);
44 private final IndexOdluxBundle indexBundle;
46 public ResFilesServlet() {
48 indexBundle = new IndexOdluxBundle();
49 OdluxBundleLoaderImpl.getInstance();
52 private List<String> getBundleNames(final List<OdluxBundle> bundles) {
53 final List<String> names = new ArrayList<String>();
54 for (OdluxBundle b : bundles)
55 names.add(b.getBundleName());
56 names.add(this.indexBundle.getBundleName());
61 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
63 LOG.debug("get req: " + req.getRequestURI().toString());
64 final String fn = req.getRequestURI().toString();
65 String fileContent = null;
66 final List<OdluxBundle> bundles = OdluxBundleLoaderImpl.getInstance().getBundles();
67 if (indexBundle.hasResource(fn)) {
68 bundles.sort(this.indexBundle.getBundleSorter());
69 fileContent = indexBundle.getResourceFileContent(fn, this.getBundleNames(bundles));
71 LOG.debug("not found in framework res. try to find in applications");
72 synchronized (bundles) {
73 final Iterator<OdluxBundle> it = bundles.iterator();
74 while (it.hasNext()) {
75 OdluxBundle b = it.next();
76 if (b.hasResource(fn)) {
77 LOG.debug("found res in " + b.getBundleName());
78 fileContent = b.getResourceFileContent(fn);
84 if (fileContent != null) {
85 LOG.debug("found " + fn + " in res. write to output stream");
87 OutputStream os = resp.getOutputStream();
88 os.write(fileContent.getBytes(java.nio.charset.StandardCharsets.UTF_8));
91 LOG.debug("file " + fn + " not found in res.");
97 public String loadFileContent(String filename) {
98 return this.indexBundle.getResourceFileContent(filename);