diff options
author | priyanshu <pagarwal@amdocs.com> | 2018-07-29 19:58:44 +0300 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-07-31 10:03:15 +0000 |
commit | a9fd70f3839766507a58e2eabb38c2d70b7a4330 (patch) | |
tree | 68432977585acaf9b4b1bcfc692308d2837a5278 /catalog-fe | |
parent | e7c8c7299e656e3f7e2d8aca69d0aa9400903e60 (diff) |
SDC-WF API Integration via Proxy
SDC-WF Integration to call WF APIs via SDC Proxy
Integration using extensibility Plugin configuration
Change-Id: I06debeacef6ad681eaae131287df2aaa2f70a4fd
Issue-ID: SDC-1535
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-fe')
-rw-r--r-- | catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java | 50 | ||||
-rw-r--r-- | catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java | 31 |
2 files changed, 70 insertions, 11 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 b726998555..0540fad269 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 @@ -22,11 +22,15 @@ package org.openecomp.sdc.fe.servlets; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import java.net.MalformedURLException; +import java.net.URL; import org.eclipse.jetty.client.api.Response; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.fe.config.Configuration; import org.openecomp.sdc.fe.config.ConfigurationManager; import org.openecomp.sdc.fe.config.FeEcompErrorManager; +import org.openecomp.sdc.fe.config.PluginsConfiguration; +import org.openecomp.sdc.fe.config.PluginsConfiguration.Plugin; import org.openecomp.sdc.fe.impl.MdcData; import org.openecomp.sdc.fe.utils.BeProtocol; import org.slf4j.Logger; @@ -42,20 +46,33 @@ 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 PLUGIN_ID_WORKFLOW = "WORKFLOW"; + private static final Logger log = LoggerFactory.getLogger(FeProxyServlet.class.getName()); private static Cache<String, MdcData> mdcDataCache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build(); @Override protected String rewriteTarget(HttpServletRequest request) { + String originalUrl=""; + String redirectedUrl = ""; + try { logFeRequest(request); - } catch (Exception e) { + + originalUrl = request.getRequestURL().toString(); + redirectedUrl = getModifiedUrl(request); + + } catch(MalformedURLException mue){ + FeEcompErrorManager.getInstance().logFeHttpLoggingError("FE Request"); + log.error("Unexpected FE request processing error :", mue); + } + catch (Exception e) { FeEcompErrorManager.getInstance().logFeHttpLoggingError("FE Request"); log.error("Unexpected FE request logging error :", e); } - String originalUrl = request.getRequestURL().toString(); - String redirectedUrl = getModifiedUrl(request); log.debug("FeProxyServlet Redirecting request from: {} , to: {}", originalUrl, redirectedUrl); @@ -138,7 +155,7 @@ public class FeProxyServlet extends SSLProxyServlet { - private String getModifiedUrl(HttpServletRequest request) { + private String getModifiedUrl(HttpServletRequest request) throws MalformedURLException { Configuration config = getConfiguration(request); if (config == null) { log.error("failed to retrive configuration."); @@ -149,12 +166,12 @@ public class FeProxyServlet extends SSLProxyServlet { String host; String port; if (uri.contains(ONBOARDING_CONTEXT)){ - uri = uri.replace("/sdc1/feProxy"+ONBOARDING_CONTEXT,ONBOARDING_CONTEXT); + uri = uri.replace(SDC1_FE_PROXY+ONBOARDING_CONTEXT,ONBOARDING_CONTEXT); protocol = config.getOnboarding().getProtocolBe(); host = config.getOnboarding().getHostBe(); port = config.getOnboarding().getPortBe().toString(); }else if(uri.contains(DCAED_CONTEXT)){ - uri = uri.replace("/sdc1/feProxy"+DCAED_CONTEXT,DCAED_CONTEXT); + uri = uri.replace(SDC1_FE_PROXY+DCAED_CONTEXT,DCAED_CONTEXT); protocol = config.getBeProtocol(); host = config.getBeHost(); if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) { @@ -163,8 +180,21 @@ public class FeProxyServlet extends SSLProxyServlet { port = config.getBeSslPort().toString(); } } + else if (uri.contains(WORKFLOW_CONTEXT)){ + uri = uri.replace(SDC1_FE_PROXY +WORKFLOW_CONTEXT,WORKFLOW_CONTEXT); + String workflowPluginURL = getPluginConfiguration(request).getPluginsList() + .stream() + .filter(plugin -> plugin.getPluginId().equalsIgnoreCase(PLUGIN_ID_WORKFLOW)) + .map(Plugin::getPluginSourceUrl) + .findFirst().orElse(null); + + java.net.URL workflowURL = new URL(workflowPluginURL); + protocol = workflowURL.getProtocol(); + host = workflowURL.getHost(); + port = String.valueOf(workflowURL.getPort()); + } else{ - uri = uri.replace("/sdc1/feProxy","/sdc2"); + uri = uri.replace(SDC1_FE_PROXY,"/sdc2"); protocol = config.getBeProtocol(); host = config.getBeHost(); if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) { @@ -180,9 +210,9 @@ public class FeProxyServlet extends SSLProxyServlet { } - - - + private PluginsConfiguration getPluginConfiguration(HttpServletRequest request) { + return ((ConfigurationManager) request.getSession().getServletContext().getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).getPluginsConfiguration(); + } private Configuration getConfiguration(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 1e42fec42f..9597928fc0 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 @@ -28,6 +28,7 @@ import org.mockito.Mockito; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.fe.config.Configuration; import org.openecomp.sdc.fe.config.ConfigurationManager; +import org.openecomp.sdc.fe.config.PluginsConfiguration; import org.openecomp.sdc.fe.servlets.FeProxyServlet; import javax.servlet.ServletContext; @@ -37,6 +38,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; @@ -54,9 +56,11 @@ public class FeProxyServletTest { final static ServletContext servletContext = Mockito.mock(ServletContext.class); final static ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class); final static Configuration configuration = Mockito.mock(Configuration.class); - final static Configuration.OnboardingConfig onboardingConfiguration = Mockito.mock(Configuration.OnboardingConfig.class); + final static Configuration.OnboardingConfig onboardingConfiguration = Mockito.mock(Configuration.OnboardingConfig.class); final static Request proxyRequest = Mockito.spy(Request.class); final static HttpFields httpFields = Mockito.mock(HttpFields.class); + private static final PluginsConfiguration pluginsConfiguration = Mockito.mock(PluginsConfiguration.class); + private static final PluginsConfiguration.Plugin plugin = Mockito.mock(PluginsConfiguration.Plugin.class); final static String BE_PROTOCOL = "http"; final static String BE_HOST = "172.20.43.124"; @@ -64,6 +68,9 @@ public class FeProxyServletTest { final static String ONBOARDING_BE_PROTOCOL = "http"; final static String ONBOARDING_BE_HOST = "172.20.43.125"; final static int ONBOARDING_BE_PORT = 8091; + final static String WF_PROTOCOL = "http"; + final static String WF_HOST = "172.20.43.126"; + final static int WF_PORT = 8092; final static String HEADER_1 = "Header1"; final static String HEADER_2 = "Header2"; final static String HEADER_3 = "Header3"; @@ -102,6 +109,13 @@ public class FeProxyServletTest { when(httpFields.containsKey(HEADER_2)).thenReturn(true); when(httpFields.containsKey(HEADER_3)).thenReturn(false); + List<PluginsConfiguration.Plugin> pluginList = new ArrayList<PluginsConfiguration.Plugin>(); + when(plugin.getPluginId()).thenReturn("WORKFLOW"); + when(plugin.getPluginSourceUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT); + pluginList.add(plugin); + when(configurationManager.getPluginsConfiguration()).thenReturn(pluginsConfiguration); + when(pluginsConfiguration.getPluginsList()).thenReturn(pluginList); + } @Test @@ -175,6 +189,21 @@ public class FeProxyServletTest { } + @Test + public void testRewriteURIWithWFAPIRequest() { + when(servletRequest.getRequestURI()).thenReturn("/sdc1/feProxy/wf/workflows"); + String requestResourceUrl = "http://localhost:8080/sdc1/feProxy/wf/workflows"; + String expectedChangedUrl = WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/wf/workflows"; + when(servletRequest.getRequestURL()).thenReturn(new StringBuffer(requestResourceUrl)); + + when(servletRequest.getContextPath()).thenReturn("/sdc1"); + when(servletRequest.getServletPath()).thenReturn("/feProxy/wf/workflows"); + + String rewriteURI = feProxy.rewriteTarget(servletRequest); + + assertEquals(expectedChangedUrl, rewriteURI); + } + /** * class for testing only exposes the protected method. */ |