aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/core
diff options
context:
space:
mode:
authorHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-06-07 17:40:50 +0200
committerHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-06-07 17:41:24 +0200
commitd93e6a996e60fb6abce9a870cef6b2d57bfa70fd (patch)
tree97595acb7fa809e742beb6cd5eeaaeab5f956ba9 /sdnr/wt/odlux/core
parent1445dabe9bc28629077033e2f189ad05dc61b884 (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')
-rw-r--r--sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java2
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java2
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/OdluxBundleLoaderImpl.java7
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/ResFilesServlet.java58
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestResFileServlet.java37
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/resources/log4j.properties12
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/resources/simplelogger.properties38
7 files changed, 103 insertions, 53 deletions
diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java
index 5c8231e9c..ce003c664 100644
--- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java
+++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java
@@ -25,4 +25,6 @@ public interface OdluxBundleLoader {
public int getNumberOfBundles();
+ public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle);
+
}
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);
+ }
+
}
diff --git a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestResFileServlet.java b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestResFileServlet.java
index 287ed70d9..217735c40 100644
--- a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestResFileServlet.java
+++ b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestResFileServlet.java
@@ -21,7 +21,9 @@ import static org.junit.Assert.*;
import java.io.IOException;
import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
@@ -38,6 +40,24 @@ public class TestResFileServlet {
PublicResFilesServlet servlet;
+ @Test
+ public void test() throws ServletException {
+ servlet = new PublicResFilesServlet();
+ servlet.init();
+
+ OdluxBundleLoader loader = OdluxBundleLoaderImpl.getInstance();
+ OdluxBundle b = new OdluxBundle();
+ b.setBundleName("b1");
+ b.setIndex(9);
+ b.setLoader(loader);
+ b.initialize();
+ System.out.println("Subtest1");
+ testResReq("odlux/index.html", HttpURLConnection.HTTP_OK);
+ System.out.println("Subtest2");
+ testResReq("odlux/fragmich.txt", HttpURLConnection.HTTP_NOT_FOUND);
+ System.out.println("Done");
+ }
+
private void testResReq(String res, int responseCode) {
HttpServletRequest req = mock(HttpServletRequest.class);
HttpServletResponse resp = mock(HttpServletResponse.class);
@@ -69,19 +89,6 @@ public class TestResFileServlet {
verify(resp).setStatus(responseCode);
}
- @Test
- public void test() {
- servlet = new PublicResFilesServlet();
- OdluxBundleLoader loader = OdluxBundleLoaderImpl.getInstance();
- OdluxBundle b = new OdluxBundle();
- b.setBundleName("b1");
- b.setIndex(9);
- b.setLoader(loader);
- b.initialize();
- testResReq("odlux/index.html", 200);
- testResReq("odlux/fragmich.txt", 404);
-
- }
@SuppressWarnings("serial")
private class PublicResFilesServlet extends ResFilesServlet {
@@ -89,5 +96,9 @@ public class TestResFileServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
}
+ @Override
+ public String getMimeType(String fileName) {
+ return "mimetype";
+ }
}
}
diff --git a/sdnr/wt/odlux/core/provider/src/test/resources/log4j.properties b/sdnr/wt/odlux/core/provider/src/test/resources/log4j.properties
deleted file mode 100644
index 142663bd2..000000000
--- a/sdnr/wt/odlux/core/provider/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,12 +0,0 @@
-log4j.rootLogger=INFO, out
-
-log4j.logger.org.apache.camel.impl.converter=WARN
-log4j.logger.org.apache.camel.management=WARN
-log4j.logger.org.apache.camel.impl.DefaultPackageScanClassResolver=WARN
-log4j.logger.org.springframework=ERROR
-
-# CONSOLE appender not used by default
-log4j.appender.out=org.apache.log4j.ConsoleAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-
diff --git a/sdnr/wt/odlux/core/provider/src/test/resources/simplelogger.properties b/sdnr/wt/odlux/core/provider/src/test/resources/simplelogger.properties
new file mode 100644
index 000000000..426f84834
--- /dev/null
+++ b/sdnr/wt/odlux/core/provider/src/test/resources/simplelogger.properties
@@ -0,0 +1,38 @@
+# SLF4J's SimpleLogger configuration file
+# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
+
+# Default logging detail level for all instances of SimpleLogger.
+# Must be one of ("trace", "debug", "info", "warn", or "error").
+# If not specified, defaults to "info".
+org.slf4j.simpleLogger.defaultLogLevel=debug
+
+# Logging detail level for a SimpleLogger instance named "xxx.yyy.zzz".
+# Must be one of ("trace", "debug", "info", "warn", or "error").
+# If not specified, the default logging detail level is used.
+# org.slf4j.simpleLogger.log.xxx.yyy=debug
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=info
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice=debug
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources=info
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=info
+
+# Set to true if you want the current date and time to be included in output messages.
+# Default is false, and will output the number of milliseconds elapsed since startup.
+#org.slf4j.simpleLogger.showDateTime=false
+
+# The date and time format to be used in the output messages.
+# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
+# If the format is not specified or is invalid, the default format is used.
+# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
+#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
+
+# Set to true if you want to output the current thread name.
+# Defaults to true.
+#org.slf4j.simpleLogger.showThreadName=true
+
+# Set to true if you want the Logger instance name to be included in output messages.
+# Defaults to true.
+#org.slf4j.simpleLogger.showLogName=true
+
+# Set to true if you want the last component of the name to be included in output messages.
+# Defaults to false.
+#org.slf4j.simpleLogger.showShortLogName=false