Merge "Use managed guava version"
authorRam Koya <rk541m@att.com>
Wed, 19 Sep 2018 02:25:15 +0000 (02:25 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 19 Sep 2018 02:25:15 +0000 (02:25 +0000)
28 files changed:
pom.xml
src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java
src/main/java/org/onap/dmaap/dbcapi/aaf/AafDecrypt.java
src/main/java/org/onap/dmaap/dbcapi/aaf/AafLurService.java
src/main/java/org/onap/dmaap/dbcapi/authentication/AafLurAndFish.java
src/main/java/org/onap/dmaap/dbcapi/authentication/ApiAuthorizationCheckInterface.java
src/main/java/org/onap/dmaap/dbcapi/authentication/ApiPerms.java
src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
src/main/java/org/onap/dmaap/dbcapi/database/ConnWrapper.java
src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java
src/main/java/org/onap/dmaap/dbcapi/database/DBFieldHandler.java
src/main/java/org/onap/dmaap/dbcapi/database/DBMap.java
src/main/java/org/onap/dmaap/dbcapi/database/DBSingleton.java
src/main/java/org/onap/dmaap/dbcapi/database/DatabaseClass.java
src/main/java/org/onap/dmaap/dbcapi/database/LoadSchema.java
src/main/java/org/onap/dmaap/dbcapi/database/TableHandler.java
src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java
src/main/java/org/onap/dmaap/dbcapi/model/DcaeLocation.java
src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java
src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java
src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java
src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java
src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java
src/main/java/org/onap/dmaap/dbcapi/util/DmaapTimestamp.java
version.properties

diff --git a/pom.xml b/pom.xml
index 99fc35e..10c5db8 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                  </dependencies>
                </plugin>
 
+               <!-- prevent SNAPSHOT dependencies -->
+               <plugin>
+                       <groupId>org.apache.maven.plugins</groupId>
+                       <artifactId>maven-enforcer-plugin</artifactId>
+                       <executions>
+                               <execution>
+                                       <id>enforce-no-snapshots</id>
+                                       <goals>
+                                               <goal>enforce</goal>
+                                       </goals>
+                                       <configuration>
+                                               <rules>
+                                                       <requireReleaseDeps>
+                                                               <message>No Snapshots Allowed!</message>
+                                                               <excludes>
+                                                                       <exclude>org.onap.aaf.authz:aaf-cadi-client</exclude>
+                                                                       <exclude>org.onap.aaf.authz:aaf-misc-env</exclude>
+                                                                       <exclude>org.onap.aaf.authz:aaf-cadi-aaf</exclude>
+                                                                       <exclude>org.onap.aaf.authz:aaf-auth-client</exclude>
+                                                                       <exclude>org.onap.aaf.authz:aaf-cadi-core</exclude>
+                                                                       <exclude>org.onap.aaf.authz:aaf-misc-rosetta</exclude>
+                                                               </excludes>
+                                                       </requireReleaseDeps>
+                                               </rules>
+                                               <fail>true</fail>
+                                       </configuration>
+                               </execution>
+                       </executions>
+               </plugin>
+
                </plugins>
                <pluginManagement>
                        <plugins>
                        <artifactId>jackson-annotations</artifactId>
                        <version>${jackson.version}</version>
                </dependency>
-               <dependency>
-                       <groupId>com.fasterxml.jackson.core</groupId>
-                       <artifactId>jackson-databind</artifactId>
-<!-- for DMAAP-205, a point release on the common version
-        addresses a security issue.  Note the add notation here
-  -->
-                       <version>${jackson.version}.1</version>
-               </dependency>
                <dependency>
                        <groupId>com.fasterxml.jackson.dataformat</groupId>
                        <artifactId>jackson-dataformat-yaml</artifactId>
                        <artifactId>logback-classic</artifactId>
                        <version>1.2.0</version>
                </dependency>
+<!-- DMAAP-656:
+   - override this dependency because it utilized a third party
+   - lib called com.google.guava:20.0 which had severe security threat identified.
+ -->
+               <dependency>
+                       <groupId>com.google.guava</groupId>
+                       <artifactId>guava</artifactId>
+                       <version>24.1.1-jre</version>
+               </dependency>
                <dependency>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-core</artifactId>
-                       <version>1.5.13</version>
+                       <version>${swagger.version}</version>
                </dependency>
                <dependency>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-jersey2-jaxrs</artifactId>
-                       <version>1.5.13</version>
+                       <version>${swagger.version}</version>
                </dependency>
                <dependency>
                        <groupId>io.swagger</groupId>
                        <artifactId>swagger-annotations</artifactId>
-                       <version>1.5.13</version>
+                       <version>${swagger.version}</version>
                </dependency>
                <dependency>
                        <groupId>org.glassfish.jersey.containers</groupId>
                <dependency>
                        <groupId>commons-codec</groupId>
                        <artifactId>commons-codec</artifactId>
-                       <version>1.6</version>
+                       <version>1.11</version>
                </dependency>
                <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
                <dependency>
                </site>
        </distributionManagement>
        <properties>
-           <jackson.version>2.8.11</jackson.version>
+               <swagger.version>1.5.19</swagger.version>
+           <jackson.version>2.9.5</jackson.version>
                <jersey.version>2.26</jersey.version>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-               <jettyVersion>9.3.9.v20160517</jettyVersion> 
+               <jettyVersion>9.3.8.RC0</jettyVersion> 
                <eelf.version>0.0.1</eelf.version>
-               <artifact.version>1.0.14-SNAPSHOT</artifact.version>
+               <artifact.version>1.0.15-SNAPSHOT</artifact.version>
                <!-- SONAR -->
                <jacoco.version>0.7.7.201606060606</jacoco.version>
                <sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
index 01d103d..1d7b273 100644 (file)
@@ -40,20 +40,19 @@ import javax.net.ssl.SSLHandshakeException;
 import org.apache.commons.codec.binary.Base64;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
-import org.onap.dmaap.dbcapi.service.DmaapService;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 
 public class AafConnection extends BaseLoggingClass {
 
 
-          
-   
+
+
 
        private String aafCred;
        private String unit_test;
 
-       
+
        private HttpsURLConnection uc;
 
 
@@ -63,22 +62,23 @@ public class AafConnection extends BaseLoggingClass {
         unit_test = p.getProperty( "UnitTest", "No" );
 
        }
-       
+
 
        private boolean makeConnection( String pURL ) {
-       
+
                try {
                        URL u = new URL( pURL );
                        uc = (HttpsURLConnection) u.openConnection();
                        uc.setInstanceFollowRedirects(false);
                        logger.info( "successful connect to " + pURL );
                        return(true);
-               } catch ( UnknownHostException uhe ) {
+               } catch ( UnknownHostException uhe ) {                  
                errorLogger.error(DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION,  pURL, uhe.getMessage() );
-            uhe.printStackTrace();
+               logger.error("Error", uhe);
             return(false);
                } catch (Exception e) {
-               errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR,  pURL, e.getMessage() );
+                       logger.error("Error", e);
+               errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR,  pURL, e.getMessage());
             e.printStackTrace();
             return(false);
         }
@@ -94,9 +94,9 @@ public class AafConnection extends BaseLoggingClass {
                                sb.append( line );
                        }
                } catch (IOException ex ) {
-                       errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION,  ex.getMessage());
+                       errorLogger.error( DmaapbcLogMessageEnum.IO_EXCEPTION + ex.getMessage(),ex);
                }
-                       
+
                return sb.toString();
        }
        
@@ -107,11 +107,11 @@ public class AafConnection extends BaseLoggingClass {
                String auth =  "Basic " + Base64.encodeBase64String(aafCred.getBytes());
                int rc = -1;
 
-               
+
                if ( ! makeConnection( pURL ) ) {
                        return rc;
                };
-               
+
 
                byte[] postData = obj.getBytes();
                //logger.info( "post fields=" + postData );  //byte isn't very readable
@@ -137,21 +137,26 @@ public class AafConnection extends BaseLoggingClass {
                  os.write( postData );
 
             } catch (ProtocolException pe) {
+               logger.error("Error", pe);
                  // Rcvd error instead of 100-Continue
                  try {
                      // work around glitch in Java 1.7.0.21 and likely others
                      // without this, Java will connect multiple times to the server to run the same request
                      uc.setDoOutput(false);
                  } catch (Exception e) {
+                        logger.error("Error", e);
                  }
             } catch ( SSLHandshakeException she ) {
+               logger.error("Error", she);
                        errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL);
                        } catch ( UnknownHostException uhe ) {
+                               logger.error("Error", uhe);
                                errorLogger.error(DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION,  pURL, uhe.getMessage() );
                rc = 500;
                return rc;
             } catch ( ConnectException ce ) {
-                               if ( unit_test.equals( "Yes" ) ) {
+               logger.error("Error", ce);
+                               if ( "Yes".equals(unit_test) ) {
                                        rc = 201;
                                        return rc;
                                }
@@ -162,6 +167,7 @@ public class AafConnection extends BaseLoggingClass {
                        try {
                                rc = uc.getResponseCode();
                        } catch ( SSLHandshakeException she ) {
+                               logger.error("Error", she);
                                errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL);
                rc = 500;
                return rc;
@@ -190,16 +196,16 @@ public class AafConnection extends BaseLoggingClass {
             } 
             
                } catch (Exception e) {
-            System.err.println("Unable to read response  " );
-            e.printStackTrace();
+            logger.error("Unable to read response  ");
+            logger.error("Error", e);
         }
                finally {
                        try {
                                uc.disconnect();
-                       } catch ( Exception e ) {}
-               }
-               //return responseBody;
-       
+                       } catch ( Exception e ) {
+                               logger.error("Error", e);
+                       }
+               }       
                return rc;
                
        }
@@ -239,19 +245,22 @@ public class AafConnection extends BaseLoggingClass {
                  os.write( postData );
 
             } catch (ProtocolException pe) {
+               logger.error("Error", pe);
                  // Rcvd error instead of 100-Continue
                  try {
                      // work around glitch in Java 1.7.0.21 and likely others
                      // without this, Java will connect multiple times to the server to run the same request
                      uc.setDoOutput(false);
                  } catch (Exception e) {
+                        logger.error("Error", e);
                  }
             } catch ( SSLHandshakeException she ) {
-               errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL);
+               errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR +"For:- "+pURL,she);
             }
                        try {
                                rc = uc.getResponseCode();
                        } catch ( SSLHandshakeException she ) {
+                               logger.error("Error", she);
                                errorLogger.error( DmaapbcLogMessageEnum.SSL_HANDSHAKE_ERROR, pURL);
                rc = 500;
                return rc;
@@ -280,11 +289,9 @@ public class AafConnection extends BaseLoggingClass {
             } 
             
                } catch (Exception e) {
-            System.err.println("Unable to read response  " );
-            e.printStackTrace();
-        }
-               //return responseBody;
-       
+            logger.error("Unable to read response  ");
+            logger.error("Error", e);
+        }      
                return rc;
                
        }
index 8728988..31e2a34 100644 (file)
@@ -36,6 +36,7 @@ public class AafDecrypt extends BaseLoggingClass  {
                        dec = (DecryptionInterface) (Class.forName(dClass).newInstance());      
                        dec.init( p.getProperty("CredentialCodecKeyfile", "LocalKey"));
                } catch (Exception ee ) {
+                       logger.error("Error", ee);
                        errorLogger.error(DmaapbcLogMessageEnum.UNEXPECTED_CONDITION, "attempting to instantiate " + dClass  );         
                }       
        }
@@ -46,6 +47,7 @@ public class AafDecrypt extends BaseLoggingClass  {
                try {           
                        pwd = dec.decrypt( encPwd );
                } catch( IOException io ) {
+                       logger.error("Error", io);
                        errorLogger.error(DmaapbcLogMessageEnum.DECRYPT_IO_ERROR, dClass, encPwd );
                } 
                
index cb0be04..edc522e 100644 (file)
@@ -37,13 +37,13 @@ import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
 import org.onap.aaf.cadi.principal.UnAuthPrincipal;
 import org.onap.aaf.misc.env.APIException;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
-import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
-import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 /*
  * this service uses the AAF Lur object to lookup identities and perms
  */
 public class AafLurService extends BaseLoggingClass {
+       
+       static Logger logger = Logger.getLogger(AafLurService.class.getName());
 
        
         private static AAFConHttp aafcon;
@@ -66,6 +66,7 @@ public class AafLurService extends BaseLoggingClass {
                } catch ( CadiException | LocatorException e) {
                        appLogger.error( "Failure of AAFConHttp: " + e.getMessage() );
                        errorLogger.error( "Failure of AAFConHttp: " + e.getMessage() );
+                       logger.error(e);
                        e.printStackTrace();
                        throw e;
                } 
@@ -74,6 +75,7 @@ public class AafLurService extends BaseLoggingClass {
                } catch ( CadiException  e) {
                        appLogger.error( "Failure of newLur(): " + e.getMessage() );
                        errorLogger.error( "Failure of newLur(): " + e.getMessage() );
+                       logger.error(e);
                        e.printStackTrace();
                        throw e;
                } 
@@ -87,6 +89,7 @@ public class AafLurService extends BaseLoggingClass {
                                init( myAccess );
                        } catch (APIException | CadiException | LocatorException e) {
                                // TODO Auto-generated catch block
+                               logger.error(e);
                                e.printStackTrace();
                                throw e;
                        } 
@@ -120,7 +123,10 @@ public class AafLurService extends BaseLoggingClass {
                        return rc;
                }
                rc =  aafLur.fish( principal, aafPerm );
-               if (rc == true ) return rc;
+               boolean flag = true;
+               if (rc == flag ) {
+                       return rc;
+               }
                
                List<Permission> perms = new ArrayList<Permission>();
                aafLur.fishAll( principal,  perms);
index b699a29..2366452 100644 (file)
@@ -31,8 +31,6 @@ import org.onap.aaf.cadi.PropAccess;
 import org.onap.aaf.misc.env.APIException;
 import org.onap.dmaap.dbcapi.aaf.AafLurService;
 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
-import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
-import org.onap.dmaap.dbcapi.server.Main;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 
@@ -45,7 +43,6 @@ public class AafLurAndFish implements ApiAuthorizationCheckInterface {
        
        AafLurAndFish()  throws AuthenticationErrorException  {
        
-               String[] args = new String[1];
                DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
                api_namespace = p.getProperty( "ApiNamespace", "org.onap.dmaap-bc.api");
 
@@ -61,13 +58,15 @@ public class AafLurAndFish implements ApiAuthorizationCheckInterface {
                        }
                } catch ( IOException e ) {
                        logger.error( "Unable to load " + cadiprop );
+                       logger.error("Error", e);
                        throw new AuthenticationErrorException( );
                }
                try {
                        PropAccess myAccess = new PropAccess( props );
                
                        svc =  AafLurService.getInstance(myAccess);
-               } catch (APIException | CadiException | LocatorException e ) { 
+               } catch (APIException | CadiException | LocatorException e ) {
+                       logger.error("Error", e);
                        logger.error( e.toString() );
                        throw new AuthenticationErrorException();
                }
@@ -78,10 +77,12 @@ public class AafLurAndFish implements ApiAuthorizationCheckInterface {
        
                try {
                        boolean resp = svc.checkPerm( api_namespace, mechid, pwd, p );
-                       if ( resp == false ) {
+                       boolean flag = false;
+                       if ( resp == flag ) {
                                throw new AuthenticationErrorException();
                        }
                } catch ( IOException | CadiException  e ) { 
+                       logger.error("Error", e);
                        logger.error( e.toString() );
                        throw new AuthenticationErrorException();
                }
index a7f0d76..1fef09d 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.dmaap.dbcapi.authentication;
 
 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
 
+@FunctionalInterface
 public interface ApiAuthorizationCheckInterface {
        public void check( String mechid, String pwd, DmaapPerm p ) throws AuthenticationErrorException;
 
index 6749932..f3b9ebc 100644 (file)
@@ -34,6 +34,20 @@ import org.onap.dmaap.dbcapi.service.DmaapService;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 public  class ApiPerms extends BaseLoggingClass {
+       static String topic = "topics";
+       static String mrClusters = "mr_clusters";
+       static String mrClients = "mr_clients";
+       static String feed = "feeds";
+       static String drSubs = "dr_subs";
+       static String drPubs = "dr_pubs";
+       static String drNodes = "dr_nodes";
+       static String dcaeLocations = "dcaeLocations";
+       static String inventory = "Inventory";
+       static String portalUser = "PortalUser";
+       static String orchestrator = "Orchestrator";
+       static String delete = "DELETE";
+       static String dmaap = "dmaap";
+       static String controller = "Controller";
        
        private static class PermissionMap {
                static final EELFLogger logger = EELFManager.getInstance().getLogger( PermissionMap.class );
@@ -42,6 +56,12 @@ public  class ApiPerms extends BaseLoggingClass {
                String action;
                String[] roles;
                
+               private PermissionMap( String u, String a, String[] r ) {
+                       this.setUri(u);
+                       this.setAction(a);
+                       this.setRoles(r);
+               }       
+               
                public String getUri() {
                        return uri;
                }
@@ -62,13 +82,7 @@ public  class ApiPerms extends BaseLoggingClass {
                        this.roles = roles;
                }
 
-               private PermissionMap( String u, String a, String[] r ) {
-                       this.setUri(u);
-                       this.setAction(a);
-                       this.setRoles(r);
-               }
-               
-               static public void initMap( PermissionMap[] pmap, String instance ) {
+               public static void initMap( PermissionMap[] pmap, String instance ) {
 
                        DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
                        String api = p.getProperty("ApiNamespace", "apiNamespace.not.set");
@@ -102,54 +116,54 @@ public  class ApiPerms extends BaseLoggingClass {
        }
        
        static PermissionMap[] bootMap = {
-               new PermissionMap( "dmaap", "GET", new String[] { "Controller" }),
-               new PermissionMap( "dmaap", "POST", new String[] { "Controller" }),     
-               new PermissionMap( "dmaap", "PUT", new String[] { "Controller" }),
-               new PermissionMap( "dmaap", "DELETE", new String[] { "Controller" })
+               new PermissionMap( dmaap, "GET", new String[] { controller }),
+               new PermissionMap( dmaap, "POST", new String[] { controller }), 
+               new PermissionMap( dmaap, "PUT", new String[] { controller }),
+               new PermissionMap( dmaap, delete, new String[] { controller })
        
        };
 
        static PermissionMap[] envMap = {
-               new PermissionMap( "dmaap", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "dmaap", "POST", new String[] { "Controller" } ),            
-               new PermissionMap( "dmaap", "PUT", new String[] { "Controller" }),
-               new PermissionMap( "dmaap", "DELETE", new String[] { "Controller" }),
+               new PermissionMap( dmaap, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( dmaap, "POST", new String[] { controller } ),                
+               new PermissionMap( dmaap, "PUT", new String[] { controller }),
+               new PermissionMap( dmaap, delete, new String[] { controller }),
                new PermissionMap( "bridge", "GET", new String[] {  "Metrics" }),
                //new PermissionMap( "bridge", "POST", new String[] { "Metrics" } ),            
                //new PermissionMap( "bridge", "PUT", new String[] { "Metrics" }),
-               //new PermissionMap( "bridge", "DELETE", new String[] { "Metrics" }),
-               new PermissionMap( "dcaeLocations", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "dcaeLocations", "POST", new String[] { "Controller" } ),            
-               new PermissionMap( "dcaeLocations", "PUT", new String[] { "Controller" }),
-               new PermissionMap( "dcaeLocations", "DELETE", new String[] { "Controller" }),
-               new PermissionMap( "dr_nodes", "GET", new String[] { "Controller", "Orchestrator", "Inventory",  "PortalUser" }),
-               new PermissionMap( "dr_nodes", "POST", new String[] { "Controller" } ),         
-               new PermissionMap( "dr_nodes", "PUT", new String[] { "Controller" }),
-               new PermissionMap( "dr_nodes", "DELETE", new String[] { "Controller" }),
-               new PermissionMap( "dr_pubs", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "dr_pubs", "POST", new String[] { "Controller", "Orchestrator","PortalUser" } ),             
-               new PermissionMap( "dr_pubs", "PUT", new String[] { "Controller", "Orchestrator","PortalUser" }),
-               new PermissionMap( "dr_pubs", "DELETE", new String[] { "Controller", "Orchestrator","PortalUser" }),
-               new PermissionMap( "dr_subs", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "dr_subs", "POST", new String[] { "Controller", "Orchestrator","PortalUser" } ),             
-               new PermissionMap( "dr_subs", "PUT", new String[] { "Controller", "Orchestrator","PortalUser" }),
-               new PermissionMap( "dr_subs", "DELETE", new String[] { "Controller", "Orchestrator","PortalUser" }),
-               new PermissionMap( "feeds", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "feeds", "POST", new String[] { "Controller", "Orchestrator","PortalUser" } ),               
-               new PermissionMap( "feeds", "PUT", new String[] { "Controller", "Orchestrator", "PortalUser" }),
-               new PermissionMap( "feeds", "DELETE", new String[] { "Controller", "PortalUser" }),
-               new PermissionMap( "mr_clients", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "mr_clients", "POST", new String[] { "Controller","Orchestrator", "PortalUser" } ),          
-               new PermissionMap( "mr_clients", "PUT", new String[] { "Controller", "Orchestrator","PortalUser" }),
-               new PermissionMap( "mr_clients", "DELETE", new String[] { "Controller","Orchestrator", "PortalUser" }),
-               new PermissionMap( "mr_clusters", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "mr_clusters", "POST", new String[] { "Controller" } ),              
-               new PermissionMap( "mr_clusters", "PUT", new String[] { "Controller" }),
-               new PermissionMap( "mr_clusters", "DELETE", new String[] { "Controller" }),
-               new PermissionMap( "topics", "GET", new String[] { "Controller", "Orchestrator", "Inventory", "Metrics", "PortalUser" }),
-               new PermissionMap( "topics", "POST", new String[] { "Controller", "Orchestrator" } ),           
-               new PermissionMap( "topics", "PUT", new String[] { "Controller", "Orchestrator" }),
-               new PermissionMap( "topics", "DELETE", new String[] { "Controller", "Orchestrator" })
+               //new PermissionMap( "bridge", delete, new String[] { "Metrics" }),
+               new PermissionMap( dcaeLocations, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( dcaeLocations, "POST", new String[] { controller } ),                
+               new PermissionMap( dcaeLocations, "PUT", new String[] { controller }),
+               new PermissionMap( dcaeLocations, delete, new String[] { controller }),
+               new PermissionMap( drNodes, "GET", new String[] { controller, orchestrator, inventory,  portalUser }),
+               new PermissionMap( drNodes, "POST", new String[] { controller } ),              
+               new PermissionMap( drNodes, "PUT", new String[] { controller }),
+               new PermissionMap( drNodes, delete, new String[] { controller }),
+               new PermissionMap( drPubs, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( drPubs, "POST", new String[] { controller, orchestrator,portalUser } ),              
+               new PermissionMap( drPubs, "PUT", new String[] { controller, orchestrator,portalUser }),
+               new PermissionMap( drPubs, delete, new String[] { controller, orchestrator,portalUser }),
+               new PermissionMap( drSubs, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( drSubs, "POST", new String[] { controller, orchestrator,portalUser } ),              
+               new PermissionMap( drSubs, "PUT", new String[] { controller, orchestrator,portalUser }),
+               new PermissionMap( drSubs, delete, new String[] { controller, orchestrator,portalUser }),
+               new PermissionMap( feed, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( feed, "POST", new String[] { controller, orchestrator,portalUser } ),                
+               new PermissionMap( feed, "PUT", new String[] { controller, orchestrator, portalUser }),
+               new PermissionMap( feed, delete, new String[] { controller, portalUser }),
+               new PermissionMap( mrClients, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( mrClients, "POST", new String[] { controller,orchestrator, portalUser } ),           
+               new PermissionMap( mrClients, "PUT", new String[] { controller, orchestrator,portalUser }),
+               new PermissionMap( mrClients, delete, new String[] { controller,orchestrator, portalUser }),
+               new PermissionMap( mrClusters, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( mrClusters, "POST", new String[] { controller } ),           
+               new PermissionMap( mrClusters, "PUT", new String[] { controller }),
+               new PermissionMap( mrClusters, delete, new String[] { controller }),
+               new PermissionMap( topic, "GET", new String[] { controller, orchestrator, inventory, "Metrics", portalUser }),
+               new PermissionMap( topic, "POST", new String[] { controller, orchestrator } ),          
+               new PermissionMap( topic, "PUT", new String[] { controller, orchestrator }),
+               new PermissionMap( topic, delete, new String[] { controller, orchestrator })
        };
        
        public void setBootMap() {
@@ -159,8 +173,8 @@ public  class ApiPerms extends BaseLoggingClass {
        
        public void setEnvMap() {
                Dmaap dmaap = new DmaapService().getDmaap();
-               String dmaap_name = dmaap.getDmaapName();
-               PermissionMap.initMap( envMap, dmaap_name );
+               String dmaapName = dmaap.getDmaapName();
+               PermissionMap.initMap( envMap, dmaapName );
        }
        
 
index 751c5b8..34d36ba 100644 (file)
@@ -30,6 +30,7 @@ import java.net.ProtocolException;
 import java.net.SocketException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import javax.net.ssl.HttpsURLConnection;
 
@@ -143,7 +144,7 @@ public class DrProvConnection extends BaseLoggingClass {
        public  String doPostFeed( Feed postFeed, ApiError err ) {
 
                byte[] postData = postFeed.getBytes();
-               logger.info( "post fields=" + postData.toString() );
+               logger.info( "post fields=" + Arrays.toString(postData) );
                String responsemessage = null;
                String responseBody = null;
 
@@ -361,7 +362,7 @@ public class DrProvConnection extends BaseLoggingClass {
 
        public String doPutFeed(Feed putFeed, ApiError err) {
                byte[] postData = putFeed.getBytes();
-               logger.info( "post fields=" + postData.toString() );
+               logger.info( "post fields=" + Arrays.toString(postData) );
                String responsemessage = null;
                String responseBody = null;
 
@@ -830,12 +831,11 @@ public class DrProvConnection extends BaseLoggingClass {
                      }
                  }
             }
+               err.setCode(rc);
             if (rc == 204 ) {
                        responseBody = bodyToString( uc.getInputStream() );
                        logger.info( "responseBody=" + responseBody );
-
             } else {
-               err.setCode(rc);
                err.setMessage(responsemessage);
             }
             
index 4db6ca3..26c494f 100644 (file)
@@ -30,6 +30,7 @@ import java.net.HttpURLConnection;
 import java.net.ProtocolException;
 import java.net.URL;
 import java.net.UnknownHostException;
+import java.util.Arrays;
 
 import javax.net.ssl.HttpsURLConnection;
 
@@ -155,7 +156,7 @@ public class MrProvConnection extends BaseLoggingClass{
 
                try {
                        byte[] postData = postTopic.getBytes();
-                       logger.info( "post fields=" + postData.toString() );
+                       logger.info( "post fields=" + Arrays.toString(postData));
                        
                        // when not using AAF, do not attempt Basic Authentication
                        if ( useAAF ) {
index 18fdeba..492037c 100644 (file)
@@ -33,7 +33,6 @@ import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLException;
 
 import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.model.ApiError;
 import org.onap.dmaap.dbcapi.model.MR_Cluster;
@@ -81,7 +80,7 @@ public class MrTopicConnection extends BaseLoggingClass  {
                        return(true);
                } catch (Exception e) {
             logger.error("Unexpected error during openConnection of " + pURL );
-            e.printStackTrace();
+            logger.error("Error", e);;
             return(false);
         }
 
@@ -97,7 +96,7 @@ public class MrTopicConnection extends BaseLoggingClass  {
                        return(true);
                } catch (Exception e) {
             logger.error("Unexpected error during openConnection of " + pURL );
-            e.printStackTrace();
+            logger.error("error", e);
             return(false);
         }
 
@@ -147,13 +146,10 @@ public class MrTopicConnection extends BaseLoggingClass  {
 
             } catch (ProtocolException pe) {
                  // Rcvd error instead of 100-Continue
-                 try {
-                     // work around glitch in Java 1.7.0.21 and likely others
-                     // without this, Java will connect multiple times to the server to run the same request
-                     uc.setDoOutput(false);
-                 } catch (Exception e) {
-                 }
+               callSetDoOutputOnError();
+                 
             }  catch ( SSLException se ) {
+               logger.error("Error", se);
                        response.setCode(500);
                        response.setMessage( se.getMessage());
                        return response;
@@ -194,16 +190,28 @@ public class MrTopicConnection extends BaseLoggingClass  {
                                response.setCode(500);
                                response.setMessage( "Unable to read response");
                                logger.warn( response.getMessage() );
-               e.printStackTrace();
+               logger.error("Error", e);
                        }
         }
                finally {
                        try {
                                uc.disconnect();
-                       } catch ( Exception e ) {}
+                       } catch ( Exception e ) {
+                               logger.error("Error", e);
+                       }
                }
                return response;
 
        }
+       
+       public void callSetDoOutputOnError() {
+               try {
+            // work around glitch in Java 1.7.0.21 and likely others
+            // without this, Java will connect multiple times to the server to run the same request
+            uc.setDoOutput(false);
+        } catch (Exception e) {
+                       logger.error("Error", e);
+        }
+       }
 
 }
index e0c7819..2317fe4 100644 (file)
@@ -22,17 +22,22 @@ package org.onap.dmaap.dbcapi.database;
 
 import java.sql.*;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
 
 public abstract class ConnWrapper<T, U>        {
+       EELFLogger logger = EELFManager.getInstance().getLogger( ConnWrapper.class );
        protected Connection c;
        protected PreparedStatement ps;
        protected ResultSet     rs;
        protected abstract T run(U u) throws Exception;
-       public T protect(ConnectionFactory cf, U u) throws DBException {
+       public T protect(ConnectionFactory cf, U u) {
                try {
                        try {
                                return(attempt(cf, u, false));
                        } catch (SQLException sqle) {
+                               logger.error("Error", sqle);
                                return(attempt(cf, u, true));
                        }
                } catch (RuntimeException rte) {
@@ -52,11 +57,26 @@ public abstract class ConnWrapper<T, U>     {
                        c = null;
                        return(ret);
                } finally {
-                       if (rs != null) { try { rs.close(); } catch (Exception e) {}}
+                       if (rs != null) { 
+                               try { 
+                                       rs.close(); 
+                               } catch (Exception e) {
+                                       logger.error("Error", e);
+                               }}
                        rs = null;
-                       if (ps != null) { try { ps.close(); } catch (Exception e) {}}
+                       if (ps != null) { 
+                               try { 
+                                       ps.close(); 
+                               } catch (Exception e) {
+                                       logger.error("Error", e);
+                               }}
                        ps = null;
-                       if (c != null) { try { c.close(); } catch (Exception e) {}}
+                       if (c != null) { 
+                               try { 
+                                       c.close(); 
+                               } catch (Exception e) {
+                                       logger.error("Error", e);
+                               }}
                        c = null;
                }
        }
index 38c063c..aee3ff1 100644 (file)
@@ -23,12 +23,9 @@ package org.onap.dmaap.dbcapi.database;
 import java.sql.*;
 import java.util.*;
 
-import org.apache.log4j.Logger;
-
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
-import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 public class ConnectionFactory {
@@ -90,6 +87,10 @@ public class ConnectionFactory       {
                                return;
                        }
                }
-               try { c.close(); } catch (Exception e) {}
+               try { 
+                       c.close(); 
+               } catch (Exception e) {
+                       logger.error("Error", e);
+               }
        }
 }
index 072c548..59d610c 100644 (file)
@@ -24,7 +24,6 @@ import java.lang.reflect.*;
 import java.sql.*;
 import java.util.*;
 
-import org.apache.log4j.Logger;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
@@ -33,7 +32,40 @@ import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 
 
 public class DBFieldHandler    {
-       static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
+       static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();       
+
+       public DBFieldHandler(Class<?> c, String fieldname, int fieldnum) throws Exception {
+               this(c, fieldname, fieldnum, null);
+       }
+       public DBFieldHandler(Class<?> c, String fieldname, int fieldnum, SqlOp op) throws Exception {
+               this.fieldnum = fieldnum;
+               StringBuilder sb = new StringBuilder();
+               for (String s: fieldname.split("_")) {  
+                       sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1));
+               }
+               String camelcase = sb.toString();
+               try {
+                       objget = c.getMethod("is" + camelcase);
+               } catch (Exception e) {
+                       errorLogger.error("Error", e);
+                       objget = c.getMethod("get" + camelcase);
+               }
+               objset = c.getMethod("set" + camelcase, objget.getReturnType());
+               sqlop = op;
+               if (sqlop != null) {
+                       return;
+               }
+               Class<?> x = objget.getReturnType();
+               if (x.isEnum()) {
+                       sqlop = new EnumSql(x);
+                       return;
+               }
+               sqlop = sqltypes.get(x.getName());
+               if (sqlop != null) {
+                       return;
+               }
+               errorLogger.error(DmaapbcLogMessageEnum.DB_NO_FIELD_HANDLER,  c.getName(),  fieldname,  Integer.toString(fieldnum),  x.getName());
+       }
        
        public static interface SqlOp   {
                public Object get(ResultSet rs, int index) throws Exception;
@@ -121,7 +153,7 @@ public class DBFieldHandler {
         }
         private static Map<String, SqlOp> sqltypes;
         static {
-                sqltypes = new HashMap<String, SqlOp>();
+                sqltypes = new HashMap<>();
                sqltypes.put("[Ljava.lang.String;", new AofString());
                sqltypes.put("java.util.Date", new SqlDate());
                 try {
@@ -134,6 +166,7 @@ public class DBFieldHandler {
                         new SqlType("Short");
                         new SqlType("String");
                 } catch (Exception e) {
+                       errorLogger.error("Error", e);
                        errorLogger.error(DmaapbcLogMessageEnum.DB_ACCESS_INIT_ERROR,  e.getMessage() );
                 }
         }
@@ -156,37 +189,6 @@ public class DBFieldHandler        {
        public void fromSQL(ResultSet r, Object o) throws Exception {
                objset.invoke(o, sqlop.get(r, fieldnum));
        }
-       public DBFieldHandler(Class<?> c, String fieldname, int fieldnum) throws Exception {
-               this(c, fieldname, fieldnum, null);
-       }
-       public DBFieldHandler(Class<?> c, String fieldname, int fieldnum, SqlOp op) throws Exception {
-               this.fieldnum = fieldnum;
-               StringBuffer sb = new StringBuffer();
-               for (String s: fieldname.split("_")) {
-                       sb.append(s.substring(0, 1).toUpperCase()).append(s.substring(1));
-               }
-               String camelcase = sb.toString();
-               try {
-                       objget = c.getMethod("is" + camelcase);
-               } catch (Exception e) {
-                       objget = c.getMethod("get" + camelcase);
-               }
-               objset = c.getMethod("set" + camelcase, objget.getReturnType());
-               sqlop = op;
-               if (sqlop != null) {
-                       return;
-               }
-               Class<?> x = objget.getReturnType();
-               if (x.isEnum()) {
-                       sqlop = new EnumSql(x);
-                       return;
-               }
-               sqlop = sqltypes.get(x.getName());
-               if (sqlop != null) {
-                       return;
-               }
-               errorLogger.error(DmaapbcLogMessageEnum.DB_NO_FIELD_HANDLER,  c.getName(),  fieldname,  Integer.toString(fieldnum),  x.getName());
-       }
        public static String fesc(String s) {
                if (s == null) {
                        return(s);
index a9bf56e..6f63848 100644 (file)
@@ -30,42 +30,42 @@ public class DBMap<C> extends TableHandler<C> implements Map<String, C>     {
        public DBMap(ConnectionFactory cf, Class<C> cls, String tabname, String keyfield) throws Exception {
                super(cf, cls, tabname, keyfield);
        }
-       public void clear() throws UnsupportedOperationException {
+       public void clear() {
                throw new UnsupportedOperationException();
        }
-       public boolean containsKey(Object key) throws DBException {
+       public boolean containsKey(Object key) {
                return(get(key) != null);
        }
-       public boolean containsValue(Object value) throws UnsupportedOperationException {
+       public boolean containsValue(Object value) {
                throw new UnsupportedOperationException();
        }
        public boolean isEmpty() {
                return(false);
        }
-       public Set<Map.Entry<String, C>> entrySet() throws DBException {
+       public Set<Map.Entry<String, C>> entrySet() {
                return(list());
        }
-       public Set<String> keySet() throws DBException {
-               Set<String> ret = new HashSet<String>();
+       public Set<String> keySet() {
+               Set<String> ret = new HashSet<>();
                for (Map.Entry<String, C> x: list()) {
                        ret.add(x.getKey());
                }
                return(ret);
        }
-       public void putAll(Map<? extends String, ? extends C> m) throws UnsupportedOperationException {
+       public void putAll(Map<? extends String, ? extends C> m) {
                throw new UnsupportedOperationException();
        }
        public int size() {
                return(2);
        }
-       public Collection<C> values() throws DBException {
-               Collection<C> ret = new Vector<C>();
+       public Collection<C> values() {
+               Collection<C> ret = new Vector<>();
                for (Map.Entry<String, C> x: list()) {
                        ret.add(x.getValue());
                }
                return(ret);
        }
-       public C get(Object key) throws DBException {
+       public C get(Object key) {
                if (!(key instanceof String)) {
                        return(null);
                }
@@ -85,13 +85,13 @@ public class DBMap<C> extends TableHandler<C> implements Map<String, C>     {
                        }
                }).protect(cf, (String)key));
        }
-       public Set<Map.Entry<String, C>> list() throws DBException {
+       public Set<Map.Entry<String, C>> list() {
                return((new ConnWrapper<Set<Map.Entry<String, C>>, Object>() {
                        protected Set<Map.Entry<String, C>> run(Object junk) throws Exception {
                                DBFieldHandler keyfield = fields[fields.length - 1];
                                ps = c.prepareStatement(liststmt);
                                rs = ps.executeQuery();
-                               Set<Map.Entry<String, C>> ret = new HashSet<Map.Entry<String, C>>();
+                               Set<Map.Entry<String, C>> ret = new HashSet<>();
                                while (rs.next()) {
                                        C val = cls.newInstance();
                                        for (DBFieldHandler f: fields) {
@@ -104,7 +104,7 @@ public class DBMap<C> extends TableHandler<C> implements Map<String, C>     {
                        }
                }).protect(cf, null));
        }
-       public C put(String key, C val) throws DBException {
+       public C put(String key, C val) {
                try {
                        fields[fields.length - 1].setKey(val, key);
                } catch (Exception e) {
@@ -122,7 +122,7 @@ public class DBMap<C> extends TableHandler<C> implements Map<String, C>     {
                        }
                }).protect(cf, val));
        }
-       public C remove(Object key) throws DBException {
+       public C remove(Object key) {
                if (!(key instanceof String)) {
                        return(null);
                }
index 9a34f58..2633d70 100644 (file)
@@ -34,7 +34,7 @@ public class DBSingleton<C> extends TableHandler<C> implements Singleton<C>   {
                super(cf, cls, tabname, null);
                singleton = cls.newInstance();
        }
-       public C get() throws DBException {
+       public C get() {
                return((new ConnWrapper<C, Object>() {
                        protected C run(Object junk) throws Exception {
                                ps = c.prepareStatement(getstmt);
@@ -49,7 +49,7 @@ public class DBSingleton<C> extends TableHandler<C> implements Singleton<C>   {
                        }
                }).protect(cf, null));
        }
-       public void init(C val) throws DBException {
+       public void init(C val) {
                if (get() != null) {
                        return;
                }
@@ -69,7 +69,7 @@ public class DBSingleton<C> extends TableHandler<C> implements Singleton<C>   {
                        }
                }).protect(cf, val);
        }
-       public void update(C val) throws DBException {
+       public void update(C val) {
                (new ConnWrapper<Void, C>() {
                        protected Void run(C val) throws Exception {
                                ps = c.prepareStatement(insorreplstmt);
index f0a5582..11b0d15 100644 (file)
@@ -57,10 +57,6 @@ public class DatabaseClass extends BaseLoggingClass {
                        }
                        List<String> rv = new ArrayList<String>();
                        for (String s: val.split(",")) {
-                               //String[] f = s.split(";");
-                               //if (f.length < 3) {
-                               //      continue;
-                               //}
                                rv.add(new String(s));
                        }
                        return(rv);
@@ -72,7 +68,7 @@ public class DatabaseClass extends BaseLoggingClass {
                        }
                        @SuppressWarnings("unchecked")
                        List<String> xv = (List<String>)val;
-                       StringBuffer sb = new StringBuffer();
+                       StringBuilder sb = new StringBuilder();
                        String sep = "";
                        for (Object o: xv) {
                                String rv = (String)o;
@@ -152,17 +148,17 @@ public class DatabaseClass extends BaseLoggingClass {
                        }
                        try {
                                dmaap = new DBSingleton<Dmaap>(Dmaap.class, "dmaap");
-                               dcaeLocations = new DBMap<DcaeLocation>(DcaeLocation.class, "dcae_location", "dcae_location_name");
-                               dr_nodes = new DBMap<DR_Node>(DR_Node.class, "dr_node", "fqdn");
-                               dr_pubs = new DBMap<DR_Pub>(DR_Pub.class, "dr_pub", "pub_id");
-                               dr_subs = new DBMap<DR_Sub>(DR_Sub.class, "dr_sub", "sub_id");
-                               mr_clients = new DBMap<MR_Client>(MR_Client.class, "mr_client", "mr_client_id");
-                               mr_clusters = new DBMap<MR_Cluster>(MR_Cluster.class, "mr_cluster", "dcae_location_name");
-                               feeds = new DBMap<Feed>(Feed.class, "feed", "feed_id");
+                               dcaeLocations = new DBMap<>(DcaeLocation.class, "dcae_location", "dcae_location_name");
+                               dr_nodes = new DBMap<>(DR_Node.class, "dr_node", "fqdn");
+                               dr_pubs = new DBMap<>(DR_Pub.class, "dr_pub", "pub_id");
+                               dr_subs = new DBMap<>(DR_Sub.class, "dr_sub", "sub_id");
+                               mr_clients = new DBMap<>(MR_Client.class, "mr_client", "mr_client_id");
+                               mr_clusters = new DBMap<>(MR_Cluster.class, "mr_cluster", "dcae_location_name");
+                               feeds = new DBMap<>(Feed.class, "feed", "feed_id");
                                TableHandler.setSpecialCase("topic", "replication_case", new TopicReplicationTypeHandler());
-                               topics = new DBMap<Topic>(Topic.class, "topic", "fqtn");                        
+                               topics = new DBMap<>(Topic.class, "topic", "fqtn");                     
                                TableHandler.setSpecialCase("mirror_maker", "topics", new MirrorTopicsHandler());
-                               mirrors = new DBMap<MirrorMaker>(MirrorMaker.class, "mirror_maker", "mm_name");
+                               mirrors = new DBMap<>(MirrorMaker.class, "mirror_maker", "mm_name");
                        } catch (Exception e) {
                                errorLogger.error("Error initializing database access " + e, e);
                                System.exit(1);
@@ -193,15 +189,15 @@ public class DatabaseClass extends BaseLoggingClass {
                                        dmaap.setAccessKeyOwner(nd.getAccessKeyOwner());
                                }
                        };
-                       dcaeLocations = new HashMap<String, DcaeLocation>();
-                       dr_nodes = new HashMap<String, DR_Node>();
-                       dr_pubs = new HashMap<String, DR_Pub>();
-                       dr_subs = new HashMap<String, DR_Sub>();
-                       mr_clients = new HashMap<String, MR_Client>();
-                       mr_clusters = new HashMap<String, MR_Cluster>();
-                       feeds = new HashMap<String, Feed>();
-                       topics = new HashMap<String, Topic>();
-                       mirrors = new HashMap<String, MirrorMaker>();
+                       dcaeLocations = new HashMap<>();
+                       dr_nodes = new HashMap<>();
+                       dr_pubs = new HashMap<>();
+                       dr_subs = new HashMap<>();
+                       mr_clients = new HashMap<>();
+                       mr_clusters = new HashMap<>();
+                       feeds = new HashMap<>();
+                       topics = new HashMap<>();
+                       mirrors = new HashMap<>();
                }
                dmaap.init(new Dmaap("0", "", "", "", "", "", "", ""));
                // check for, and set up initial data, if it isn't already there
@@ -217,11 +213,12 @@ public class DatabaseClass extends BaseLoggingClass {
                        dmaap.update(dmx);
                }
                } catch (Exception e) {
+                       errorLogger.error("Error", e);
                        errorLogger.error(DmaapbcLogMessageEnum.DB_UPDATE_ERROR, e.getMessage());
                }
        }
        
-       public synchronized static String getNextClientId() {
+       public static synchronized String getNextClientId() {
                
                long id = System.currentTimeMillis();
                if ( id <= lastTime ) {
index 2c52b0d..1f1b078 100644 (file)
@@ -23,20 +23,12 @@ package org.onap.dmaap.dbcapi.database;
 import java.io.*;
 import java.sql.*;
 
-import org.apache.log4j.Logger;
-
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-
-import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
+;
 
 public class LoadSchema        {
        private static final EELFLogger logger = EELFManager.getInstance().getLogger(LoadSchema.class);
-       private static final EELFLogger appLogger = EELFManager.getInstance().getApplicationLogger();
-       private static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
-       private static final EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
-       private static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
-       private static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
        
        static int getVer(Statement s) throws SQLException {
                ResultSet rs = null;
@@ -66,6 +58,7 @@ public class LoadSchema       {
                                stmt.execute(cmd);
                                logger.info("SCHEMA: " + cmd);
                        } catch (SQLException sqle) {
+                               logger.error("Error", sqle);
                                        throw sqle;
                        }
                        
@@ -74,7 +67,9 @@ public class LoadSchema       {
                        int newver = -1;
                        try {
                                newver = getVer(stmt);
-                       } catch (Exception e) {}
+                       } catch (Exception e) {
+                               logger.error("Error", e);
+                       }
                        logger.info("Database schema currently at version " + newver++);
                        
 
@@ -126,8 +121,20 @@ public class LoadSchema    {
                } catch (IOException ioe) {
                        throw new SQLException(ioe);
                } finally {
-                       if (stmt != null) { try { stmt.close(); } catch (Exception e) {}}
-                       if (c != null) { try { c.close(); } catch (Exception e) {}}
+                       if (stmt != null) { 
+                               try { 
+                                       stmt.close(); 
+                               } catch (Exception e) {
+                                       logger.error("Error", e);
+                               }
+                       }
+                       if (c != null) { 
+                               try { 
+                                       c.close(); 
+                                       } catch (Exception e) {
+                                               logger.error("Error", e);
+                                       }
+                               }
                }
        }
        public static void main(String[] args) throws Exception {
index c83b6be..fc68aa2 100644 (file)
@@ -40,22 +40,10 @@ class TableHandler<C>       {
        protected String        initstmt;
        protected Class<C>      cls;
        protected DBFieldHandler[] fields;
-       private static Map<String, Map<String, DBFieldHandler.SqlOp>> exceptions = new HashMap<String, Map<String, DBFieldHandler.SqlOp>>();
-       public static void setSpecialCase(String dbtabname, String dbfldname, DBFieldHandler.SqlOp handler) {
-               Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname);
-               if (m == null) {
-                       m = new HashMap<String, DBFieldHandler.SqlOp>();
-                       exceptions.put(dbtabname, m);
-               }
-               m.put(dbfldname, handler);
-       }
-       public static DBFieldHandler.SqlOp getSpecialCase(String dbtabname, String dbfldname) {
-               Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname);
-               if (m != null) {
-                       return(m.get(dbfldname));
-               }
-               return(null);
-       }
+       private static Map<String, Map<String, DBFieldHandler.SqlOp>> exceptions = new HashMap<>();
+       private String select = "SELECT ";
+       private String from = " FROM ";
+       
        protected TableHandler(Class<C> cls, String tabname, String keyname) throws Exception {
                this(ConnectionFactory.getDefaultInstance(), cls, tabname, keyname);
        }
@@ -71,14 +59,31 @@ class TableHandler<C>       {
                        }
                }
        }
+       
+       public static void setSpecialCase(String dbtabname, String dbfldname, DBFieldHandler.SqlOp handler) {
+               Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname);
+               if (m == null) {
+                       m = new HashMap<>();
+                       exceptions.put(dbtabname, m);
+               }
+               m.put(dbfldname, handler);
+       }
+       public static DBFieldHandler.SqlOp getSpecialCase(String dbtabname, String dbfldname) {
+               Map<String, DBFieldHandler.SqlOp> m = exceptions.get(dbtabname);
+               if (m != null) {
+                       return(m.get(dbfldname));
+               }
+               return(null);
+       }
+       
        private void setup(DatabaseMetaData dmd, Class<C> cls, String tabname, String keyname) throws Exception {
                this.cls = cls;
-               Vector<DBFieldHandler> h = new Vector<DBFieldHandler>();
+               Vector<DBFieldHandler> h = new Vector<>();
                String qualifiedTableName = String.format( "%s.%s", cf.getSchema(), tabname );
                ResultSet rs = dmd.getColumns("", cf.getSchema(), tabname, null);
-               StringBuffer sb1 = new StringBuffer();
-               StringBuffer sb2 = new StringBuffer();
-               StringBuffer sb3 = new StringBuffer();
+               StringBuilder sb1 = new StringBuilder();
+               StringBuilder sb2 = new StringBuilder();
+               StringBuilder sb3 = new StringBuilder();
                int     count = 0;
                while (rs.next()) {
                        if (!rs.getString(3).equals(tabname)) {
@@ -109,13 +114,13 @@ class TableHandler<C>     {
                        h.add(new DBFieldHandler(cls, keyname, count, getSpecialCase(tabname, keyname)));
                        delstmt = "DELETE FROM " + qualifiedTableName + " WHERE " + keyname + " = ?";
                        insorreplstmt = "INSERT INTO " + qualifiedTableName + " (" + clist + ", " + keyname + ") VALUES (" + qlist + ", ?) ON CONFLICT(" + keyname + ") DO UPDATE SET (" + clist + ") = (" + elist + ")";
-                       getstmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName + " WHERE " + keyname + " = ?";
-                       liststmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName;
+                       getstmt = select + clist + ", " + keyname + from + qualifiedTableName + " WHERE " + keyname + " = ?";
+                       liststmt = select + clist + ", " + keyname + from + qualifiedTableName;
                } else {
                        delstmt = "DELETE FROM " + qualifiedTableName;
                        initstmt = "INSERT INTO " + qualifiedTableName + " (" + clist + ") VALUES (" + qlist + ")";
                        insorreplstmt = "UPDATE " + qualifiedTableName + " SET (" + clist + ") = (" + qlist + ")";
-                       getstmt = "SELECT " + clist + ", " + keyname + " FROM " + qualifiedTableName;
+                       getstmt = select + clist + ", " + keyname + from + qualifiedTableName;
                }
                fields = h.toArray(new DBFieldHandler[h.size()]);
        }
index 5a768c5..e089881 100644 (file)
@@ -42,32 +42,6 @@ public class DR_Sub extends DmaapObject {
        private boolean use100;
        private boolean suspended;
        private String owner;
-       
-       public String getOwner() {
-               return owner;
-       }
-
-       public void setOwner(String owner) {
-               this.owner = owner;
-       }
-
-       public boolean isSuspended() {
-               return suspended;
-       }
-
-       public void setSuspended(boolean suspended) {
-               this.suspended = suspended;
-       }
-
-
-
-       public boolean isUse100() {
-               return use100;
-       }
-
-       public void setUse100(boolean use100) {
-               this.use100 = use100;
-       }
 
        public DR_Sub() {
 
@@ -125,6 +99,32 @@ public class DR_Sub extends DmaapObject {
 
                logger.info( "new DR_Sub returning");
        }
+       
+       public String getOwner() {
+               return owner;
+       }
+
+       public void setOwner(String owner) {
+               this.owner = owner;
+       }
+
+       public boolean isSuspended() {
+               return suspended;
+       }
+
+       public void setSuspended(boolean suspended) {
+               this.suspended = suspended;
+       }
+
+
+
+       public boolean isUse100() {
+               return use100;
+       }
+
+       public void setUse100(boolean use100) {
+               this.use100 = use100;
+       }
 
        public String getDcaeLocationName() {
                return dcaeLocationName;
index 8248ef1..b4b5e2e 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.log4j.Logger;
 
 @XmlRootElement
 public class DcaeLocation extends DmaapObject {
-       static final Logger logger = Logger.getLogger(MR_Cluster.class);
+       static final Logger errorLogger = Logger.getLogger(MR_Cluster.class);
        private String clli;
        private String dcaeLayer;
        private String dcaeLocationName;
index 166fc21..06b6194 100644 (file)
@@ -48,17 +48,17 @@ public class MR_Cluster extends DmaapObject {
        private static  String defaultTargetReplicationPort;
        
        private static void setDefaults() {
-               boolean been_here = false;
+               /* boolean been_here = false;
                if ( been_here ) {
                        return;
-               }
+               } */
                DmaapConfig dc = (DmaapConfig)DmaapConfig.getConfig();
                defaultTopicProtocol = dc.getProperty("MR.TopicProtocol", "https");
                defaultTopicPort = dc.getProperty( "MR.TopicPort", "3905");
                defaultReplicationGroup = dc.getProperty( "MR.ReplicationGroup", "" );
                defaultSourceReplicationPort = dc.getProperty( "MR.SourceReplicationPort", "2181");
                defaultTargetReplicationPort = dc.getProperty( "MR.TargetReplicationPort", "9092");
-               been_here = true;
+               // been_here = true;
        }
 
 
index ab0e262..9dafb55 100644 (file)
@@ -25,15 +25,15 @@ import java.io.IOException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 
+import org.apache.log4j.Logger;
 import org.onap.dmaap.dbcapi.authentication.AuthenticationErrorException;
 import org.onap.dmaap.dbcapi.service.ApiService;
-import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
 
 @Authorization
 public class AuthorizationFilter implements ContainerRequestFilter   {
        
-
+       private Logger logger = Logger.getLogger(AuthorizationFilter.class.getName());
        
        @Override
        public void filter(ContainerRequestContext requestContext)
@@ -48,9 +48,11 @@ public class AuthorizationFilter implements ContainerRequestFilter   {
                try {
                        apiResp.checkAuthorization();
                } catch ( AuthenticationErrorException ae ) {
+                       logger.error("Error", ae);
                        requestContext.abortWith( apiResp.unauthorized( apiResp.getErr().getMessage() ) );
                        return ;
                } catch ( Exception e ) {
+                       logger.error("Error", e);
                        requestContext.abortWith( apiResp.unavailable() ); 
                        return;
                }
index 06319de..bcdb4b3 100644 (file)
@@ -196,7 +196,7 @@ public class DR_PubResource extends BaseLoggingClass {
                for( Iterator<DR_Pub> i = pubs.iterator(); i.hasNext(); ) {
                        DR_Pub listItem = i.next();
                        if ( listItem.getPubId().equals(id)) {
-                               pubs.remove( listItem );
+                               i.remove();
                        }
                }
                fnew.setPubs(pubs);
index 95f9d33..cab48ca 100644 (file)
@@ -96,7 +96,7 @@ public class TopicResource extends BaseLoggingClass {
        public Response  addTopic( 
                        Topic topic
                        ) {
-               logger.info( "addTopic request: " + String.valueOf(topic) );
+               logger.info( "addTopic request: " + topic );
                ApiService check = new ApiService();
 
                try {
@@ -104,10 +104,10 @@ public class TopicResource extends BaseLoggingClass {
                        check.required( "topicDescription", topic.getTopicDescription(), "" );
                        check.required( "owner", topic.getOwner(), "" );
                } catch( RequiredFieldException rfe ) {
+                       logger.error("Error", rfe);
                        return check.error();
                }
                
-               //String repReq = topic.getReplicationRequest();
                ReplicationType t = topic.getReplicationCase();
                if ( t == null || t == ReplicationType.REPLICATION_NOT_SPECIFIED ) {
                        topic.setReplicationCase( mr_topicService.reviewTopic(topic));
@@ -163,6 +163,7 @@ public class TopicResource extends BaseLoggingClass {
                try {
                        check.required( "fqtn", id, "" );
                } catch( RequiredFieldException rfe ) {
+                       logger.error("Error", rfe);
                        return check.error();
                }
                
@@ -192,6 +193,7 @@ public class TopicResource extends BaseLoggingClass {
                try {
                        check.required( "topicName", id, "^\\S+$" );  //no white space allowed in topicName
                } catch( RequiredFieldException rfe ) {
+                       logger.error("Error", rfe);
                        return check.error();
                }
                Topic mrc =  mr_topicService.getTopic( id, check.getErr() );
index 519fa4a..748eedc 100644 (file)
@@ -69,6 +69,9 @@ public class JettyServer extends BaseLoggingClass {
                boolean allowHttp = Boolean.valueOf(params.getProperty("HttpAllowed", "false"));
        serverLogger.info( "port params: http=" + httpPort + " https=" + sslPort );
        serverLogger.info( "allowHttp=" + allowHttp );
+        String keystore=null;
+        String keystorePwd = null;
+        String keyPwd = null;
         
         // HTTP Server
 
@@ -79,50 +82,50 @@ public class JettyServer extends BaseLoggingClass {
 
        
        
-        ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http_config));
-        httpConnector.setPort(httpPort);  
-        httpConnector.setIdleTimeout(30000);
-  
-        
-        // HTTPS Server
-        HttpConfiguration https_config = new HttpConfiguration(http_config);
-        https_config.addCustomizer(new SecureRequestCustomizer());
-        SslContextFactory sslContextFactory = new SslContextFactory();
-        String keystore = params.getProperty("KeyStoreFile", "etc/keystore");
-        logger.info( "https Server using keystore at " + keystore );
-        String keystorePwd = params.getProperty( "KeyStorePassword", "changeit");
-        String keyPwd = params.getProperty("KeyPassword", "changeit");
-
-        sslContextFactory.setKeyStorePath(keystore);
-        sslContextFactory.setKeyStorePassword(keystorePwd);
-        sslContextFactory.setKeyManagerPassword(keyPwd);     
-
-  
-               ServerConnector sslConnector = null;
-               if ( sslPort != 0 ) {
-                       sslConnector = new ServerConnector(server,
-                                       new SslConnectionFactory(sslContextFactory, "http/1.1"),
-                                       new HttpConnectionFactory(https_config));
-                       sslConnector.setPort(sslPort);
-               if ( allowHttp ) {
-               logger.info("Starting httpConnector on port " + httpPort );
-               logger.info("Starting sslConnector on port " +   sslPort + " for https");
-                       server.setConnectors( new Connector[] { httpConnector, sslConnector });
-               } else {
-               logger.info("NOT starting httpConnector because HttpAllowed param is " + allowHttp  );  
-               logger.info("Starting sslConnector on port " +   sslPort + " for https");
-                       server.setConnectors( new Connector[] { sslConnector });        
-               }
+        try(ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http_config))) {
+                       httpConnector.setPort(httpPort);
+                       httpConnector.setIdleTimeout(30000);
+
+
+                       // HTTPS Server
+
+                       HttpConfiguration https_config = new HttpConfiguration(http_config);
+                       https_config.addCustomizer(new SecureRequestCustomizer());
+                       SslContextFactory sslContextFactory = new SslContextFactory();
+                       keystore = params.getProperty("KeyStoreFile", "etc/keystore");
+                       logger.info("https Server using keystore at " + keystore);
+                       keystorePwd = params.getProperty("KeyStorePassword", "changeit");
+                       keyPwd = params.getProperty("KeyPassword", "changeit");
+
+
+                       sslContextFactory.setKeyStorePath(keystore);
+                       sslContextFactory.setKeyStorePassword(keystorePwd);
+                       sslContextFactory.setKeyManagerPassword(keyPwd);
+
+
+                       if (sslPort != 0) {
+                try(ServerConnector sslConnector = new ServerConnector(server,
+                                               new SslConnectionFactory(sslContextFactory, "http/1.1"),
+                                               new HttpConnectionFactory(https_config))) {
+                    sslConnector.setPort(sslPort);
+                    if (allowHttp) {
+                        logger.info("Starting httpConnector on port " + httpPort);
+                        logger.info("Starting sslConnector on port " + sslPort + " for https");
+                        server.setConnectors(new Connector[]{httpConnector, sslConnector});
+                    } else {
+                        logger.info("NOT starting httpConnector because HttpAllowed param is " + allowHttp);
+                        logger.info("Starting sslConnector on port " + sslPort + " for https");
+                        server.setConnectors(new Connector[]{sslConnector});
+                    }
+                }
+                       } else {
+                               serverLogger.info("NOT starting sslConnector on port " + sslPort + " for https");
+                               if (allowHttp) {
+                                       serverLogger.info("Starting httpConnector on port " + httpPort);
+                                       server.setConnectors(new Connector[]{httpConnector});
+                               }
+                       }
                }
-               else {
-            serverLogger.info("NOT starting sslConnector on port " +   sslPort + " for https");
-               if ( allowHttp ) {
-               serverLogger.info("Starting httpConnector on port " + httpPort );
-                       server.setConnectors( new Connector[] { httpConnector });
-                       } 
-        } 
  
         // Set context for servlet.  This is shared for http and https
                ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
index 3943419..26def91 100644 (file)
@@ -197,7 +197,9 @@ public class TopicService extends BaseLoggingClass {
                                return null;
                        }
                }
-               mr_topics.put( ntopic.getFqtn(), ntopic );
+               if(ntopic != null) {
+                       mr_topics.put( ntopic.getFqtn(), ntopic );
+               }
                err.setCode(Status.OK.getStatusCode());
                return ntopic;
        }
index e287acb..776a4b4 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.log4j.Logger;
 @XmlRootElement
 public class DmaapTimestamp {
        static final Logger logger = Logger.getLogger(DmaapTimestamp.class);
-       private static Calendar cal = Calendar.getInstance();
+       private Calendar cal = Calendar.getInstance();
        private Date stamp;
        
        public DmaapTimestamp() {
index 8add583..815d79c 100644 (file)
@@ -27,7 +27,7 @@
 
 major=1
 minor=0
-patch=14
+patch=15
 base_version=${major}.${minor}.${patch}
 
 # Release must be completed with git revision # in Jenkins