diff options
author | Bharat saraswal <bharat.saraswal@huawei.com> | 2017-09-17 14:15:01 +0530 |
---|---|---|
committer | Bharat saraswal <bharat.saraswal@huawei.com> | 2017-09-17 09:40:50 +0000 |
commit | 4e9e25c0bd99bd686648d7dd1dc64ad98c49f5b4 (patch) | |
tree | d335b78d2fbce53a05109694a6609abdcd578ef7 /src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java | |
parent | a38b4cf499b4461d2dcf747837bd346b1b2c71a5 (diff) |
Fixing sonar issues.
removed redundant code.
Issue-Id:DCAEGEN2-92
Change-Id: I98a64dcfb1d7d40617324ee0fc6d1a70e368cff9
Signed-off-by: Bharat saraswal <bharat.saraswal@huawei.com>
Diffstat (limited to 'src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java')
-rw-r--r-- | src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java | 202 |
1 files changed, 90 insertions, 112 deletions
diff --git a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java index bd9a223e..babb184b 100644 --- a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java +++ b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java @@ -21,17 +21,6 @@ package org.onap.dcae.restapi; -import java.io.IOException; -import java.net.URL; - -import javax.servlet.ServletException; - -import org.apache.tomcat.util.codec.binary.Base64; -import org.onap.dcae.commonFunction.CommonStartup; -import org.onap.dcae.commonFunction.VESLogger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.att.nsa.apiServer.CommonServlet; import com.att.nsa.configs.ConfigDbException; import com.att.nsa.drumlin.service.framework.DrumlinErrorHandler; @@ -43,108 +32,97 @@ import com.att.nsa.drumlin.till.nv.rrNvReadable; import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException; import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting; import com.att.nsa.security.NsaAuthenticator; - import com.att.nsa.security.authenticators.SimpleAuthenticator; import com.att.nsa.security.db.simple.NsaSimpleApiKey; +import org.apache.tomcat.util.codec.binary.Base64; +import org.onap.dcae.commonFunction.CommonStartup; +import org.onap.dcae.commonFunction.VESLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URL; +import javax.servlet.ServletException; -public class RestfulCollectorServlet extends CommonServlet -{ - String authid = null; - String authpwd = null; - String authlist = null; - - public RestfulCollectorServlet ( rrNvReadable settings ) throws loadException, missingReqdSetting - { - super ( settings, "collector", false ); - authid = settings.getString(CommonStartup.kSetting_authid,null); - if (authid != null) - { - String authpwdtemp = settings.getString(CommonStartup.kSetting_authpwd,null); - authpwd = new String(Base64.decodeBase64(authpwdtemp)); - } - authlist = settings.getString(CommonStartup.kSetting_authlist,null); - } - - - /** - * This is called once at server start. Use it to init any shared objects and setup the route mapping. - */ - @Override - protected void servletSetup () throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException - { - super.servletSetup (); - - 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. - commonServletSetup ( ConfigDbType.MEMORY ); - - VESLogger.setUpEcompLogging(); - - // setup the servlet routing and error handling - 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() ); - } - }); - - // load the routes from the config file - final URL routes = findStream ( "routes.conf" ); - if ( routes == null ) throw new rrNvReadable.missingReqdSetting ( "No routing configuration." ); - final DrumlinPlayishRoutingFileSource drs = new DrumlinPlayishRoutingFileSource ( routes ); - drr.addRouteSource ( drs ); - - if (CommonStartup.authflag > 0) { - NsaAuthenticator<NsaSimpleApiKey> NsaAuth = new SimpleAuthenticator (); - if (authlist != null) - { - String authpair[] = authlist.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); - } - - } - else if (authid != null) - { - ((SimpleAuthenticator) NsaAuth).add(authid,authpwd); - } - else - { - //add a default test account - ((SimpleAuthenticator) NsaAuth).add("admin","collectorpasscode"); - } - 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 ) - { - throw new ServletException ( e ); - } - } - - - - private static final long serialVersionUID = 1L; - private static final Logger log = LoggerFactory.getLogger ( RestfulCollectorServlet.class ); +public class RestfulCollectorServlet extends CommonServlet { + + String authid; + String authpwd; + String authlist; + + public RestfulCollectorServlet(rrNvReadable settings) throws loadException, missingReqdSetting { + super(settings, "collector", false); + authid = settings.getString(CommonStartup.kSetting_authid, null); + if (authid != null) { + String authpwdtemp = settings.getString(CommonStartup.kSetting_authpwd, null); + authpwd = new String(Base64.decodeBase64(authpwdtemp)); + } + authlist = settings.getString(CommonStartup.kSetting_authlist, null); + } + + + /** + * This is called once at server start. Use it to init any shared objects and setup the route mapping. + */ + @Override + protected void servletSetup() + throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException { + super.servletSetup(); + + 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. + commonServletSetup(ConfigDbType.MEMORY); + + VESLogger.setUpEcompLogging(); + + // setup the servlet routing and error handling + 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()); + } + }); + + // load the routes from the config file + final URL routes = findStream("routes.conf"); + if (routes == null) { + throw new rrNvReadable.missingReqdSetting("No routing configuration."); + } + final DrumlinPlayishRoutingFileSource drs = new DrumlinPlayishRoutingFileSource(routes); + drr.addRouteSource(drs); + + if (CommonStartup.authflag > 0) { + NsaAuthenticator<NsaSimpleApiKey> nsaAuth = new SimpleAuthenticator(); + if (authlist != null) { + String[] authpair = authlist.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); + } + + } else if (authid != null) { + ((SimpleAuthenticator) nsaAuth).add(authid, authpwd); + } else { + //add a default test account + ((SimpleAuthenticator) nsaAuth).add("admin", "collectorpasscode"); + } + this.getSecurityManager().addAuthenticator(nsaAuth); + } + + log.info("Restful Collector Servlet is up."); + } catch (SecurityException | IOException | ConfigDbException e) { + throw new ServletException(e); + } + } + + + private static final long serialVersionUID = 1L; + private static final Logger log = LoggerFactory.getLogger(RestfulCollectorServlet.class); } |