aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-08-01 16:18:25 -0500
committerJorge Hernandez <jh1730@att.com>2018-08-03 14:14:05 -0500
commit030aee91fd3aec55a8940770181825f9f04a43aa (patch)
tree122cb45734ef2a4b219ebc83a111d9101087facd /policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
parent6d662cb19aa858b743ab7e01d02a2a173abebcad (diff)
generic jetty https server support
jetty https support in constructor, or by using ".https" when creating an http server service. Change-Id: I94e8e3e4b93eb6b194657028c740b6781316c7da Issue-ID: POLICY-940 Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java50
1 files changed, 40 insertions, 10 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
index f09893b2..c7d2b1bf 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactory.java
@@ -37,9 +37,10 @@ import org.slf4j.LoggerFactory;
public interface HttpServletServerFactory {
/**
- * builds an http server with support for servlets
+ * builds an http or https server with support for servlets
*
* @param name name
+ * @param https use secured http over tls connection
* @param host binding host
* @param port port
* @param contextPath server base path
@@ -48,17 +49,32 @@ public interface HttpServletServerFactory {
* @return http server
* @throws IllegalArgumentException when invalid parameters are provided
*/
- public HttpServletServer build(String name, String host, int port, String contextPath, boolean swagger,
+ HttpServletServer build(String name, boolean https, String host, int port, String contextPath, boolean swagger,
boolean managed);
/**
+ * builds an http server with support for servlets
+ *
+ * @param name name
+ * @param host binding host
+ * @param port port
+ * @param contextPath server base path
+ * @param swagger enable swagger documentation
+ * @param managed is it managed by infrastructure
+ * @return http server
+ * @throws IllegalArgumentException when invalid parameters are provided
+ */
+ HttpServletServer build(String name, String host, int port, String contextPath, boolean swagger,
+ boolean managed);
+
+ /**
* list of http servers per properties
*
* @param properties properties based configuration
* @return list of http servers
* @throws IllegalArgumentException when invalid parameters are provided
*/
- public List<HttpServletServer> build(Properties properties);
+ List<HttpServletServer> build(Properties properties);
/**
* gets a server based on the port
@@ -66,26 +82,26 @@ public interface HttpServletServerFactory {
* @param port port
* @return http server
*/
- public HttpServletServer get(int port);
+ HttpServletServer get(int port);
/**
* provides an inventory of servers
*
* @return inventory of servers
*/
- public List<HttpServletServer> inventory();
+ List<HttpServletServer> inventory();
/**
* destroys server bound to a port
*
* @param port
*/
- public void destroy(int port);
+ void destroy(int port);
/**
* destroys the factory and therefore all servers
*/
- public void destroy();
+ void destroy();
}
@@ -107,14 +123,14 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
protected HashMap<Integer, HttpServletServer> servers = new HashMap<>();
@Override
- public synchronized HttpServletServer build(String name, String host, int port, String contextPath, boolean swagger,
+ public synchronized HttpServletServer build(String name, boolean https, String host, int port, String contextPath, boolean swagger,
boolean managed) {
if (servers.containsKey(port)) {
return servers.get(port);
}
- JettyJerseyServer server = new JettyJerseyServer(name, host, port, contextPath, swagger);
+ JettyJerseyServer server = new JettyJerseyServer(name, https, host, port, contextPath, swagger);
if (managed) {
servers.put(port, server);
}
@@ -123,6 +139,13 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
@Override
+ public synchronized HttpServletServer build(String name, String host, int port, String contextPath,
+ boolean swagger, boolean managed) {
+ return build(name, false, host, port, contextPath, swagger, managed);
+ }
+
+
+ @Override
public synchronized List<HttpServletServer> build(Properties properties) {
ArrayList<HttpServletServer> serviceList = new ArrayList<>();
@@ -192,7 +215,14 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
swagger = Boolean.parseBoolean(swaggerString);
}
- HttpServletServer service = build(serviceName, hostName, servicePort, contextUriPath, swagger, managed);
+ String httpsString = properties.getProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
+ + serviceName + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX);
+ boolean https = false;
+ if (httpsString != null && !httpsString.isEmpty()) {
+ https = Boolean.parseBoolean(httpsString);
+ }
+
+ HttpServletServer service = build(serviceName, https, hostName, servicePort, contextUriPath, swagger, managed);
if (userName != null && !userName.isEmpty() && password != null && !password.isEmpty()) {
service.setBasicAuthentication(userName, password, authUriPath);
}