diff options
author | Herbert Eiselt <herbert.eiselt@highstreet-technologies.com> | 2019-06-07 17:40:50 +0200 |
---|---|---|
committer | Herbert Eiselt <herbert.eiselt@highstreet-technologies.com> | 2019-06-07 17:41:24 +0200 |
commit | d93e6a996e60fb6abce9a870cef6b2d57bfa70fd (patch) | |
tree | 97595acb7fa809e742beb6cd5eeaaeab5f956ba9 /sdnr/wt/odlux/core/provider/src/main/java | |
parent | 1445dabe9bc28629077033e2f189ad05dc61b884 (diff) |
SDNR Add missing status bar to ODLUX Framework
Modify framework and adapt all apps
Issue-ID: SDNC-789
Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Change-Id: I1ea0a3df6c3f6db08f2bd7a21eb3b4cbf230a08a
Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/odlux/core/provider/src/main/java')
3 files changed, 39 insertions, 28 deletions
diff --git a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java index dfd450f67..d335e52c7 100644 --- a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java +++ b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java @@ -98,7 +98,7 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource } in.close(); } catch (IOException e) { - LOG.warn("could not load resfile " + url.toString() + ": " + e.getMessage()); + LOG.warn("could not load resfile {} : {}", url, e.getMessage()); return null; } diff --git a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/OdluxBundleLoaderImpl.java b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/OdluxBundleLoaderImpl.java index be271026d..205c96129 100644 --- a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/OdluxBundleLoaderImpl.java +++ b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/OdluxBundleLoaderImpl.java @@ -84,11 +84,6 @@ public class OdluxBundleLoaderImpl implements OdluxBundleLoader { } - private Comparator<OdluxBundle> getBundleSorter() { - return this.sortorderbundlecomparator; - } - - public List<String> getLoadedBundles(String myBundleName) { List<String> list = new ArrayList<>(); for (OdluxBundle b : bundles2) { @@ -107,7 +102,7 @@ public class OdluxBundleLoaderImpl implements OdluxBundleLoader { return names; } - public String getResource(String fn, OdluxBundleResourceAccess indexBundle) { + public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle) { String fileContent = null; if (indexBundle.hasResource(fn)) { diff --git a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/ResFilesServlet.java b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/ResFilesServlet.java index 41d10adfa..fe00662aa 100644 --- a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/ResFilesServlet.java +++ b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/ResFilesServlet.java @@ -19,21 +19,23 @@ package org.onap.ccsdk.features.sdnr.wt.odlux; import java.io.IOException; import java.io.OutputStream; +import java.net.HttpURLConnection; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.onap.ccsdk.features.sdnr.wt.odlux.IndexOdluxBundle; + +import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundleLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ResFilesServlet extends HttpServlet { - /** - * - */ private static final long serialVersionUID = -6807215213921798293L; private static Logger LOG = LoggerFactory.getLogger(ResFilesServlet.class); + + private final IndexOdluxBundle indexBundle; public ResFilesServlet() { @@ -41,32 +43,46 @@ public class ResFilesServlet extends HttpServlet { indexBundle = new IndexOdluxBundle(); } - @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - LOG.debug("get req: " + req.getRequestURI().toString()); - final String fn = req.getRequestURI().toString(); - String fileContent = null; - - fileContent = OdluxBundleLoaderImpl.getInstance().getResource(fn, indexBundle); + final String fn = req.getRequestURI(); + LOG.debug("Get request with for URI: {}", fn); - if (fileContent != null) { - LOG.debug("found " + fn + " in res. write to output stream"); - resp.setStatus(200); - OutputStream os = resp.getOutputStream(); - os.write(fileContent.getBytes(java.nio.charset.StandardCharsets.UTF_8)); - os.flush(); - os.close(); - } else { - LOG.debug("file " + fn + " not found in res."); - resp.setStatus(404); + OdluxBundleLoader odluxBundleLoader = OdluxBundleLoaderImpl.getInstance(); + if (odluxBundleLoader != null) { + String fileContent = odluxBundleLoader.getResourceContent(fn, indexBundle); + if (fileContent != null) { + //Store header info + String mimeType = getMimeType(fn); + byte[] byteContent = fileContent.getBytes(java.nio.charset.StandardCharsets.UTF_8); + int length = byteContent.length; - } + LOG.debug("Found file in resources. Name {} mimetype {} length {} and write to output stream", fn, mimeType, length); + resp.setContentType(mimeType); + resp.setContentLength(length); + resp.setStatus(HttpURLConnection.HTTP_OK); + OutputStream os = resp.getOutputStream(); + os.write(byteContent); + os.flush(); + os.close(); + } else { + LOG.debug("File {} not found in res.", fn); + resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND); + } + } else { + LOG.debug("BundleLoaderInstance to found.", fn); + resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND); + } } public String loadFileContent(String filename) { return this.indexBundle.getResourceFileContent(filename); } + //Provide own function that can be overloaded for test + public String getMimeType(String fileName) { + return getServletContext().getMimeType(fileName); + } + } |