diff options
author | vasraz <vasyl.razinkov@est.tech> | 2023-05-05 11:57:56 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2023-05-08 13:11:02 +0000 |
commit | a2feaf9b65cbba66181fb560b5815a62427d65cc (patch) | |
tree | be49cc57d447f7bb94e717e1ee970d4b095e1473 /catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java | |
parent | af3fdfce91aeea1804c76a8571c102b78dde3794 (diff) |
Support SIP TLS
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Icbadd04cfa87302491c59f2e4a39ef92aaafcaa3
Issue-ID: SDC-4483
Diffstat (limited to 'catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java')
-rw-r--r-- | catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java index 891bc4ae34..812be7f8ea 100644 --- a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java +++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/SSLProxyServlet.java @@ -19,10 +19,12 @@ */ package org.openecomp.sdc.fe.servlets; -import javax.servlet.ServletException; import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.dynamic.HttpClientTransportDynamic; +import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.proxy.ProxyServlet; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.onap.config.api.JettySSLUtils; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.fe.config.Configuration; import org.openecomp.sdc.fe.config.ConfigurationManager; @@ -30,15 +32,17 @@ import org.openecomp.sdc.fe.utils.BeProtocol; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.servlet.ServletException; + public abstract class SSLProxyServlet extends ProxyServlet { private static final long serialVersionUID = 1L; - private static final Logger log = LoggerFactory.getLogger(SSLProxyServlet.class); + private static final Logger LOGGER = LoggerFactory.getLogger(SSLProxyServlet.class); @Override protected HttpClient createHttpClient() throws ServletException { Configuration config = ((ConfigurationManager) getServletConfig().getServletContext().getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)) - .getConfiguration(); + .getConfiguration(); boolean isSecureClient = !config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName()); HttpClient client = (isSecureClient) ? getSecureHttpClient() : super.createHttpClient(); int requestTimeout = config.getRequestTimeout() * 1000; @@ -47,22 +51,30 @@ public abstract class SSLProxyServlet extends ProxyServlet { } setTimeout(requestTimeout); client.setIdleTimeout(requestTimeout); - client.setStopTimeout(requestTimeout); return client; } private HttpClient getSecureHttpClient() throws ServletException { - // Instantiate HttpClient with the SslContextFactory - final var httpClient = new HttpClient(new SslContextFactory.Client(true)); + final SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(true); + try { + sslContextFactory.setSslContext(JettySSLUtils.getSslContext()); + } catch (Exception e) { + LOGGER.error("Exception thrown while getting SslContext", e); + throw new ServletException(e); + } + final ClientConnector clientConnector = new ClientConnector(); + clientConnector.setSslContextFactory(sslContextFactory); + final HttpClient httpClient = new HttpClient(new HttpClientTransportDynamic(clientConnector)); // Configure HttpClient, for example: httpClient.setFollowRedirects(false); // Start HttpClient try { httpClient.start(); } catch (Exception x) { - log.error("Exception thrown while starting httpClient", x); + LOGGER.error("Exception thrown while starting httpClient", x); throw new ServletException(x); } return httpClient; } + } |