diff options
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal')
2 files changed, 27 insertions, 22 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java index 8d66807d..f882c927 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java @@ -93,7 +93,7 @@ public class JettyJerseyServer extends JettyServletServer { /** * Container for servlets */ - protected HashMap<String, ServletHolder> servlets = new HashMap<String, ServletHolder>(); + protected HashMap<String, ServletHolder> servlets = new HashMap<>(); /** * Swagger ID @@ -171,14 +171,14 @@ public class JettyJerseyServer extends JettyServletServer { @Override public synchronized void addServletPackage(String servletPath, String restPackage) { - + String servPath = servletPath; if (restPackage == null || restPackage.isEmpty()) throw new IllegalArgumentException("No discoverable REST package provided"); - if (servletPath == null || servletPath.isEmpty()) - servletPath = "/*"; + if (servPath == null || servPath.isEmpty()) + servPath = "/*"; - ServletHolder jerseyServlet = this.getServlet(servletPath); + ServletHolder jerseyServlet = this.getServlet(servPath); String initClasses = jerseyServlet.getInitParameter(JERSEY_INIT_CLASSNAMES_PARAM_NAME); diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java index e0a46173..08c62445 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java @@ -111,37 +111,40 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable * @throws IllegalArgumentException if invalid parameters are passed in */ public JettyServletServer(String name, String host, int port, String contextPath) { - - if (name == null || name.isEmpty()) - name = "http-" + port; + String srvName = name; + String srvHost = host; + String ctxtPath = contextPath; + + if (srvName == null || srvName.isEmpty()) + srvName = "http-" + port; if (port <= 0 && port >= 65535) throw new IllegalArgumentException("Invalid Port provided: " + port); - if (host == null || host.isEmpty()) - host = "localhost"; + if (srvHost == null || srvHost.isEmpty()) + srvHost = "localhost"; - if (contextPath == null || contextPath.isEmpty()) - contextPath = "/"; + if (ctxtPath == null || ctxtPath.isEmpty()) + ctxtPath = "/"; - this.name = name; + this.name = srvName; - this.host = host; + this.host = srvHost; this.port = port; - this.contextPath = contextPath; + this.contextPath = ctxtPath; this.context = new ServletContextHandler(ServletContextHandler.SESSIONS); - this.context.setContextPath(contextPath); + this.context.setContextPath(ctxtPath); this.jettyServer = new Server(); this.jettyServer.setRequestLog(new Slf4jRequestLog()); this.connector = new ServerConnector(this.jettyServer); - this.connector.setName(name); + this.connector.setName(srvName); this.connector.setReuseAddress(true); this.connector.setPort(port); - this.connector.setHost(host); + this.connector.setHost(srvHost); this.jettyServer.addConnector(this.connector); this.jettyServer.setHandler(context); @@ -149,11 +152,13 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable @Override public void setBasicAuthentication(String user, String password, String servletPath) { - if (user == null || user.isEmpty() || password == null || password.isEmpty()) + String srvltPath = servletPath; + + if (user == null || user.isEmpty() || password == null || password.isEmpty()) throw new IllegalArgumentException("Missing user and/or password"); - if (servletPath == null || servletPath.isEmpty()) - servletPath = "/*"; + if (srvltPath == null || srvltPath.isEmpty()) + srvltPath = "/*"; HashLoginService hashLoginService = new HashLoginService(); hashLoginService.putUser(user, @@ -168,7 +173,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); - constraintMapping.setPathSpec(servletPath); + constraintMapping.setPathSpec(srvltPath); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.setAuthenticator(new BasicAuthenticator()); |