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;
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 ) {
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 {
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 ) {
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");