use of org.wso2.carbon.apimgt.solace.SolaceAdminApis in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method patchSolaceApplicationClientId.
/**
* Get and patch client id for Solace application
*
* @param organization Name of the Organization
* @param application Solace application
* @param consumerKey Consumer key to be used when patching
* @param consumerSecret Consumer secret to be used when patching
* @throws APIManagementException If the Solace env configuration if not provided properly
*/
public static void patchSolaceApplicationClientId(String organization, Application application, String consumerKey, String consumerSecret) throws APIManagementException {
SolaceAdminApis solaceAdminApis = SolaceNotifierUtils.getSolaceAdminApis();
if (log.isDebugEnabled()) {
log.info("Identified as Solace Application. Patching CliendID and Secret in solace application.....");
}
CloseableHttpResponse response = solaceAdminApis.patchClientIdForApplication(organization, application, consumerKey, consumerSecret);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
log.info("CliendID and Secret patched successfully for " + application.getName() + " Solace application");
} else {
log.error("Error while patching clientID for Solace application. : " + response.getStatusLine().toString());
}
}
use of org.wso2.carbon.apimgt.solace.SolaceAdminApis in project carbon-apimgt by wso2.
the class SolaceStoreUtils method getSolaceURLsInfo.
/**
* Get SolaceUrlsInfo using admin APIs and map into DTOs to parse Devportal
*
* @param solaceEnvironment Solace environment Object
* @param organizationName Solace broker organization name
* @param environmentName Name of the Solace environment
* @param availableProtocols List of available protocols
* @return List of SolaceURLsDTO
* @throws APIManagementException if error occurred when creating
*/
public static List<SolaceURLsDTO> getSolaceURLsInfo(Environment solaceEnvironment, String organizationName, String environmentName, List<String> availableProtocols) throws APIManagementException {
// Create solace admin APIs instance
SolaceAdminApis solaceAdminApis = new SolaceAdminApis(solaceEnvironment.getServerURL(), solaceEnvironment.getUserName(), solaceEnvironment.getPassword(), solaceEnvironment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_DEV_NAME));
List<SolaceURLsDTO> solaceURLsDTOs = new ArrayList<>();
HttpResponse response = solaceAdminApis.environmentGET(organizationName, environmentName);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String responseString = null;
try {
responseString = EntityUtils.toString(response.getEntity());
org.json.JSONObject jsonObject = new org.json.JSONObject(responseString);
JSONArray protocols = jsonObject.getJSONArray("messagingProtocols");
for (int i = 0; i < protocols.length(); i++) {
org.json.JSONObject protocolDetails = protocols.getJSONObject(i);
String protocolName = protocolDetails.getJSONObject("protocol").getString("name");
// Get solace protocol URLs for available protocols
if (availableProtocols.contains(protocolName)) {
String endpointURI = protocolDetails.getString("uri");
SolaceURLsDTO subscriptionInfoSolaceProtocolURLsDTO = new SolaceURLsDTO();
subscriptionInfoSolaceProtocolURLsDTO.setProtocol(protocolName);
subscriptionInfoSolaceProtocolURLsDTO.setEndpointURL(endpointURI);
solaceURLsDTOs.add(subscriptionInfoSolaceProtocolURLsDTO);
}
}
} catch (IOException e) {
throw new APIManagementException("Error occurred when retrieving protocols URLs from Solace " + "admin apis");
}
}
return solaceURLsDTOs;
}
use of org.wso2.carbon.apimgt.solace.SolaceAdminApis in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method checkApiProductAlreadyDeployedInSolace.
/**
* Check whether the given API product is already deployed in the Solace broker
*
* @param api Name of the API
* @param organization Name of the organization
* @return returns true if the given API product is already deployed in the Solace
* @throws APIManagementException If an error occurs when checking API product availability
*/
private boolean checkApiProductAlreadyDeployedInSolace(API api, String organization) throws IOException, APIManagementException {
Map<String, Environment> environmentMap = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = environmentMap.get(SolaceConstants.SOLACE_ENVIRONMENT);
if (solaceEnvironment != null) {
SolaceAdminApis solaceAdminApis = new SolaceAdminApis(solaceEnvironment.getServerURL(), solaceEnvironment.getUserName(), solaceEnvironment.getPassword(), solaceEnvironment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_DEV_NAME));
String apiNameWithContext = generateApiProductNameForSolaceBroker(api, getThirdPartySolaceBrokerEnvironmentNameOfAPIDeployment(api));
CloseableHttpResponse response = solaceAdminApis.apiProductGet(organization, apiNameWithContext);
if (response != null) {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
log.info("API product found in Solace Broker");
return true;
} else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
log.error("API product not found in Solace broker");
log.error(EntityUtils.toString(response.getEntity()));
throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
} else {
log.error("Cannot find API product in Solace Broker");
log.error(EntityUtils.toString(response.getEntity()));
throw new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
}
}
return false;
} else {
throw new APIManagementException("Solace Environment configurations are not provided properly");
}
}
Aggregations