aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/core/provider/src/main
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/src/main
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/src/main')
-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
3 files changed, 75 insertions, 78 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);
}
}