Fix cluster object to use http port
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / client / MrTopicConnection.java
index b79b33a..18fdeba 100644 (file)
@@ -27,6 +27,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.ProtocolException;
 import java.net.URL;
+import java.net.HttpURLConnection;
 
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLException;
@@ -41,18 +42,19 @@ import org.onap.dmaap.dbcapi.util.DmaapConfig;
 public class MrTopicConnection extends BaseLoggingClass  {
        private String topicURL;
        
-       private HttpsURLConnection uc;
+       private HttpURLConnection uc;
 
        
        private  String mmProvCred; 
        private String unit_test;
-       
+       private boolean useAAF;
 
 
        public MrTopicConnection(String user, String pwd ) {
                mmProvCred = new String( user + ":" + pwd );
                DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
         unit_test = p.getProperty( "UnitTest", "No" );
+       useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "false"));
        }
        
        public boolean makeTopicConnection( MR_Cluster cluster, String topic, String overrideFqdn ) {
@@ -62,10 +64,13 @@ public class MrTopicConnection extends BaseLoggingClass  {
 
                topicURL = cluster.getTopicProtocol() + "://" + fqdn + ":" + cluster.getTopicPort() + "/events/" + topic ;
 
+               if ( cluster.getTopicProtocol().equals( "https")) {
+                       return makeSecureConnection( topicURL );
+               }
                return makeConnection( topicURL );
        }
 
-       private boolean makeConnection( String pURL ) {
+       private boolean makeSecureConnection( String pURL ) {
                logger.info( "makeConnection to " + pURL );
        
                try {
@@ -80,6 +85,22 @@ public class MrTopicConnection extends BaseLoggingClass  {
             return(false);
         }
 
+       }
+       private boolean makeConnection( String pURL ) {
+               logger.info( "makeConnection to " + pURL );
+       
+               try {
+                       URL u = new URL( pURL );
+                       uc = (HttpURLConnection) u.openConnection();
+                       uc.setInstanceFollowRedirects(false);
+                       logger.info( "open connection to " + pURL );
+                       return(true);
+               } catch (Exception e) {
+            logger.error("Unexpected error during openConnection of " + pURL );
+            e.printStackTrace();
+            return(false);
+        }
+
        }
        
        static String bodyToString( InputStream is ) {
@@ -106,8 +127,10 @@ public class MrTopicConnection extends BaseLoggingClass  {
                try {
                        byte[] postData = postMessage.getBytes();
                        logger.info( "post fields=" + postMessage );
-                       uc.setRequestProperty("Authorization", auth);
-                       logger.info( "Authenticating with " + auth );
+                       if ( useAAF ) {
+                               uc.setRequestProperty("Authorization", auth);
+                               logger.info( "Authenticating with " + auth );
+                       }
                        uc.setRequestMethod("POST");
                        uc.setRequestProperty("Content-Type", "application/json");
                        uc.setRequestProperty( "charset", "utf-8");