2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.fe.servlets;
23 import org.eclipse.jetty.client.HttpClient;
24 import org.eclipse.jetty.proxy.ProxyServlet;
25 import org.eclipse.jetty.util.ssl.SslContextFactory;
26 import org.openecomp.sdc.common.api.Constants;
27 import org.openecomp.sdc.fe.config.Configuration;
28 import org.openecomp.sdc.fe.config.ConfigurationManager;
29 import org.openecomp.sdc.fe.utils.BeProtocol;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import javax.servlet.ServletException;
35 public abstract class SSLProxyServlet extends ProxyServlet {
37 private static final long serialVersionUID = 1L;
38 private static final int TIMEOUT = 600000;
39 private static Logger log = LoggerFactory.getLogger(SSLProxyServlet.class.getName());
42 protected HttpClient createHttpClient() throws ServletException {
43 Configuration config = ((ConfigurationManager) getServletConfig().getServletContext()
44 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).getConfiguration();
45 boolean isSecureClient = !config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName());
46 HttpClient client = (isSecureClient) ? getSecureHttpClient() : super.createHttpClient();
48 client.setIdleTimeout(TIMEOUT);
49 client.setStopTimeout(TIMEOUT);
54 private HttpClient getSecureHttpClient() throws ServletException {
55 // Instantiate and configure the SslContextFactory
56 SslContextFactory sslContextFactory = new SslContextFactory(true);
58 // Instantiate HttpClient with the SslContextFactory
59 HttpClient httpClient = new HttpClient(sslContextFactory);
61 // Configure HttpClient, for example:
62 httpClient.setFollowRedirects(false);
67 } catch (Exception x) {
68 log.error("Exception thrown while starting httpClient {}", x);
69 throw new ServletException(x);