// Get and initialize a basic auth client private OslcClient2 getBasicAuthClient(FriendInfo friend) { BasicAuthClient basicClient = null; String exMessage = ""; try { JazzRootServicesHelper2 helper = new JazzRootServicesHelper2( HandlerSettings.ClientUri, HandlerSettings.RootservicesUri); // Specific code - logging in basicClient = new BasicAuthClient(friend.EncodedCredentials); HttpClient client = basicClient.GetHttpClient(); // Get the Creation Factory for mhweb String user = friend.GetBasicAuthUser(); String serviceProviderUrl = basicClient.LookupServiceProviderUrl( helper.GetCatalogUrl(), "mhweb", HandlerSettings.getRESTHeaders(user)); HandlerSettings.CreationFactoryUri = basicClient.LookupCreationFactory( serviceProviderUrl, Constants.ENTERPRISE_CHANGE_MANAGEMENT_DOMAIN, Constants.TYPE_ENTERPRISE_CHANGE_REQUEST, HandlerSettings.getRESTHeaders(user)); } catch (Exception ex) { basicClient = null; exMessage = ex.Message; } if (basicClient == null || exMessage.Length > 0) { HandlerSettings.LogMessage( String.Format( "Failed to get a httpClient for basic auth." + "\nUsing client uri: {0}" + "\nUsing rootservices uri: {1}" + "\nMessage: {2}", HandlerSettings.ClientUri, HandlerSettings.RootservicesUri, exMessage), HandlerSettings.LoggingLevel.ERROR); } return(basicClient); }
// Get and initialize an oauth client private OslcClient2 getOAuthClient(FriendInfo friend) { JazzOAuthClient2 oauthClient = null; String exMessage = ""; try { JazzRootServicesHelper2 helper = new JazzRootServicesHelper2( HandlerSettings.ClientUri, HandlerSettings.RootservicesUri); oauthClient = helper.InitOAuthClient2(friend.ConsumerKey, friend.ConsumerSecret, friend.AccessToken, friend.AccessTokenSecret); // Get the Creation Factory for mhweb String serviceProviderUrl = oauthClient.LookupServiceProviderUrl(helper.GetCatalogUrl(), "mhweb"); HandlerSettings.CreationFactoryUri = oauthClient.LookupCreationFactory( serviceProviderUrl, Constants.ENTERPRISE_CHANGE_MANAGEMENT_DOMAIN, Constants.TYPE_ENTERPRISE_CHANGE_REQUEST); } catch (Exception ex) { oauthClient = null; exMessage = ex.Message; } if (oauthClient == null || exMessage.Length > 0) { HandlerSettings.LogMessage( String.Format( "Failed to get a httpClient for oauth." + "\nUsing client uri: {0}" + "\nUsing rootservices uri: {1}" + "\nMessage: {2}", HandlerSettings.ClientUri, HandlerSettings.RootservicesUri, exMessage), HandlerSettings.LoggingLevel.ERROR); } return(oauthClient); }