diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2018-07-24 17:34:04 +0300 |
---|---|---|
committer | vempo <vitaliy.emporopulo@amdocs.com> | 2018-07-25 11:39:10 +0300 |
commit | a52d50e788792a63e97a9176ab319d53db7a2853 (patch) | |
tree | b1c2222cacf4b8192aea16d1e0315b1f005c5347 /workflow-designer-ui/src/main/java | |
parent | 3c2665debb400aef7f0ed9e235698d2ff9f859db (diff) |
Replaced old implementation at root
Old project files and directories has been moved
under 'deprecated-workflow-designer'. The old project
is not built by the CI anymore, but can be still built manually.
New modules/directories have been moved up and integrated with
the CI system.
Change-Id: I1528c792bcbcce9e50bfc294a1328a20e72c91cf
Issue-ID: SDC-1559
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'workflow-designer-ui/src/main/java')
-rw-r--r-- | workflow-designer-ui/src/main/java/org/onap/workflow/web/TransparentProxy.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/workflow-designer-ui/src/main/java/org/onap/workflow/web/TransparentProxy.java b/workflow-designer-ui/src/main/java/org/onap/workflow/web/TransparentProxy.java new file mode 100644 index 00000000..d7f54306 --- /dev/null +++ b/workflow-designer-ui/src/main/java/org/onap/workflow/web/TransparentProxy.java @@ -0,0 +1,80 @@ +package org.onap.workflow.web; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import org.eclipse.jetty.proxy.ProxyServlet; + +/** + * <p>A naive implementation of transparent proxy based on + * <a href="https://www.eclipse.org/jetty/documentation/9.4.x/proxy-servlet.html">Jetty proxy servlet</a>. + * The only difference is that the <code>proxyTo</code> configuration parameter is taken from a JVM argument (and can + * be therefore injected via an environment variable), instead of an <code>init-param</code> in <i>web.xml</i>.</p> + * <p>Example: <code>java -DproxyTo=http://172.17.0.9:8080 -jar $JETTY_HOME/start.jar</code></p> + * <p>If you get a <i>502 Bad Gateway</i> error:</p> + * <ul> + * <ol> + * Make sure that Jetty 'proxy' module + * <a href="https://www.eclipse.org/jetty/documentation/9.4.x/startup-modules.html">is not enabled</a>. + * </ol> + * <ol> + * Check the value of <code>proxyTo</code>. Make sure it does not redirect to the proxy server itself. + * </ol> + * <ol> + * Make sure there is no proxy (e.g. in a corporate environment) between the servlet and <code>proxyTo</code>. + * </ol> + * </ul> + * + * @author evitaliy + * @since 16 Jul 2018 + */ +public class TransparentProxy extends ProxyServlet.Transparent { + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(new ServletConfigWrapper(config)); + } + + private class ServletConfigWrapper implements ServletConfig { + + private static final String PROXY_TO = "proxyTo"; + + private final String proxyTo; + private final ServletConfig config; + + ServletConfigWrapper(ServletConfig config) throws ServletException { + + this.proxyTo = System.getProperty(PROXY_TO); + if (this.proxyTo == null) { + throw new ServletException("-D" + PROXY_TO + " must be specified"); + } + + this.config = config; + } + + @Override + public String getServletName() { + return config.getServletName(); + } + + @Override + public ServletContext getServletContext() { + return config.getServletContext(); + } + + @Override + public String getInitParameter(String s) { + return PROXY_TO.equals(s) ? this.proxyTo : config.getInitParameter(s); + } + + @Override + public Enumeration<String> getInitParameterNames() { + ArrayList<String> params = Collections.list(config.getInitParameterNames()); + params.add(PROXY_TO); + return Collections.enumeration(params); + } + } +} |