aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/core
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/core')
-rw-r--r--sdnr/wt/odlux/core/features/pom.xml11
-rw-r--r--sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java125
-rw-r--r--sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java8
-rw-r--r--sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java25
-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/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java2
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexOdluxBundle.java35
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexServlet.java65
-rw-r--r--sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/ResFilesServlet.java53
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestBundleLoaderImpl.java9
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestLoadResources.java12
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestRedirect.java48
-rw-r--r--sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestResFileServlet.java9
13 files changed, 192 insertions, 212 deletions
diff --git a/sdnr/wt/odlux/core/features/pom.xml b/sdnr/wt/odlux/core/features/pom.xml
index d63f8d892..2aa72b769 100644
--- a/sdnr/wt/odlux/core/features/pom.xml
+++ b/sdnr/wt/odlux/core/features/pom.xml
@@ -46,17 +46,6 @@
</license>
</licenses>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>mdsal-artifacts</artifactId>
- <version>${odl.controller.mdsal.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
<dependencies>
<dependency>
diff --git a/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java b/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
index 133b08494..636c9db29 100644
--- a/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
+++ b/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java
@@ -22,11 +22,11 @@ import java.util.*;
/**
- * This class is extremely useful for loading resources and classes in a fault tolerant manner
- * that works across different applications servers.
+ * This class is extremely useful for loading resources and classes in a fault tolerant manner that works across
+ * different applications servers.
*
- * It has come out of many months of frustrating use of multiple application servers at Atlassian,
- * please don't change things unless you're sure they're not going to break in one server or another!
+ * It has come out of many months of frustrating use of multiple application servers at Atlassian, please don't change
+ * things unless you're sure they're not going to break in one server or another!
*
* It was brought in from oscore trunk revision 147.
*
@@ -37,58 +37,59 @@ public class ClassLoaderUtil {
//~ Methods ////////////////////////////////////////////////////////////////
/**
- * Load all resources with a given name, potentially aggregating all results
- * from the searched classloaders. If no results are found, the resource name
- * is prepended by '/' and tried again.
+ * Load all resources with a given name, potentially aggregating all results from the searched classloaders. If no
+ * results are found, the resource name is prepended by '/' and tried again.
*
* This method will try to load the resources using the following methods (in order):
* <ul>
- * <li>From Thread.currentThread().getContextClassLoader()
- * <li>From ClassLoaderUtil.class.getClassLoader()
- * <li>callingClass.getClassLoader()
+ * <li>From Thread.currentThread().getContextClassLoader()
+ * <li>From ClassLoaderUtil.class.getClassLoader()
+ * <li>callingClass.getClassLoader()
* </ul>
*
* @param resourceName The name of the resources to load
* @param callingClass The Class object of the calling object
*/
- public static Iterator<URL> getResources(String resourceName, Class<?> callingClass, boolean aggregate) throws IOException {
+ public static Iterator<URL> getResources(String resourceName, Class<?> callingClass, boolean aggregate)
+ throws IOException {
- AggregateIterator<URL> iterator = new AggregateIterator<>();
+ AggregateIterator<URL> iterator = new AggregateIterator<>();
- iterator.addEnumeration(Thread.currentThread().getContextClassLoader().getResources(resourceName));
+ iterator.addEnumeration(Thread.currentThread().getContextClassLoader().getResources(resourceName));
- if (!iterator.hasNext() || aggregate) {
- iterator.addEnumeration(ClassLoaderUtil.class.getClassLoader().getResources(resourceName));
- }
+ if (!iterator.hasNext() || aggregate) {
+ iterator.addEnumeration(ClassLoaderUtil.class.getClassLoader().getResources(resourceName));
+ }
- if (!iterator.hasNext() || aggregate) {
- ClassLoader cl = callingClass.getClassLoader();
+ if (!iterator.hasNext() || aggregate) {
+ ClassLoader cl = callingClass.getClassLoader();
- if (cl != null) {
- iterator.addEnumeration(cl.getResources(resourceName));
- }
- }
+ if (cl != null) {
+ iterator.addEnumeration(cl.getResources(resourceName));
+ }
+ }
- if (!iterator.hasNext() && resourceName != null && (resourceName.length() == 0 || resourceName.charAt(0) != '/')) {
- return getResources('/' + resourceName, callingClass, aggregate);
- }
+ if (!iterator.hasNext() && resourceName != null
+ && (resourceName.length() == 0 || resourceName.charAt(0) != '/')) {
+ return getResources('/' + resourceName, callingClass, aggregate);
+ }
- return iterator;
- }
+ return iterator;
+ }
/**
- * Load a given resource.
- *
- * This method will try to load the resource using the following methods (in order):
- * <ul>
- * <li>From Thread.currentThread().getContextClassLoader()
- * <li>From ClassLoaderUtil.class.getClassLoader()
- * <li>callingClass.getClassLoader()
- * </ul>
- *
- * @param resourceName The name IllegalStateException("Unable to call ")of the resource to load
- * @param callingClass The Class object of the calling object
- */
+ * Load a given resource.
+ *
+ * This method will try to load the resource using the following methods (in order):
+ * <ul>
+ * <li>From Thread.currentThread().getContextClassLoader()
+ * <li>From ClassLoaderUtil.class.getClassLoader()
+ * <li>callingClass.getClassLoader()
+ * </ul>
+ *
+ * @param resourceName The name IllegalStateException("Unable to call ")of the resource to load
+ * @param callingClass The Class object of the calling object
+ */
public static URL getResource(String resourceName, Class<?> callingClass) {
URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
@@ -112,13 +113,13 @@ public class ClassLoaderUtil {
}
/**
- * This is a convenience method to load a resource as a stream.
- *
- * The algorithm used to find the resource is given in getResource()
- *
- * @param resourceName The name of the resource to load
- * @param callingClass The Class object of the calling object
- */
+ * This is a convenience method to load a resource as a stream.
+ *
+ * The algorithm used to find the resource is given in getResource()
+ *
+ * @param resourceName The name of the resource to load
+ * @param callingClass The Class object of the calling object
+ */
public static InputStream getResourceAsStream(String resourceName, Class<?> callingClass) {
URL url = getResource(resourceName, callingClass);
@@ -130,20 +131,20 @@ public class ClassLoaderUtil {
}
/**
- * Load a class with a given name.
- *
- * It will try to load the class in the following order:
- * <ul>
- * <li>From Thread.currentThread().getContextClassLoader()
- * <li>Using the basic Class.forName()
- * <li>From ClassLoaderUtil.class.getClassLoader()
- * <li>From the callingClass.getClassLoader()
- * </ul>
- *
- * @param className The name of the class to load
- * @param callingClass The Class object of the calling object
- * @throws ClassNotFoundException If the class cannot be found anywhere.
- */
+ * Load a class with a given name.
+ *
+ * It will try to load the class in the following order:
+ * <ul>
+ * <li>From Thread.currentThread().getContextClassLoader()
+ * <li>Using the basic Class.forName()
+ * <li>From ClassLoaderUtil.class.getClassLoader()
+ * <li>From the callingClass.getClassLoader()
+ * </ul>
+ *
+ * @param className The name of the class to load
+ * @param callingClass The Class object of the calling object
+ * @throws ClassNotFoundException If the class cannot be found anywhere.
+ */
public static Class<?> loadClass(String className, Class<?> callingClass) throws ClassNotFoundException {
try {
return Thread.currentThread().getContextClassLoader().loadClass(className);
@@ -161,8 +162,8 @@ public class ClassLoaderUtil {
}
/**
- * Aggregates Enumeration instances into one iterator and filters out duplicates. Always keeps one
- * ahead of the enumerator to protect against returning duplicates.
+ * Aggregates Enumeration instances into one iterator and filters out duplicates. Always keeps one ahead of the
+ * enumerator to protect against returning duplicates.
*/
static class AggregateIterator<E> implements Iterator<E> {
diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java
index f6d0b55bf..a4a0e76c3 100644
--- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java
+++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java
@@ -37,7 +37,7 @@ public class ClassLoaderUtilExt {
try {
urls = getResources(resourceName, callingClass, true);
} catch (IOException e) {
- LOG.debug("No resource {}",resourceName);
+ LOG.debug("No resource {}", resourceName);
}
if (urls != null) {
while (urls.hasNext()) {
@@ -50,11 +50,9 @@ public class ClassLoaderUtilExt {
if (url == null) {
LOG.debug("res currently not found. try to find with bundle");
Bundle b = FrameworkUtil.getBundle(callingClass);
- if(b!=null)
- {
+ if (b != null) {
url = b.getEntry(resourceName);
- }
- else {
+ } else {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
url = loader.getResource(resourceName);
}
diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java
index e1e300a0d..ab69d63c8 100644
--- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java
+++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java
@@ -25,8 +25,8 @@ import java.io.InputStreamReader;
import java.net.URL;
/**
- * At startup of each karaf bundle, each UI module creates an instance of this class via blueprint.
- * Initialize method gets called at loading of bundle.
+ * At startup of each karaf bundle, each UI module creates an instance of this class via blueprint. Initialize method
+ * gets called at loading of bundle.
*/
public class OdluxBundle {
@@ -103,12 +103,12 @@ public class OdluxBundle {
public String getResourceFileContent(String filename) {
return this.loadFileContent(this.getResource(filename));
}
-
+
protected URL getResource(String filename) {
return ClassLoaderUtilExt.getResource(filename, this.getClass());
}
- protected String loadFileContent(final URL url ) {
+ protected String loadFileContent(final URL url) {
if (url == null)
return null;
LOG.debug("try to load res " + url.toString());
@@ -124,15 +124,14 @@ public class OdluxBundle {
} catch (IOException e) {
LOG.warn("could not load resfile " + url.toString() + ": " + e.getMessage());
return null;
- }
- finally {
- if(in!=null) {
- try {
- in.close();
- } catch (IOException e) {
-
- }
- }
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+
+ }
+ }
}
return sb.toString();
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 455c83296..870011e85 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,6 +25,6 @@ public interface OdluxBundleLoader {
public int getNumberOfBundles();
- public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle);
+ public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle);
}
diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java
index f9a842556..1abed468b 100644
--- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java
+++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java
@@ -22,7 +22,9 @@ import java.util.List;
public interface OdluxBundleResourceAccess {
boolean hasResource(String fn);
+
String getResourceFileContent(String fn, List<String> bundleNames);
+
String getBundleName();
}
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 75497e08c..1ea27d71f 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
@@ -46,15 +46,15 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource
super(null, BUNDLENAME_APP);
}
+
@Override
- protected String loadFileContent(URL url)
- {
+ protected String loadFileContent(URL url) {
return loadFileContent(url, OdluxBundleLoaderImpl.getInstance().getLoadedBundles(this.getBundleName()));
}
@Override
public String getResourceFileContent(String fn, List<String> bundleNames) {
- return loadFileContent(this.getResource(fn),bundleNames);
+ return loadFileContent(this.getResource(fn), bundleNames);
}
private static String loadFileContent(URL url, List<String> bundlesNamesList) {
@@ -64,7 +64,7 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource
LOG.debug("try to load res " + url.toString());
StringBuilder sb = new StringBuilder();
Matcher matcher;
- BufferedReader in=null;
+ BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(url.openStream()));
@@ -73,8 +73,8 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource
if (url.getFile().endsWith("index.html")) {
matcher = patternRequire.matcher(inputLine);
if (matcher.find()) {
- inputLine = inputLine.substring(0, matcher.start(1)) + "\"" + String.join("\",\"", bundlesNamesList)
- + "\"" + inputLine.substring(matcher.end(1));
+ inputLine = inputLine.substring(0, matcher.start(1)) + "\""
+ + String.join("\",\"", bundlesNamesList) + "\"" + inputLine.substring(matcher.end(1));
}
matcher = patternFunction.matcher(inputLine);
if (matcher.find()) {
@@ -89,26 +89,25 @@ public class IndexOdluxBundle extends OdluxBundle implements OdluxBundleResource
hlp += bundle + ".register();" + LR;
}
}
- inputLine = inputLine.substring(0, matcher.start(1)) + hlp
- + inputLine.substring(matcher.start(1));
+ inputLine =
+ inputLine.substring(0, matcher.start(1)) + hlp + inputLine.substring(matcher.start(1));
}
}
sb.append(inputLine + LR);
}
-
+
} catch (IOException e) {
LOG.warn("could not load resfile {} : {}", url, e.getMessage());
return null;
- }
- finally {
- try {
- if (in != null) {
- in.close();
- }
- } catch (IOException e) {
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException e) {
- }
- }
+ }
+ }
return sb.toString();
}
diff --git a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexServlet.java b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexServlet.java
index db709b17d..a7cc2ac82 100644
--- a/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexServlet.java
+++ b/sdnr/wt/odlux/core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/IndexServlet.java
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.nio.file.Files;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -32,40 +31,40 @@ import org.slf4j.LoggerFactory;
public class IndexServlet extends HttpServlet {
- private static final long serialVersionUID = 3039669437157215355L;
- private static Logger LOG = LoggerFactory.getLogger(IndexServlet.class);
+ private static final long serialVersionUID = 3039669437157215355L;
+ private static Logger LOG = LoggerFactory.getLogger(IndexServlet.class);
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (req.getRequestURI() != null && req.getRequestURI().contains("favicon.ico")) {
- this.sendFile(resp, "etc/favicon.ico","image/x-icon");
- } else {
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ if (req.getRequestURI() != null && req.getRequestURI().contains("favicon.ico")) {
+ this.sendFile(resp, "etc/favicon.ico", "image/x-icon");
+ } else {
- LOG.debug("redirect to odlux/index.html");
- resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
- resp.setHeader("Location", "odlux/index.html");
- }
- }
+ LOG.debug("redirect to odlux/index.html");
+ resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ resp.setHeader("Location", "odlux/index.html");
+ }
+ }
- private void sendFile(HttpServletResponse response, String filename, String mimeType) {
- File f = new File(filename);
- if (f.exists()) {
- try {
- byte[] bytes = Files.readAllBytes(f.toPath());
- response.setContentType(mimeType);
- response.setContentLength(bytes.length);
- response.setStatus(HttpURLConnection.HTTP_OK);
- OutputStream os = response.getOutputStream();
- os.write(bytes);
- os.flush();
- os.close();
- } catch (IOException e) {
- LOG.debug("problem sending {}: {}", filename, e);
- }
- } else {
- LOG.debug("file not found: {}",filename);
- response.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
- }
- }
+ private void sendFile(HttpServletResponse response, String filename, String mimeType) {
+ File f = new File(filename);
+ if (f.exists()) {
+ try {
+ byte[] bytes = Files.readAllBytes(f.toPath());
+ response.setContentType(mimeType);
+ response.setContentLength(bytes.length);
+ response.setStatus(HttpURLConnection.HTTP_OK);
+ OutputStream os = response.getOutputStream();
+ os.write(bytes);
+ os.flush();
+ os.close();
+ } catch (IOException e) {
+ LOG.debug("problem sending {}: {}", filename, e);
+ }
+ } else {
+ LOG.debug("file not found: {}", filename);
+ response.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
+ }
+ }
}
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 321924e52..b480d89eb 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
@@ -20,12 +20,10 @@ 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.model.bundles.OdluxBundleLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,34 +44,35 @@ public class ResFilesServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- final String fn = req.getRequestURI();
+ final String fn = req.getRequestURI();
LOG.debug("Get request with for URI: {}", fn);
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;
+ 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);
- }
+ 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) {
@@ -82,7 +81,7 @@ public class ResFilesServlet extends HttpServlet {
//Provide own function that can be overloaded for test
public String getMimeType(String fileName) {
- return getServletContext().getMimeType(fileName);
+ return getServletContext().getMimeType(fileName);
}
}
diff --git a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestBundleLoaderImpl.java b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestBundleLoaderImpl.java
index c973d530b..3d817a2d2 100644
--- a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestBundleLoaderImpl.java
+++ b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestBundleLoaderImpl.java
@@ -20,7 +20,6 @@ package org.onap.ccsdk.features.sdnr.odlux.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.odlux.OdluxBundleLoaderImpl;
import org.onap.ccsdk.features.sdnr.wt.odlux.model.bundles.OdluxBundle;
@@ -45,10 +44,10 @@ public class TestBundleLoaderImpl {
bundle2.initialize();
assertNotNull(bundle1.getResourceFileContent("index.html"));
assertNotNull(bundle2.getResourceFileContent("index2.html"));
- assertEquals(loaded+2, loader.getNumberOfBundles());
+ assertEquals(loaded + 2, loader.getNumberOfBundles());
loader.addBundle(bundle1);
loader.addBundle(bundle2);
- assertEquals(loaded+2, loader.getNumberOfBundles());
+ assertEquals(loaded + 2, loader.getNumberOfBundles());
loader.removeBundle(bundle1);
loader.removeBundle(bundle2);
assertEquals(loaded, loader.getNumberOfBundles());
@@ -56,10 +55,10 @@ public class TestBundleLoaderImpl {
assertTrue(bundle1.hasResource("index.html"));
assertTrue(bundle2.hasResource("index2.html"));
assertNotNull(bundle1.getLoader());
- assertEquals(0,bundle1.getIndex());
+ assertEquals(0, bundle1.getIndex());
bundle1.clean();
bundle2.clean();
- assertEquals(loaded,loader.getNumberOfBundles());
+ assertEquals(loaded, loader.getNumberOfBundles());
}
diff --git a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestLoadResources.java b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestLoadResources.java
index d9cd920de..bef3dba28 100644
--- a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestLoadResources.java
+++ b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestLoadResources.java
@@ -16,11 +16,10 @@
* ============LICENSE_END==========================================================================
*/
package org.onap.ccsdk.features.sdnr.odlux.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.odlux.ResFilesServlet;
@@ -29,15 +28,16 @@ public class TestLoadResources {
@Test
public void test() {
ResFilesServlet servlet = new ResFilesServlet();
- String indexhtml=null;
- indexhtml=servlet.loadFileContent("odlux/index.html");
+ String indexhtml = null;
+ indexhtml = servlet.loadFileContent("odlux/index.html");
assertNotNull(indexhtml);
final String regex = "require\\(\\[.*\"run\".*\\]";
- final Pattern pattern = Pattern.compile(regex,Pattern.MULTILINE);
+ final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
System.out.println(indexhtml);
final Matcher matcher = pattern.matcher(indexhtml);
- assertTrue("Can not find patter '"+regex+"'",matcher.find());
+ assertTrue("Can not find patter '" + regex + "'", matcher.find());
}
+
@Test
public void test2() {
diff --git a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestRedirect.java b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestRedirect.java
index bbf542441..68bcae547 100644
--- a/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestRedirect.java
+++ b/sdnr/wt/odlux/core/provider/src/test/java/org/onap/ccsdk/features/sdnr/odlux/test/TestRedirect.java
@@ -18,40 +18,36 @@
package org.onap.ccsdk.features.sdnr.odlux.test;
import static org.junit.Assert.*;
-
+import static org.mockito.Mockito.*;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.odlux.IndexServlet;
-
-import static org.mockito.Mockito.*;
-
import java.io.IOException;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestRedirect {
- private static final int RESPONSECODE_REDIRECT = 301;
-
- @Test
- public void test() {
- PublicIndexServlet servlet =new PublicIndexServlet();
- HttpServletRequest req = mock(HttpServletRequest.class);
- HttpServletResponse resp = mock(HttpServletResponse.class);
- try {
- servlet.doGet(req,resp);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- verify(resp).setStatus(RESPONSECODE_REDIRECT);
- }
-
- private static class PublicIndexServlet extends IndexServlet{
- @Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doGet(req, resp);
- }
- }
+ private static final int RESPONSECODE_REDIRECT = 301;
+
+ @Test
+ public void test() {
+ PublicIndexServlet servlet = new PublicIndexServlet();
+ HttpServletRequest req = mock(HttpServletRequest.class);
+ HttpServletResponse resp = mock(HttpServletResponse.class);
+ try {
+ servlet.doGet(req, resp);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ verify(resp).setStatus(RESPONSECODE_REDIRECT);
+ }
+
+ private static class PublicIndexServlet extends IndexServlet {
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+ }
}
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 0490c80d5..6d537e38b 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
@@ -18,18 +18,16 @@
package org.onap.ccsdk.features.sdnr.odlux.test;
import static org.junit.Assert.*;
-
+import static org.mockito.Mockito.*;
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;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import static org.mockito.Mockito.*;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.odlux.OdluxBundleLoaderImpl;
import org.onap.ccsdk.features.sdnr.wt.odlux.ResFilesServlet;
@@ -43,7 +41,7 @@ public class TestResFileServlet {
@Test
public void test() throws ServletException {
servlet = new PublicResFilesServlet();
- servlet.init();
+ servlet.init();
OdluxBundleLoader loader = OdluxBundleLoaderImpl.getInstance();
OdluxBundle b = new OdluxBundle();
@@ -96,9 +94,10 @@ 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";
+ return "mimetype";
}
}
}