use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method mapSolaceURLsToStoreDTO.
/**
* Sets the Endpoint URLs For Solace API according to the protocols
*
* @param organizationName Solace broker organization name
* @param environmentName Name of the Solace environment
* @param availableProtocols List of available protocols
* @return List containing AdditionalSubscriptionInfoSolaceURLsDTO
* @throws APIManagementException if error occurred when retrieving protocols URLs from Solace broker
*/
private static List<AdditionalSubscriptionInfoSolaceURLsDTO> mapSolaceURLsToStoreDTO(String organizationName, String environmentName, List<String> availableProtocols) throws APIManagementException {
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = null;
// Get Solace broker environment details
for (Map.Entry<String, Environment> entry : gatewayEnvironments.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
if (solaceEnvironment != null) {
List<SolaceURLsDTO> solaceURLsDTOEntries = SolaceStoreUtils.getSolaceURLsInfo(solaceEnvironment, organizationName, environmentName, availableProtocols);
List<AdditionalSubscriptionInfoSolaceURLsDTO> solaceURLsDTOs = new ArrayList<>();
for (SolaceURLsDTO entry : solaceURLsDTOEntries) {
AdditionalSubscriptionInfoSolaceURLsDTO subscriptionInfoSolaceProtocolURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
subscriptionInfoSolaceProtocolURLsDTO.setProtocol(entry.getProtocol());
subscriptionInfoSolaceProtocolURLsDTO.setEndpointURL(entry.getEndpointURL());
solaceURLsDTOs.add(subscriptionInfoSolaceProtocolURLsDTO);
}
return solaceURLsDTOs;
} else {
throw new APIManagementException("Solace Environment configurations are not provided properly");
}
}
use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.
the class AdditionalSubscriptionInfoMappingUtil method setSolaceEnvironmentDetailsForSubscription.
/**
* Sets the solace environment details For Solace API subscription with the protocol details
*
* @param api API object
* @param tenantDomain Tenant Domain
* @return List containing AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO
* @throws APIManagementException if error occurred when retrieving protocols URLs
*/
private static List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> setSolaceEnvironmentDetailsForSubscription(API api, String tenantDomain) throws APIManagementException {
APIDTO apidto = APIMappingUtil.fromAPItoDTO(api, tenantDomain);
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
List<APIRevisionDeployment> revisionDeployments = apiConsumer.getAPIRevisionDeploymentListOfAPI(apidto.getId());
List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEndpointURLsList = new ArrayList<>();
// Get revision list of APIs and check Solace deployment environment
for (APIRevisionDeployment revisionDeployment : revisionDeployments) {
if (revisionDeployment.isDisplayOnDevportal()) {
if (gatewayEnvironments != null) {
// Deployed environment
Environment environment = gatewayEnvironments.get(revisionDeployment.getDeployment());
if (environment != null) {
// Set solace environment details if deployment is in Solace broker
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(environment.getProvider())) {
AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceEnvironmentDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
solaceEnvironmentDTO.setEnvironmentName(environment.getName());
solaceEnvironmentDTO.setEnvironmentDisplayName(environment.getDisplayName());
solaceEnvironmentDTO.setOrganizationName(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION));
// Get Solace endpoint URLs for provided protocols
solaceEnvironmentDTO.setSolaceURLs(mapSolaceURLsToStoreDTO(environment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION), environment.getName(), apidto.getAsyncTransportProtocols()));
solaceEndpointURLsList.add(solaceEnvironmentDTO);
}
}
}
}
}
return solaceEndpointURLsList;
}
use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.
the class SolaceAdminApis method renameApplication.
/**
* Rename application in Solace Broker
*
* @param organization name of the Organization
* @param application Application object to be renamed
* @return CloseableHttpResponse of the DELETE call
*/
public CloseableHttpResponse renameApplication(String organization, Application application) {
URL serviceEndpointURL = new URL(baseUrl);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
HttpPatch httpPatch = new HttpPatch(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + application.getUUID());
httpPatch.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
httpPatch.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
org.json.JSONObject requestBody = buildRequestBodyForRenamingApp(application);
StringEntity params = null;
try {
params = new StringEntity(requestBody.toString());
httpPatch.setEntity(params);
return APIUtil.executeHTTPRequest(httpPatch, httpClient);
} catch (IOException | APIManagementException e) {
log.error(e.getMessage());
}
return null;
}
use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.
the class SolaceAdminApis method deleteApiProduct.
/**
* Delete API Product from Solace Broker
*
* @param organization name of the Organization
* @param apiProductName name of the API product
* @return CloseableHttpResponse of the DELETE call
*/
public CloseableHttpResponse deleteApiProduct(String organization, String apiProductName) {
URL serviceEndpointURL = new URL(baseUrl);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
HttpDelete httpDelete = new HttpDelete(baseUrl + "/" + organization + "/apiProducts/" + apiProductName);
httpDelete.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
try {
return APIUtil.executeHTTPRequest(httpDelete, httpClient);
} catch (IOException | APIManagementException e) {
log.error(e.getMessage());
}
return null;
}
use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.
the class SolaceKeyGenNotifier method syncSolaceApplicationClientId.
/**
* Syncing consumer key of the dev portal applications with applications on the Solace broker
*
* @param event ApplicationEvent to sync Solace applications with dev portal applications
* @throws NotifierException if error occurs when patching applications on the Solace broker
*/
private void syncSolaceApplicationClientId(ApplicationRegistrationEvent event) throws NotifierException {
// get list of subscribed APIs in the application
try {
Application application = apiMgtDAO.getApplicationByUUID(event.getApplicationUUID());
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
Set<SubscribedAPI> subscriptions = apiMgtDAO.getSubscribedAPIs(application.getSubscriber(), application.getName(), application.getGroupId());
boolean isContainsSolaceApis = false;
String organizationNameOfSolaceDeployment = null;
labelOne: // Check whether the application needs to be updated has a Solace API subscription
for (SubscribedAPI api : subscriptions) {
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentByApiUUID(api.getIdentifier().getUUID());
for (APIRevisionDeployment deployment : deployments) {
if (gatewayEnvironments.containsKey(deployment.getDeployment())) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(gatewayEnvironments.get(deployment.getDeployment()).getProvider())) {
isContainsSolaceApis = true;
organizationNameOfSolaceDeployment = gatewayEnvironments.get(deployment.getDeployment()).getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_ORGANIZATION);
break labelOne;
}
}
}
}
// Patching consumerKey to Solace application using Admin Apis
if (isContainsSolaceApis) {
if (application.getKeys() != null) {
String consumerSecret = null;
APIConsumer apiConsumer = APIManagerFactory.getInstance().getAPIConsumer(CarbonContext.getThreadLocalCarbonContext().getUsername());
Set<APIKey> consumerKeys = apiConsumer.getApplicationKeysOfApplication(application.getId());
for (APIKey key : consumerKeys) {
if (key.getConsumerKey().equals(event.getConsumerKey())) {
consumerSecret = key.getConsumerSecret();
}
}
SolaceNotifierUtils.patchSolaceApplicationClientId(organizationNameOfSolaceDeployment, application, event.getConsumerKey(), consumerSecret);
} else {
throw new NotifierException("Application keys are not found in the application : " + application.getName());
}
}
} catch (APIManagementException e) {
throw new NotifierException(e.getMessage());
}
}
Aggregations