summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/core/provider
diff options
context:
space:
mode:
authorMichael Dürre <michael.duerre@highstreet-technologies.com>2020-07-16 05:55:07 +0200
committerMichael Dürre <michael.duerre@highstreet-technologies.com>2020-07-16 05:55:21 +0200
commit7dbe38ba0522b346a0fcd9851e797f0fd71ecd5e (patch)
treecc19db7e0637c8e392d40cdf3a53bb5e5f3e0d30 /sdnr/wt/odlux/core/provider
parent25b3759a0907d06e0d8e391f751c6fcf067087f5 (diff)
switch to rfc8040 restconf
change rest interface and some small code cleanups Issue-ID: CCSDK-2572 Signed-off-by: Michael Dürre <michael.duerre@highstreet-technologies.com> Change-Id: I3475bd2574b32950c4bf84fbd1c2a9dac9af208a
Diffstat (limited to 'sdnr/wt/odlux/core/provider')
-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
7 files changed, 111 insertions, 120 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 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";
}
}
}