summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/apigateway/provider/src/main
diff options
context:
space:
mode:
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.java82
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java366
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java103
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java247
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/SitedocServlet.java80
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TerrainServlet.java79
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TilesServlet.java89
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TopologyServlet.java89
-rw-r--r--sdnr/wt/apigateway/provider/src/main/resources/org/opendaylight/blueprint/blueprint.xml58
9 files changed, 0 insertions, 1193 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
deleted file mode 100644
index 219e75a78..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/AaiServlet.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-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();
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setStatus(200);
- }
-
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
-
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isAAIOff();
- }
-
- @Override
- protected String getRemoteUrl(String 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 += "/";
- }
-
- return base + uri;
- }
-
- @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
deleted file mode 100644
index 7c8a9a1d9..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/BaseServlet.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.nio.charset.StandardCharsets;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManager;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class BaseServlet extends HttpServlet {
-
- private static final long serialVersionUID = 7403047480257892794L;
- private static Logger LOG = LoggerFactory.getLogger(BaseServlet.class);
- private static SSLContext sc;
- private static TrustManager[] trustCerts = null;
- private static final int BUFSIZE = 2048;
-
- protected abstract String getOfflineResponse();
-
- protected abstract boolean isOff();
-
- protected abstract boolean doTrustAll();
-
- protected abstract void trustAll(boolean trust);
-
- protected abstract String getRemoteUrl(String uri);
-
- private static void setupSslTrustAll(boolean trustall) throws NoSuchAlgorithmException, KeyManagementException {
-
- sc = SSLContext.getInstance("TLSv1.2");
- if (trustall) {
- if (trustCerts == null) {
- trustCerts = new TrustManager[] {new javax.net.ssl.X509TrustManager() {
- @Override
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return new java.security.cert.X509Certificate[] {};
- }
-
- @Override
- public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
- // do not check anything when trust all
- }
-
- @Override
- public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
- // do not check anything when trust all
- }
- }};
- }
- } else {
- if (trustCerts != null) {
- trustCerts = null;
- }
- }
- // Init the SSLContext with a TrustManager[] and SecureRandom()
- sc.init(null, trustCerts, new java.security.SecureRandom());
- }
-
- public BaseServlet() {
- try {
- MyProperties.Instantiate();
- } catch (Exception e) {
- LOG.error(e.getMessage());
- }
- this.trysslSetup(true);
- }
-
- private void trysslSetup() {
- this.trysslSetup(false);
- }
-
- /**
- * init or deinit ssl insecure mode regarding to property
- *
- * @param force init independent from property
- */
- private void trysslSetup(boolean force) {
- // if trustall config has changed
- boolean trustAll = MyProperties.getInstance().trustInsecure();
- if (force || this.doTrustAll() != trustAll) {
- this.trustAll(trustAll);
- // resetup ssl config
- try {
- setupSslTrustAll(trustAll);
- } catch (Exception e) {
- LOG.error("problem setting up SSL: {}", e.getMessage());
- }
- }
- }
-
- protected void sendOffResponse(HttpServletResponse response) {
- response.setStatus(200);// HTML/OK
- response.setHeader("Content-Type", "text/html; charset=utf-8");
- try {
- response.getOutputStream().write(this.getOfflineResponse().getBytes(StandardCharsets.UTF_8));
- } catch (IOException e) {
- LOG.debug("problem writing offline response");
- }
-
- }
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (this.isOff()) {
- this.sendOffResponse(resp);
- } else {
- this.trysslSetup();
- HttpURLConnection http = null;
- try {
- http = (HttpURLConnection) this.getConnection(req, "GET");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- if (http != null) {
- try {
- this.handleRequest(http, req, resp, "GET");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- http.disconnect();
- } else {
- this.set404Response(resp);
- }
- }
- }
-
- @Override
- protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (this.isOff()) {
- this.sendOffResponse(resp);
- } else {
- this.trysslSetup();
- HttpURLConnection http = null;
- try {
- http = (HttpURLConnection) this.getConnection(req, "PUT");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- if (http != null) {
- try {
- this.handleRequest(http, req, resp, "PUT");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- http.disconnect();
- } else {
- this.set404Response(resp);
- }
- }
- }
-
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (this.isOff()) {
- this.sendOffResponse(resp);
- } else {
- this.trysslSetup();
- HttpURLConnection http = null;
- try {
- http = (HttpURLConnection) this.getConnection(req, "POST");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- if (http != null) {
- try {
- this.handleRequest(http, req, resp, "POST");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- http.disconnect();
- } else {
- this.set404Response(resp);
- }
- }
- }
-
- @Override
- protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- if (this.isOff()) {
- this.sendOffResponse(resp);
- } else {
- this.trysslSetup();
- HttpURLConnection http = null;
- try {
- http = (HttpURLConnection) this.getConnection(req, "DELETE");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- if (http != null) {
- try {
- this.handleRequest(http, req, resp, "DELETE");
- } catch (IOException e) {
- LOG.warn(e.getMessage());
- }
- http.disconnect();
- } else {
- this.set404Response(resp);
- }
- }
- }
-
- private void set404Response(HttpServletResponse resp) {
- resp.setStatus(404);
- }
-
- private URLConnection getConnection(HttpServletRequest req, final String method) throws IOException {
-
- LOG.debug("{} Request to {}", method, req.getRequestURL());
- String surl = this.getRemoteUrl(req.getRequestURI());
- if ("GET".equals(method)) {
- Enumeration<?> params = req.getParameterNames();
- if (params != null) {
- String 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);
- }
- }
- }
- LOG.debug("RemoteURL: {}", surl);
- if (surl == null) {
- return null;
- }
- URL url = new URL(surl);
- URLConnection http = url.openConnection();
- ((HttpURLConnection) http).setRequestMethod(method);
- if (url.toString().startsWith("https")) {
- ((HttpsURLConnection) http).setSSLSocketFactory(sc.getSocketFactory());
- if (this.doTrustAll()) {
- HostnameVerifier allHostsValid = (hostname, session) -> true;
- ((HttpsURLConnection) http).setHostnameVerifier(allHostsValid);
- }
- }
- http.setDoOutput(true);
- // copy request headers
- String s = "";
- Enumeration<?> headers = req.getHeaderNames();
- while (headers.hasMoreElements()) {
- String h = (String) headers.nextElement();
- String v = req.getHeader(h);
- if (h != null && h.equals("Host")) {
- v = url.getAuthority();
- }
- s += String.format("%s:%s;", h, v);
- http.setRequestProperty(h, v);
- }
- LOG.debug("Request Headers: {}", s);
- return http;
- }
-
- private void handleRequest(HttpURLConnection http, HttpServletRequest req, HttpServletResponse resp, String method)
- throws IOException {
- byte[] buffer = new byte[BUFSIZE];
- int len = 0, lensum = 0;
- // send request
- // Send the message to destination
- OutputStream output = null;
- if (!method.equals("GET")) {
- try {
- output = http.getOutputStream();
- } catch (Exception e) {
- LOG.debug("problem reading output stream: {}", e.getMessage());
- }
- }
- if (output != null) {
- while (true) {
- len = req.getInputStream().read(buffer, 0, BUFSIZE);
- if (len <= 0) {
- break;
- }
- lensum += len;
- output.write(buffer, 0, len);
- }
- }
- LOG.debug("written {} data out", lensum);
- int responseCode = http.getResponseCode();
- // Receive answer
- InputStream response;
- if (responseCode >= 200 && responseCode < 300) {
- response = http.getInputStream();
- } else {
- response = http.getErrorStream();
- if (response == null) {
- http.getInputStream();
- }
- }
-
- LOG.debug("ResponseCode: {}", responseCode);
- resp.setStatus(responseCode);
- Map<String, List<String>> set = http.getHeaderFields();
- String s = "";
- if (set != null) {
- for (Map.Entry<String, List<String>> entry : set.entrySet()) {
- if (entry.getKey() == null) {
- continue;
- }
- for (String v : entry.getValue()) {
- resp.setHeader(entry.getKey(), v);
- s += String.format("%s:%s;", entry.getKey(), v);
- }
- if (MyProperties.getInstance().corsEnabled()) {
- resp.setHeader("Access-Control-Allow-Origin", "*");
- // resp.setHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
- resp.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
- }
-
- }
- }
- LOG.debug("Received Headers: {}", s);
- lensum = 0;
- if (response != null) {
- while (true) {
- len = response.read(buffer, 0, BUFSIZE);
- if (len <= 0) {
- break;
- }
- lensum += len;
- resp.getOutputStream().write(buffer, 0, len);
- }
- } else {
- LOG.debug("response is null");
- }
- LOG.debug("Received {} bytes", lensum);
- }
-
-}
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
deleted file mode 100644
index e1a9ae0f8..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/EsServlet.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern;
-
-@HttpWhiteboardServletPattern("/database/*")
-@HttpWhiteboardServletName("EsServlet")
-@Component(service = Servlet.class)
-public class EsServlet extends BaseServlet {
-
- private static final long serialVersionUID = -3996363343749995011L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "Database interface is offline";
-
- 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
deleted file mode 100644
index 560330f85..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.json.JSONArray;
-import org.slf4j.Logger;
-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";
- private static final String DEFAULT_URL_OFF = "off";
- private static final String DEFAULT_TILES = "${TILEURL}";
- private static final String DEFAULT_TOPOLOGY = "${TOPOURL}";
- private static final String DEFAULT_SITEDOC = "${SITEDOCURL}";
- private static final String DEFAULT_TERRAIN = "${TERRAINURL}";
-
- private static MyProperties mObj;
- private static final String ENVVARIABLE = "${";
- private static final String REGEXENVVARIABLE = "(\\$\\{[A-Z0-9_-]+\\})";
- private static final Pattern ENV_PATTERN = Pattern.compile(REGEXENVVARIABLE);
-
-
- private String aaiBase;
- private Map<String, String> aaiHeaders;
- private String esBase;
- private String tilesBase;
- private String topologyBase;
- private String sitedocBase;
- private String terrainBase;
-
- 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 boolean isTilesOff() {
- return this.tilesBase == null ? true : this.tilesBase.equals("off");
- }
-
- public boolean isTopologyOff() {
- return this.topologyBase == null ? true : this.topologyBase.equals("off");
- }
-
- public String getAAIBaseUrl() {
- return this.aaiBase;
- }
-
- public String getEsBaseUrl() {
- return this.esBase;
- }
-
- public String getTilesBaseUrl() {
- return this.tilesBase;
- }
-
- public String getTopologyBaseUrl() {
- return this.topologyBase;
- }
- public String getSitedocBaseUrl() {
- return this.sitedocBase;
- }
-
- public String getTerrainBaseUrl() {
- return this.terrainBase;
- }
-
- 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 = DEFAULT_AAI;
- 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 = getProperty(defaultProps,"aai", DEFAULT_AAI);
- this.aaiHeaders = parseHeadersMap(getProperty(defaultProps,"aaiHeaders", DEFAULT_AAI_HEADERS));
- this.esBase = getProperty(defaultProps,"database", DEFAULT_ESDATABASE);
- this.tilesBase = getProperty(defaultProps,"tiles", DEFAULT_TILES, DEFAULT_URL_OFF);
- this.topologyBase = getProperty(defaultProps,"topology", DEFAULT_TOPOLOGY, DEFAULT_URL_OFF);
- this.sitedocBase = getProperty(defaultProps,"sitedoc", DEFAULT_SITEDOC, DEFAULT_URL_OFF);
- this.terrainBase = getProperty(defaultProps,"terrain", DEFAULT_TERRAIN, DEFAULT_URL_OFF);
- this.trustInsecure = Integer.parseInt(getProperty(defaultProps,"insecure", DEFAULT_TRUSTINSECURE)) == 1;
- this.corsEnabled = Integer.parseInt(getProperty(defaultProps,"cors", DEFAULT_CORSENABLED)) == 1;
- }
- private static String getProperty(Properties props,final String key, final String defValue) {
- return getProperty(props, key, defValue, null);
- }
- private static String getProperty(Properties props,final String key, final String defValue, final String valueIfEmpty) {
-
- LOG.debug("try to get property for {} with def {}", key, defValue);
- String value = props.getProperty(key,defValue);
- //try to read env var
- if (value != null && value.contains(ENVVARIABLE)) {
-
- LOG.debug("try to find env var(s) for {}", value);
- final Matcher matcher = ENV_PATTERN.matcher(value);
- String tmp = new String(value);
- while (matcher.find() && matcher.groupCount() > 0) {
- final String mkey = matcher.group(1);
- if (mkey != null) {
- try {
- LOG.debug("match found for v={} and env key={}", tmp, mkey);
- //String env=System.getenv(mkey.substring(2,mkey.length()-1));
- String env = System.getenv(mkey.substring(2, mkey.length() - 1));
- tmp = tmp.replace(mkey, env == null ? "" : env);
- } catch (SecurityException e) {
- LOG.warn("unable to read env {}: {}", value, e);
- }
- }
- }
- value = tmp;
- }
- if((value==null || value.isEmpty()) && valueIfEmpty!=null) {
- value = valueIfEmpty;
- }
- return value;
- }
- 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("tiles=" + DEFAULT_TILES + LR);
- sb.append("topology=" + DEFAULT_TOPOLOGY + LR);
- sb.append("terrain=" + DEFAULT_TERRAIN + 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;
- }
-
- @Override
- public String toString() {
- return "MyProperties [aaiBase=" + aaiBase + ", aaiHeaders=" + aaiHeaders + ", esBase=" + esBase
- + ", trustInsecure=" + trustInsecure + ", corsEnabled=" + corsEnabled + "]";
- }
-
-
-}
diff --git a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/SitedocServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/SitedocServlet.java
deleted file mode 100644
index d96ddb613..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/SitedocServlet.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern;
-
-@HttpWhiteboardServletPattern("/sitedoc/*")
-@HttpWhiteboardServletName("SitedocServlet")
-@Component(service = Servlet.class)
-public class SitedocServlet extends BaseServlet {
-
- private static final long serialVersionUID = 5946205120796162644L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "Topology interface is offline";
- private static final String BASEURL = "/sitedoc";
- private static final String SITEDOC_SUBPATH = "/topology/stadok";
- private static boolean trustAll = false;
-
- public SitedocServlet() {
- super();
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setStatus(200);
- }
-
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
-
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isTopologyOff();
- }
-
- @Override
- protected String getRemoteUrl(String uri) {
-
- if (uri != null && uri.length() > 0) {
- uri = uri.substring(BASEURL.length());
- }
- return MyProperties.getInstance().getSitedocBaseUrl() + SITEDOC_SUBPATH + uri;
- }
-
- @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/TerrainServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TerrainServlet.java
deleted file mode 100644
index 5b5cc8ab9..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TerrainServlet.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern;
-
-@HttpWhiteboardServletPattern("/terrain/*")
-@HttpWhiteboardServletName("TerrainServlet")
-@Component(service = Servlet.class)
-public class TerrainServlet extends BaseServlet {
-
- private static final long serialVersionUID = 5946205120796162644L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "Terrain interface is offline";
- private static final String BASEURL = "/terrain";
- private static boolean trustAll = false;
-
- public TerrainServlet() {
- super();
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setStatus(200);
- }
-
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
-
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isTopologyOff();
- }
-
- @Override
- protected String getRemoteUrl(String uri) {
-
- if (uri != null && uri.length() > 0) {
- uri = uri.substring(BASEURL.length());
- }
- return MyProperties.getInstance().getTerrainBaseUrl() + uri;
- }
-
- @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/TilesServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TilesServlet.java
deleted file mode 100644
index 1978d7c6f..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TilesServlet.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern;
-
-@HttpWhiteboardServletPattern("/tiles/*")
-@HttpWhiteboardServletName("TilesServlet")
-@Component(service = Servlet.class)
-public class TilesServlet extends BaseServlet {
-
- private static final long serialVersionUID = 5946205120796162644L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "Tiles interface is offline";
- private static boolean trustAll = false;
-
- public TilesServlet() {
- super();
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setStatus(200);
- }
-
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
-
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isTilesOff();
- }
-
- @Override
- protected String getRemoteUrl(String uri) {
-
- if (uri.startsWith("/")) {
- uri = uri.substring(1);
- }
- if (uri.startsWith("tiles")) {
- uri = uri.substring("tiles".length());
- }
- if (uri.startsWith("/")) {
- uri = uri.substring(1);
- }
- String base = MyProperties.getInstance().getTilesBaseUrl();
- if (!base.endsWith("/")) {
- base += "/";
- }
-
- return base + uri;
- }
-
- @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/TopologyServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TopologyServlet.java
deleted file mode 100644
index 0350d966b..000000000
--- a/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TopologyServlet.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK.apps.sdnr.wt.apigateway
- * ================================================================================
- * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
- * All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.ccsdk.features.sdnr.wt.apigateway;
-
-import java.io.IOException;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletName;
-import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardServletPattern;
-
-@HttpWhiteboardServletPattern("/topology/*")
-@HttpWhiteboardServletName("TopologyServlet")
-@Component(service = Servlet.class)
-public class TopologyServlet extends BaseServlet {
-
- private static final long serialVersionUID = 5946205120796162644L;
- private static final String OFFLINE_RESPONSE_MESSAGE = "Topology interface is offline";
- private static boolean trustAll = false;
-
- public TopologyServlet() {
- super();
- }
-
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.setStatus(200);
- }
-
- @Override
- protected String getOfflineResponse() {
- return OFFLINE_RESPONSE_MESSAGE;
- }
-
- @Override
- protected boolean isOff() {
- return MyProperties.getInstance().isTopologyOff();
- }
-
- @Override
- protected String getRemoteUrl(String uri) {
-
- if (uri.startsWith("/")) {
- uri = uri.substring(1);
- }
- if (uri.startsWith("topology")) {
- uri = uri.substring("topology".length());
- }
- if (uri.startsWith("/")) {
- uri = uri.substring(1);
- }
- String base = MyProperties.getInstance().getTopologyBaseUrl();
- if (!base.endsWith("/")) {
- base += "/";
- }
-
- return base + uri;
- }
-
- @Override
- protected boolean doTrustAll() {
- return trustAll;
- }
-
- @Override
- protected void trustAll(boolean trust) {
- trustAll = trust;
- }
-}
diff --git a/sdnr/wt/apigateway/provider/src/main/resources/org/opendaylight/blueprint/blueprint.xml b/sdnr/wt/apigateway/provider/src/main/resources/org/opendaylight/blueprint/blueprint.xml
deleted file mode 100644
index a6166b433..000000000
--- a/sdnr/wt/apigateway/provider/src/main/resources/org/opendaylight/blueprint/blueprint.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ ============LICENSE_START=======================================================
- ~ ONAP : ccsdk features
- ~ ================================================================================
- ~ Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- ~ ================================================================================
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- ~ ============LICENSE_END=======================================================
- ~
- -->
-
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <bean id="aaiServlet"
- class="org.onap.ccsdk.features.sdnr.wt.apigateway.AaiServlet">
- </bean>
-
-
- <bean id="esServlet"
- class="org.onap.ccsdk.features.sdnr.wt.apigateway.EsServlet">
- </bean>
-
-
- <bean id="tilesServlet"
- class="org.onap.ccsdk.features.sdnr.wt.apigateway.TilesServlet">
- </bean>
-
-
- <bean id="topologyServlet"
- class="org.onap.ccsdk.features.sdnr.wt.apigateway.TopologyServlet">
- </bean>
-
-
- <bean id="sitedocServlet"
- class="org.onap.ccsdk.features.sdnr.wt.apigateway.SitedocServlet">
- </bean>
-
- <bean id="terrainServlet"
- class="org.onap.ccsdk.features.sdnr.wt.apigateway.TerrainServlet">
- </bean>
-
- <!-- <service interface="javax.servlet.http.HttpServlet" ref="terrainServlet">
- <service-properties>
- <entry key="alias" value="/terrain"/>
- </service-properties>
- </service>-->
-</blueprint>