From 943a47187dbb1393d720b2fdf0019d48270edb4d Mon Sep 17 00:00:00 2001 From: PawelSzalapski Date: Thu, 21 Jun 2018 12:12:30 +0200 Subject: Remove dead code from VESCollector Many things there are unused or have inproper modifiers, spelling etc. I run static analysis tool (Intellij code inspect) and clear those things up. It will be easier to maintain now. No actual behavior changes were done. Issue-ID: DCAEGEN2-526 Signed-off-by: PawelSzalapski Change-Id: I1a4ad0c896bd32165cba654344ffc5245648c615 --- .../onap/dcae/restapi/RestfulCollectorServlet.java | 66 +++++++--------------- 1 file changed, 21 insertions(+), 45 deletions(-) (limited to 'src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java') diff --git a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java index d664b137..0d9df155 100644 --- a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java +++ b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java @@ -34,8 +34,6 @@ import org.slf4j.LoggerFactory; import com.att.nsa.apiServer.CommonServlet; import com.att.nsa.configs.ConfigDbException; -import com.att.nsa.drumlin.service.framework.DrumlinErrorHandler; -import com.att.nsa.drumlin.service.framework.context.DrumlinRequestContext; import com.att.nsa.drumlin.service.framework.routing.DrumlinRequestRouter; import com.att.nsa.drumlin.service.framework.routing.playish.DrumlinPlayishRoutingFileSource; import com.att.nsa.drumlin.service.standards.HttpStatusCodes; @@ -50,12 +48,15 @@ import com.att.nsa.security.db.simple.NsaSimpleApiKey; public class RestfulCollectorServlet extends CommonServlet { - public static String authlist; + private static final long serialVersionUID = 1L; + private static final Logger log = LoggerFactory.getLogger ( RestfulCollectorServlet.class ); + + private static String authCredentialsList; public RestfulCollectorServlet ( rrNvReadable settings ) throws loadException, missingReqdSetting { super ( settings, "collector", false ); - authlist = settings.getString(CommonStartup.KSETTING_AUTHLIST,null); + authCredentialsList = settings.getString(CommonStartup.KSETTING_AUTHLIST, null); } @@ -69,8 +70,7 @@ public class RestfulCollectorServlet extends CommonServlet { super.servletSetup (); - try - { + try { // the base class provides a bunch of things like API authentication and ECOMP compliant // logging. The Restful Collector likely doesn't need API authentication, so for now, // we init the base class services with an in-memory (and empty!) config DB. @@ -82,14 +82,8 @@ public class RestfulCollectorServlet extends CommonServlet final DrumlinRequestRouter drr = getRequestRouter (); // you can tell the request router what to do when a particular kind of exception is thrown. - drr.setHandlerForException( IllegalArgumentException.class, new DrumlinErrorHandler() - { - @Override - public void handle ( DrumlinRequestContext ctx, Throwable cause ) - { - sendJsonReply ( ctx, HttpStatusCodes.k400_badRequest, cause.getMessage() ); - } - }); + drr.setHandlerForException(IllegalArgumentException.class, + (ctx, cause) -> sendJsonReply (ctx, HttpStatusCodes.k400_badRequest, cause.getMessage() )); // load the routes from the config file final URL routes = findStream ( "routes.conf" ); @@ -99,52 +93,34 @@ public class RestfulCollectorServlet extends CommonServlet if (CommonStartup.authflag > 0) { NsaAuthenticator NsaAuth; - NsaAuth = AuthlistHandler(authlist); + NsaAuth = createAuthenticator(authCredentialsList); this.getSecurityManager().addAuthenticator(NsaAuth); } log.info ( "Restful Collector Servlet is up." ); } - catch ( SecurityException e ) - { - throw new ServletException ( e ); - } - catch ( IOException e ) - { - throw new ServletException ( e ); - } - catch ( ConfigDbException e ) - { + catch ( SecurityException | IOException | ConfigDbException e ) { throw new ServletException ( e ); } } - public NsaAuthenticator AuthlistHandler (String authlist) - { - NsaAuthenticator NsaAuth = new SimpleAuthenticator (); - if (authlist != null) - { - String authpair[] = authlist.split("\\|"); - for (String pair: authpair) { + public NsaAuthenticator createAuthenticator(String authCredentials) { + NsaAuthenticator authenticator = new SimpleAuthenticator(); + if (authCredentials != null) { + String authpair[] = authCredentials.split("\\|"); + for (String pair : authpair) { String lineid[] = pair.split(","); - String listauthid = lineid[0]; - String listauthpwd = new String(Base64.decodeBase64(lineid[1])); - ((SimpleAuthenticator) NsaAuth).add(listauthid,listauthpwd); + String listauthid = lineid[0]; + String listauthpwd = new String(Base64.decodeBase64(lineid[1])); + ((SimpleAuthenticator) authenticator).add(listauthid, listauthpwd); } + } else { + ((SimpleAuthenticator) authenticator).add("admin", "collectorpasscode"); } - else - { - //add a default test account - ((SimpleAuthenticator) NsaAuth).add("admin","collectorpasscode"); - } - return NsaAuth; - + return authenticator; } - - private static final long serialVersionUID = 1L; - private static final Logger log = LoggerFactory.getLogger ( RestfulCollectorServlet.class ); } -- cgit 1.2.3-korg