aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-fe/src
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2019-12-17 10:23:13 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-12-18 13:26:17 +0000
commitf13ad6348df59f8883c9a3f86a7ef81ee4cb089c (patch)
tree52cca793d78d2d8f94a39f71cf6ea7053a0a5bd3 /catalog-fe/src
parent0ce779a2e1d9272ea3a0680b51ac032d6da8098a (diff)
Revert "Add Option to proxy to plugins"
This reverts commit ee4c4d72 Issue-ID: SDC-2648 Change-Id: I1f6cba80d3fb803530573c75f2fc54ca207e768a Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'catalog-fe/src')
-rw-r--r--catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java116
-rw-r--r--catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java25
2 files changed, 39 insertions, 102 deletions
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java
index 1d7643fe40..1c7b174c57 100644
--- a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java
+++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java
@@ -46,8 +46,9 @@ public class FeProxyServlet extends SSLProxyServlet {
private static final String URL = "%s://%s%s%s";
private static final String ONBOARDING_CONTEXT = "/onboarding-api";
private static final String DCAED_CONTEXT = "/dcae-api";
+ private static final String WORKFLOW_CONTEXT = "/wf";
private static final String SDC1_FE_PROXY = "/sdc1/feProxy";
- private static final String SDC1_PLUGIN_REDIRECT = SDC1_FE_PROXY + "/plugin";
+ private static final String PLUGIN_ID_WORKFLOW = "WORKFLOW";
private static final Logger LOGGER = Logger.getLogger(FeProxyServlet.class);
private static final int EXPIRE_DURATION = 10;
@@ -153,24 +154,6 @@ public class FeProxyServlet extends SSLProxyServlet {
}
- /****
- * scan all the plugins from the configuration against the URL and the redicert path
- * @param request
- * @return
- */
- private Plugin getPluginProxyForRequest(HttpServletRequest request) {
- return getPluginConfiguration(request).getPluginsList()
- .stream()
- .filter(plugin -> {
- if (plugin.getPluginProxyRedirectPath() != null && !plugin.getPluginProxyRedirectPath().isEmpty()) {
- return request.getRequestURI().contains(SDC1_PLUGIN_REDIRECT + plugin.getPluginProxyRedirectPath());
- } else {
- return false;
- }
- })
- .findFirst().orElse(null);
- }
-
private String getModifiedUrl(HttpServletRequest request) throws MalformedURLException {
Configuration config = getConfiguration(request);
if (config == null) {
@@ -178,77 +161,50 @@ public class FeProxyServlet extends SSLProxyServlet {
throw new RuntimeException("failed to read FE configuration");
}
String uri = request.getRequestURI();
-
- // the modify logic is as follows:
- // - proxy ONBOARDING to the onboarding context. this is not a plugin and hardcoded
- // - proxy DCAE to the correct context. also - not a plugin but hardcoded
- // - proxy to the plugin according to configuration if the path is found in the plugin patterns
- // - proxy to the catalog backend if no other proxy was found
-
+ String protocol;
+ String host;
+ String port;
if (uri.contains(ONBOARDING_CONTEXT)) {
uri = uri.replace(SDC1_FE_PROXY + ONBOARDING_CONTEXT, ONBOARDING_CONTEXT);
- return getModifiedUrlString(
- request,
- uri,
- config.getOnboarding().getHostBe(),
- config.getOnboarding().getPortBe().toString(),
- config.getOnboarding().getProtocolBe());
- }
- if (uri.contains(DCAED_CONTEXT)) {
+ protocol = config.getOnboarding().getProtocolBe();
+ host = config.getOnboarding().getHostBe();
+ port = config.getOnboarding().getPortBe().toString();
+ } else if (uri.contains(DCAED_CONTEXT)) {
uri = uri.replace(SDC1_FE_PROXY + DCAED_CONTEXT, DCAED_CONTEXT);
- return getModifiedUrlString(
- request,
- uri,
- config.getBeHost(),
- getCatalogBePort(config),
- config.getBeProtocol());
- }
-
- if (uri.contains(SDC1_PLUGIN_REDIRECT)) {
- Plugin proxyPlugin = getPluginProxyForRequest(request);
- if (proxyPlugin != null) {
- String proxyUrlStr = (proxyPlugin.getPluginFeProxyUrl() != null) ? proxyPlugin.getPluginFeProxyUrl() : proxyPlugin.getPluginSourceUrl();
- URL proxyUrl = new URL(proxyUrlStr);
- uri = uri.replace(SDC1_PLUGIN_REDIRECT + proxyPlugin.getPluginProxyRedirectPath(), proxyUrl.getPath());
- return getModifiedUrlString(request, uri, proxyUrl);
+ protocol = config.getBeProtocol();
+ host = config.getBeHost();
+ if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) {
+ port = config.getBeHttpPort().toString();
+ } else {
+ port = config.getBeSslPort().toString();
}
- }
-
- Plugin proxyPlugin = getPluginProxyForRequest(request);
- if (proxyPlugin != null) {
- String proxyUrlStr = (proxyPlugin.getPluginFeProxyUrl() != null) ? proxyPlugin.getPluginFeProxyUrl() : proxyPlugin.getPluginSourceUrl();
- URL proxyUrl = new URL(proxyUrlStr);
- uri = uri.replace(SDC1_FE_PROXY + proxyPlugin.getPluginProxyRedirectPath(), proxyUrl.getPath());
- return getModifiedUrlString(request, uri, proxyUrl);
- }
-
- uri = uri.replace(SDC1_FE_PROXY, "/sdc2");
- return getModifiedUrlString(
- request,
- uri,
- config.getBeHost(),
- getCatalogBePort(config),
- config.getBeProtocol());
- }
-
-
- private String getCatalogBePort(Configuration config) {
- if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) {
- return config.getBeHttpPort().toString();
+ } else if (uri.contains(WORKFLOW_CONTEXT)) {
+ String workflowPluginURL = getPluginConfiguration(request).getPluginsList()
+ .stream()
+ .filter(plugin -> plugin.getPluginId().equalsIgnoreCase(PLUGIN_ID_WORKFLOW))
+ .map(Plugin::getPluginDiscoveryUrl)
+ .findFirst().orElse(null);
+
+ java.net.URL workflowURL = new URL(workflowPluginURL);
+ protocol = workflowURL.getProtocol();
+ host = workflowURL.getHost();
+ port = String.valueOf(workflowURL.getPort());
+ uri = uri.replace(SDC1_FE_PROXY + WORKFLOW_CONTEXT, workflowURL.getPath() + WORKFLOW_CONTEXT);
} else {
- return config.getBeSslPort().toString();
+ uri = uri.replace(SDC1_FE_PROXY, "/sdc2");
+ protocol = config.getBeProtocol();
+ host = config.getBeHost();
+ if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) {
+ port = config.getBeHttpPort().toString();
+ } else {
+ port = config.getBeSslPort().toString();
+ }
}
- }
- private String getModifiedUrlString(HttpServletRequest request, String uri, URL url) {
- String queryString = getQueryString(request);
- return String.format(URL, url.getProtocol(), url.getAuthority(), uri, queryString);
- }
-
- private String getModifiedUrlString(HttpServletRequest request, String uri, String host, String port, String protocol) {
String authority = getAuthority(host, port);
String queryString = getQueryString(request);
return String.format(URL, protocol, authority, uri, queryString);
+
}
private PluginsConfiguration getPluginConfiguration(HttpServletRequest request) {
diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java
index 81e939b929..4915936b1d 100644
--- a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java
+++ b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java
@@ -113,12 +113,7 @@ public class FeProxyServletTest {
when(plugin.getPluginId()).thenReturn("WORKFLOW");
when(plugin.getPluginSourceUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT);
when(plugin.getPluginDiscoveryUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows");
- when(plugin.getPluginFeProxyUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows/wf/");
- when(plugin.getPluginProxyRedirectPath()).thenReturn("/wf/");
pluginList.add(plugin);
- PluginsConfiguration.Plugin noConfigPlugin = new PluginsConfiguration.Plugin();
- noConfigPlugin.setPluginId("NO_CONFIG");
- pluginList.add(noConfigPlugin);
when(configurationManager.getPluginsConfiguration()).thenReturn(pluginsConfiguration);
when(pluginsConfiguration.getPluginsList()).thenReturn(pluginList);
@@ -187,31 +182,17 @@ public class FeProxyServletTest {
@Test
public void testRewriteURIWithWFAPIRequest() {
- when(servletRequest.getRequestURI()).thenReturn("/sdc1/feProxy/plugin/wf/workflows");
- String requestResourceUrl = "http://localhost:8080/sdc1/feProxy/plugin/wf/workflows";
- String expectedChangedUrl = WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows/wf/workflows";
- when(servletRequest.getRequestURL()).thenReturn(new StringBuffer(requestResourceUrl));
-
- when(servletRequest.getContextPath()).thenReturn("/sdc1");
- when(servletRequest.getServletPath()).thenReturn("/feProxy/plugin/wf/workflows");
-
- String rewriteURI = feProxy.rewriteTarget(servletRequest);
-
- assertEquals(expectedChangedUrl, rewriteURI);
-
- // now test in case it did not go through the plugin
when(servletRequest.getRequestURI()).thenReturn("/sdc1/feProxy/wf/workflows");
- requestResourceUrl = "http://localhost:8080/sdc1/feProxy/wf/workflows";
- expectedChangedUrl = BE_PROTOCOL + "://" + BE_HOST + ":" + BE_PORT + "/sdc2/wf/workflows";
+ String requestResourceUrl = "http://localhost:8080/sdc1/feProxy/wf/workflows";
+ String expectedChangedUrl = WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows/wf/workflows";
when(servletRequest.getRequestURL()).thenReturn(new StringBuffer(requestResourceUrl));
when(servletRequest.getContextPath()).thenReturn("/sdc1");
when(servletRequest.getServletPath()).thenReturn("/feProxy/wf/workflows");
- rewriteURI = feProxy.rewriteTarget(servletRequest);
+ String rewriteURI = feProxy.rewriteTarget(servletRequest);
assertEquals(expectedChangedUrl, rewriteURI);
-
}
/**