summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/apigateway/provider/src
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/apigateway/provider/src')
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/MyProperties.java79
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TilesServlet.java82
-rw-r--r--sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TopologyServlet.java82
-rw-r--r--sdnr/wt/apigateway/provider/src/main/resources/org/opendaylight/blueprint/blueprint.xml20
-rw-r--r--sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java36
5 files changed, 264 insertions, 35 deletions
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 d644c63a3..c518cff81 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
@@ -28,6 +28,8 @@ 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;
@@ -41,12 +43,20 @@ public class MyProperties {
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 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 boolean trustInsecure;
@@ -60,6 +70,14 @@ public class MyProperties {
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;
}
@@ -68,6 +86,14 @@ public class MyProperties {
return this.esBase;
}
+ public String getTilesBaseUrl() {
+ return this.tilesBase;
+ }
+
+ public String getTopologyBaseUrl() {
+ return this.topologyBase;
+ }
+
public Map<String, String> getAAIHeaders() {
return this.aaiHeaders;
}
@@ -98,7 +124,7 @@ public class MyProperties {
}
private MyProperties(File file) throws IOException, NumberFormatException {
- this.aaiBase = "off";
+ this.aaiBase = DEFAULT_AAI;
this.trustInsecure = false;
if (!file.exists()) {
this.writeDefaults(file);
@@ -112,13 +138,47 @@ public class MyProperties {
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;
+ 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.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 == "") && valueIfEmpty!=null) {
+ value = valueIfEmpty;
+ }
+ return value;
}
-
private static Map<String, String> _parseHeadersMap(String s) {
Map<String, String> r = new HashMap<>();
try {
@@ -145,6 +205,8 @@ public class MyProperties {
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("insecure=" + DEFAULT_TRUSTINSECURE + LR);
sb.append("cors=" + DEFAULT_CORSENABLED);
try {
@@ -166,4 +228,5 @@ public class MyProperties {
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/TilesServlet.java b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TilesServlet.java
new file mode 100644
index 000000000..a29717a73
--- /dev/null
+++ b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TilesServlet.java
@@ -0,0 +1,82 @@
+/*
+ * ============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 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
new file mode 100644
index 000000000..1a8187640
--- /dev/null
+++ b/sdnr/wt/apigateway/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/apigateway/TopologyServlet.java
@@ -0,0 +1,82 @@
+/*
+ * ============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 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
index 256a9cfa3..cd325e4dc 100644
--- 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
@@ -42,4 +42,24 @@
</service-properties>
</service>
+ <bean id="tilesServlet"
+ class="org.onap.ccsdk.features.sdnr.wt.apigateway.TilesServlet">
+ </bean>
+
+ <service interface="javax.servlet.http.HttpServlet" ref="tilesServlet">
+ <service-properties>
+ <entry key="alias" value="/tiles"/>
+ </service-properties>
+ </service>
+
+ <bean id="topologyServlet"
+ class="org.onap.ccsdk.features.sdnr.wt.apigateway.TopologyServlet">
+ </bean>
+
+ <service interface="javax.servlet.http.HttpServlet" ref="topologyServlet">
+ <service-properties>
+ <entry key="alias" value="/topology"/>
+ </service-properties>
+ </service>
+
</blueprint>
diff --git a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java
index b12281e32..4048012bb 100644
--- a/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java
+++ b/sdnr/wt/apigateway/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/apigateway/test/helper/HelpServletBase.java
@@ -26,28 +26,23 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.StringWriter;
import java.net.InetSocketAddress;
import java.util.Enumeration;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.junit.After;
import org.junit.Before;
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-import com.sun.net.httpserver.HttpServer;
+import org.onap.ccsdk.features.sdnr.wt.common.test.ServletInputStreamFromByteArrayInputStream;
+import org.onap.ccsdk.features.sdnr.wt.common.test.ServletOutputStreamToStringWriter;
@SuppressWarnings("restriction")
public class HelpServletBase {
@@ -89,21 +84,8 @@ public class HelpServletBase {
HttpServletRequest mockRequest = mock(HttpServletRequest.class);
HttpServletResponse mockResponse = mock(HttpServletResponse.class);
- StringWriter out = new StringWriter();
- ServletOutputStream printOut = new ServletOutputStream() {
-
- @Override
- public void write(int arg0) throws IOException {
- out.write(arg0);
- }
- };
- ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes());
- ServletInputStream inputStream = new ServletInputStream() {
- @Override
- public int read() throws IOException {
- return bis.read();
- }
- };
+ ServletOutputStreamToStringWriter printOut = new ServletOutputStreamToStringWriter();
+ ServletInputStreamFromByteArrayInputStream inputStream = new ServletInputStreamFromByteArrayInputStream(data.getBytes());
Vector<String> headers = new Vector<String>();
headers.addElement("Accept");
headers.add("User-Agent");
@@ -134,9 +116,9 @@ public class HelpServletBase {
verify(mockResponse).setStatus(200);
if (exact)
- assertEquals(expectedResponse, out.toString());
+ assertEquals(expectedResponse, printOut.getStringWriter().toString());
else
- assertTrue("response not for method " + method + "correct", out.toString().contains(expectedResponse));
+ assertTrue("response not for method " + method + "correct", printOut.getStringWriter().toString().contains(expectedResponse));
// currently unable to check extra headers
if (headersToCheck != null) {