summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/apigateway/provider/src/main
diff options
context:
space:
mode:
authorhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-10 12:45:37 +0200
committerhighstreetherbert <herbert.eiselt@highstreet-technologies.com>2020-07-10 15:09:50 +0200
commit4a2409623b1744028abf6d5d8d1b6546919aec61 (patch)
tree47e88fda15215b5ff8e8dd17bce597d968c36ac2 /sdnr/wt/apigateway/provider/src/main
parent23c27ddcd79913d11eac16eb42c5a43899de97a1 (diff)
Reformat sdnr apigateway to ONAP code style
Reformat to ONAP code style Issue-ID: SDNC-1271 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com> Change-Id: I18f7e93e461b94949cf5a7d9262eaf33b17c6ac9 Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/apigateway/provider/src/main')
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/AaiServlet.java93
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java40
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java136
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java264
4 files changed, 269 insertions, 264 deletions
diff --git a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/AaiServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/AaiServlet.java
index 44cad5f12..0cdf79d43 100644
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/AaiServlet.java
+++ b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/AaiServlet.java
@@ -27,58 +27,59 @@ import javax.servlet.http.HttpServletResponse;
public class AaiServlet extends BaseServlet {
- /**
- *
- */
- private static final long serialVersionUID = 5946205120796162644L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "AAI interface is offline";
- private static boolean trustAll = false;
- public AaiServlet() {
- super();
- }
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5946205120796162644L;
+ private static final String OFFLINE_RESPONSE_MESSAGE = "AAI interface is offline";
+ private static boolean trustAll = false;
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setStatus(200);
- }
+ public AaiServlet() {
+ super();
+ }
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
+ @Override
+ protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.setStatus(200);
+ }
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isAAIOff();
- }
+ @Override
+ protected String getOfflineResponse() {
+ return OFFLINE_RESPONSE_MESSAGE;
+ }
- @Override
- protected String getRemoteUrl(String uri) {
+ @Override
+ protected boolean isOff() {
+ return MyProperties.getInstance().isAAIOff();
+ }
- if (uri.startsWith("/")) {
- uri = uri.substring(1);
- }
- if (uri.startsWith("aai")) {
- uri = uri.substring("aai".length());
- }
- if (uri.startsWith("/")) {
- uri = uri.substring(1);
- }
- String base = MyProperties.getInstance().getAAIBaseUrl();
- if (!base.endsWith("/")) {
- base += "/";
- }
+ @Override
+ protected String getRemoteUrl(String uri) {
- return base + uri;
- }
+ if (uri.startsWith("/")) {
+ uri = uri.substring(1);
+ }
+ if (uri.startsWith("aai")) {
+ uri = uri.substring("aai".length());
+ }
+ if (uri.startsWith("/")) {
+ uri = uri.substring(1);
+ }
+ String base = MyProperties.getInstance().getAAIBaseUrl();
+ if (!base.endsWith("/")) {
+ base += "/";
+ }
- @Override
- protected boolean doTrustAll() {
- return trustAll;
- }
+ return base + uri;
+ }
- @Override
- protected void trustAll(boolean trust) {
- trustAll = trust;
- }
+ @Override
+ protected boolean doTrustAll() {
+ return trustAll;
+ }
+
+ @Override
+ protected void trustAll(boolean trust) {
+ trustAll = trust;
+ }
}
diff --git a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java
index a7173df28..dab7ad776 100644
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java
+++ b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java
@@ -61,7 +61,9 @@ public abstract class BaseServlet extends HttpServlet {
protected abstract boolean isOff();
protected abstract boolean doTrustAll();
+
protected abstract void trustAll(boolean trust);
+
protected abstract String getRemoteUrl(String uri);
/**
@@ -74,7 +76,7 @@ public abstract class BaseServlet extends HttpServlet {
sc = SSLContext.getInstance("TLSv1.2");
if (trustall) {
if (trustCerts == null) {
- trustCerts = new TrustManager[] { new javax.net.ssl.X509TrustManager() {
+ trustCerts = new TrustManager[] {new javax.net.ssl.X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
@@ -89,7 +91,7 @@ public abstract class BaseServlet extends HttpServlet {
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
// do not check anything when trust all
}
- } };
+ }};
}
} else {
if (trustCerts != null) {
@@ -162,8 +164,7 @@ public abstract class BaseServlet extends HttpServlet {
LOG.warn(e.getMessage());
}
http.disconnect();
- }
- else {
+ } else {
this.set404Response(resp);
}
}
@@ -188,8 +189,7 @@ public abstract class BaseServlet extends HttpServlet {
LOG.warn(e.getMessage());
}
http.disconnect();
- }
- else {
+ } else {
this.set404Response(resp);
}
}
@@ -214,8 +214,7 @@ public abstract class BaseServlet extends HttpServlet {
LOG.warn(e.getMessage());
}
http.disconnect();
- }
- else {
+ } else {
this.set404Response(resp);
}
}
@@ -240,8 +239,7 @@ public abstract class BaseServlet extends HttpServlet {
LOG.warn(e.getMessage());
}
http.disconnect();
- }
- else {
+ } else {
this.set404Response(resp);
}
}
@@ -253,24 +251,24 @@ public abstract class BaseServlet extends HttpServlet {
private URLConnection getConnection(HttpServletRequest req, final String method) throws IOException {
- LOG.debug("{} Request to {}", method,req.getRequestURL());
+ LOG.debug("{} Request to {}", method, req.getRequestURL());
String surl = this.getRemoteUrl(req.getRequestURI());
- if("GET".equals(method)) {
+ if ("GET".equals(method)) {
Enumeration<?> params = req.getParameterNames();
- if(params!=null) {
+ if (params != null) {
String param;
- if(params.hasMoreElements()) {
- param=(String)params.nextElement();
- surl+="?"+param+"="+req.getParameter(param);
+ if (params.hasMoreElements()) {
+ param = (String) params.nextElement();
+ surl += "?" + param + "=" + req.getParameter(param);
}
- while(params.hasMoreElements()) {
- param=(String)params.nextElement();
- surl+="&"+param+"="+req.getParameter(param);
+ while (params.hasMoreElements()) {
+ param = (String) params.nextElement();
+ surl += "&" + param + "=" + req.getParameter(param);
}
}
}
LOG.debug("RemoteURL: {}", surl);
- if(surl==null) {
+ if (surl == null) {
return null;
}
URL url = new URL(surl);
@@ -288,7 +286,7 @@ public abstract class BaseServlet extends HttpServlet {
String s = "";
Enumeration<?> headers = req.getHeaderNames();
while (headers.hasMoreElements()) {
- String h = (String)headers.nextElement();
+ String h = (String) headers.nextElement();
String v = req.getHeader(h);
if (h != null && h.equals("Host")) {
v = url.getAuthority();
diff --git a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java
index f08a7fffa..5db305ecb 100644
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java
+++ b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java
@@ -30,68 +30,74 @@ import org.slf4j.LoggerFactory;
public class EsServlet extends BaseServlet {
- /**
- *
- */
- private static final long serialVersionUID = -3996363343749995011L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "Database interface is offline";
- private static Logger LOG = LoggerFactory.getLogger(EsServlet.class);
-
- private static boolean trustAll = false;
-
- public EsServlet() {
- super();
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (MyProperties.getInstance().corsEnabled()) {
- resp.addHeader("Access-Control-Allow-Origin", "*");
- resp.addHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
- resp.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
- }
- resp.setStatus(200);
- }
-
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
-
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isEsOff();
- }
-
- @Override
- protected String getRemoteUrl(String uri) {
- if (uri != null && uri.length() > 0) {
- uri = uri.substring("/database".length());
- }
- return MyProperties.getInstance().getEsBaseUrl() + uri;
- }
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doGet(req, resp);
- }
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPost(req, resp);
- }
- @Override
- protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doPut(req, resp);
- }
- @Override
- protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- super.doDelete(req, resp);
- }
- @Override
- protected boolean doTrustAll() {
- return trustAll;
- }
- @Override
- protected void trustAll(boolean trust) {
- trustAll = trust;
- }
-}
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3996363343749995011L;
+ private static final String OFFLINE_RESPONSE_MESSAGE = "Database interface is offline";
+ private static Logger LOG = LoggerFactory.getLogger(EsServlet.class);
+
+ private static boolean trustAll = false;
+
+ public EsServlet() {
+ super();
+ }
+
+ @Override
+ protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ if (MyProperties.getInstance().corsEnabled()) {
+ resp.addHeader("Access-Control-Allow-Origin", "*");
+ resp.addHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
+ resp.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
+ }
+ resp.setStatus(200);
+ }
+
+ @Override
+ protected String getOfflineResponse() {
+ return OFFLINE_RESPONSE_MESSAGE;
+ }
+
+ @Override
+ protected boolean isOff() {
+ return MyProperties.getInstance().isEsOff();
+ }
+
+ @Override
+ protected String getRemoteUrl(String uri) {
+ if (uri != null && uri.length() > 0) {
+ uri = uri.substring("/database".length());
+ }
+ return MyProperties.getInstance().getEsBaseUrl() + uri;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doGet(req, resp);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPost(req, resp);
+ }
+
+ @Override
+ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doPut(req, resp);
+ }
+
+ @Override
+ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ super.doDelete(req, resp);
+ }
+
+ @Override
+ protected boolean doTrustAll() {
+ return trustAll;
+ }
+
+ @Override
+ protected void trustAll(boolean trust) {
+ trustAll = trust;
+ }
+}
diff --git a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java
index 36fce2081..d49b4dce2 100644
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java
+++ b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java
@@ -35,137 +35,137 @@ import org.slf4j.LoggerFactory;
public class MyProperties {
- private static Logger LOG = LoggerFactory.getLogger(MyProperties.class);
- public static final String PROPFILE = "etc/apigateway.properties";
- private static final String DEFAULT_AAI_HEADERS = "[\"X-FromAppId:SDNR\",\"Authorization:Basic QUFJOkFBSQ==\"]";
- private static final String DEFAULT_CORSENABLED = "0";
- private static final String DEFAULT_TRUSTINSECURE = "0";
- private static final String DEFAULT_ESDATABASE = "http://sdnrdb:9200";
- private static final String DEFAULT_AAI = "off";
-
- @Override
- public String toString() {
- return "MyProperties [aaiBase=" + aaiBase + ", aaiHeaders=" + aaiHeaders + ", esBase=" + esBase
- + ", trustInsecure=" + trustInsecure + ", corsEnabled=" + corsEnabled + "]";
- }
-
- private static MyProperties mObj;
-
- private String aaiBase;
- private Map<String, String> aaiHeaders;
- private String esBase;
-
- private boolean trustInsecure;
-
- private boolean corsEnabled;
-
- public boolean isAAIOff() {
- return this.aaiBase == null ? true : this.aaiBase.equals("off");
- }
-
- public boolean isEsOff() {
- return this.esBase == null ? true : this.esBase.equals("off");
- }
-
- public String getAAIBaseUrl() {
- return this.aaiBase;
- }
-
- public String getEsBaseUrl() {
- return this.esBase;
- }
-
- public Map<String, String> getAAIHeaders() {
- return this.aaiHeaders;
- }
-
- public boolean trustInsecure() {
- return this.trustInsecure;
- }
-
- public boolean corsEnabled() {
- return this.corsEnabled;
- }
-
- public static MyProperties Instantiate() throws IOException, NumberFormatException {
- return Instantiate(new File(PROPFILE));
- }
-
- public static MyProperties Instantiate(File file) throws IOException, NumberFormatException {
-
- return Instantiate(file, false);
- }
-
- public static MyProperties Instantiate(File file, boolean force) throws IOException, NumberFormatException {
- if (mObj == null || force) {
- mObj = new MyProperties(file);
- LOG.debug("instantiated: {}", mObj.toString());
- }
- return mObj;
- }
-
- private MyProperties(File file) throws IOException, NumberFormatException {
- this.aaiBase = "off";
- this.trustInsecure = false;
- if (!file.exists()) {
- this.writeDefaults(file);
- }
- this.load(new FileInputStream(file));
- }
-
- public void load(InputStream in) throws IOException, NumberFormatException {
-
- Properties defaultProps = new Properties();
- defaultProps.load(in);
- in.close();
-
- this.aaiBase = defaultProps.getProperty("aai", DEFAULT_AAI);
- this.aaiHeaders = _parseHeadersMap(defaultProps.getProperty("aaiHeaders", DEFAULT_AAI_HEADERS));
- this.esBase = defaultProps.getProperty("database", DEFAULT_ESDATABASE);
- this.trustInsecure = Integer.parseInt(defaultProps.getProperty("insecure", DEFAULT_TRUSTINSECURE)) == 1;
- this.corsEnabled = Integer.parseInt(defaultProps.getProperty("cors", DEFAULT_CORSENABLED)) == 1;
- }
-
- private static Map<String, String> _parseHeadersMap(String s) {
- Map<String, String> r = new HashMap<>();
- try {
- JSONArray a = new JSONArray(s);
- if ( a.length() > 0) {
- for (int i = 0; i < a.length(); i++) {
- String item = a.getString(i);
- String[] hlp = item.split(":");
- if (hlp.length > 1) {
- r.put(hlp[0], hlp[1]);
- }
- }
- }
- } catch (Exception e) {
- LOG.warn("problem loading headers map: {}",e.getMessage());
- }
- return r;
- }
-
- private String writeDefaults(File f) throws IOException {
- StringBuilder sb = new StringBuilder();
- final String LR = "\n";
- FileWriter fw = new FileWriter(f);
- sb.append("aai=" + DEFAULT_AAI + LR);
- sb.append("aaiHeaders=" + DEFAULT_AAI_HEADERS + LR);
- sb.append("database=" + DEFAULT_ESDATABASE + LR);
- sb.append("insecure=" + DEFAULT_TRUSTINSECURE + LR);
- sb.append("cors=" + DEFAULT_CORSENABLED);
- try {
- fw.write(sb.toString());
- } catch (Exception e) {
- LOG.warn("problem writing default values to propertyfile {} : {}", f.getAbsolutePath() , e.getMessage());
- } finally {
- fw.close();
- }
- return sb.toString();
- }
-
- public static MyProperties getInstance() {
- return mObj;
- }
+ private static Logger LOG = LoggerFactory.getLogger(MyProperties.class);
+ public static final String PROPFILE = "etc/apigateway.properties";
+ private static final String DEFAULT_AAI_HEADERS = "[\"X-FromAppId:SDNR\",\"Authorization:Basic QUFJOkFBSQ==\"]";
+ private static final String DEFAULT_CORSENABLED = "0";
+ private static final String DEFAULT_TRUSTINSECURE = "0";
+ private static final String DEFAULT_ESDATABASE = "http://sdnrdb:9200";
+ private static final String DEFAULT_AAI = "off";
+
+ @Override
+ public String toString() {
+ return "MyProperties [aaiBase=" + aaiBase + ", aaiHeaders=" + aaiHeaders + ", esBase=" + esBase
+ + ", trustInsecure=" + trustInsecure + ", corsEnabled=" + corsEnabled + "]";
+ }
+
+ private static MyProperties mObj;
+
+ private String aaiBase;
+ private Map<String, String> aaiHeaders;
+ private String esBase;
+
+ private boolean trustInsecure;
+
+ private boolean corsEnabled;
+
+ public boolean isAAIOff() {
+ return this.aaiBase == null ? true : this.aaiBase.equals("off");
+ }
+
+ public boolean isEsOff() {
+ return this.esBase == null ? true : this.esBase.equals("off");
+ }
+
+ public String getAAIBaseUrl() {
+ return this.aaiBase;
+ }
+
+ public String getEsBaseUrl() {
+ return this.esBase;
+ }
+
+ public Map<String, String> getAAIHeaders() {
+ return this.aaiHeaders;
+ }
+
+ public boolean trustInsecure() {
+ return this.trustInsecure;
+ }
+
+ public boolean corsEnabled() {
+ return this.corsEnabled;
+ }
+
+ public static MyProperties Instantiate() throws IOException, NumberFormatException {
+ return Instantiate(new File(PROPFILE));
+ }
+
+ public static MyProperties Instantiate(File file) throws IOException, NumberFormatException {
+
+ return Instantiate(file, false);
+ }
+
+ public static MyProperties Instantiate(File file, boolean force) throws IOException, NumberFormatException {
+ if (mObj == null || force) {
+ mObj = new MyProperties(file);
+ LOG.debug("instantiated: {}", mObj.toString());
+ }
+ return mObj;
+ }
+
+ private MyProperties(File file) throws IOException, NumberFormatException {
+ this.aaiBase = "off";
+ this.trustInsecure = false;
+ if (!file.exists()) {
+ this.writeDefaults(file);
+ }
+ this.load(new FileInputStream(file));
+ }
+
+ public void load(InputStream in) throws IOException, NumberFormatException {
+
+ Properties defaultProps = new Properties();
+ defaultProps.load(in);
+ in.close();
+
+ this.aaiBase = defaultProps.getProperty("aai", DEFAULT_AAI);
+ this.aaiHeaders = _parseHeadersMap(defaultProps.getProperty("aaiHeaders", DEFAULT_AAI_HEADERS));
+ this.esBase = defaultProps.getProperty("database", DEFAULT_ESDATABASE);
+ this.trustInsecure = Integer.parseInt(defaultProps.getProperty("insecure", DEFAULT_TRUSTINSECURE)) == 1;
+ this.corsEnabled = Integer.parseInt(defaultProps.getProperty("cors", DEFAULT_CORSENABLED)) == 1;
+ }
+
+ private static Map<String, String> _parseHeadersMap(String s) {
+ Map<String, String> r = new HashMap<>();
+ try {
+ JSONArray a = new JSONArray(s);
+ if (a.length() > 0) {
+ for (int i = 0; i < a.length(); i++) {
+ String item = a.getString(i);
+ String[] hlp = item.split(":");
+ if (hlp.length > 1) {
+ r.put(hlp[0], hlp[1]);
+ }
+ }
+ }
+ } catch (Exception e) {
+ LOG.warn("problem loading headers map: {}", e.getMessage());
+ }
+ return r;
+ }
+
+ private String writeDefaults(File f) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ final String LR = "\n";
+ FileWriter fw = new FileWriter(f);
+ sb.append("aai=" + DEFAULT_AAI + LR);
+ sb.append("aaiHeaders=" + DEFAULT_AAI_HEADERS + LR);
+ sb.append("database=" + DEFAULT_ESDATABASE + LR);
+ sb.append("insecure=" + DEFAULT_TRUSTINSECURE + LR);
+ sb.append("cors=" + DEFAULT_CORSENABLED);
+ try {
+ fw.write(sb.toString());
+ } catch (Exception e) {
+ LOG.warn("problem writing default values to propertyfile {} : {}", f.getAbsolutePath(), e.getMessage());
+ } finally {
+ fw.close();
+ }
+ return sb.toString();
+ }
+
+ public static MyProperties getInstance() {
+ return mObj;
+ }
}