Search in sources :

Example 11 with SolaceAdminApis

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());
    }
}
Also used : SolaceAdminApis(org.wso2.carbon.apimgt.solace.SolaceAdminApis) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 12 with SolaceAdminApis

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;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) HttpResponse(org.apache.http.HttpResponse) SolaceURLsDTO(org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO) IOException(java.io.IOException) SolaceAdminApis(org.wso2.carbon.apimgt.solace.SolaceAdminApis) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 13 with SolaceAdminApis

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");
    }
}
Also used : SolaceAdminApis(org.wso2.carbon.apimgt.solace.SolaceAdminApis) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Environment(org.wso2.carbon.apimgt.api.model.Environment) HttpResponseException(org.apache.http.client.HttpResponseException)

Aggregations

SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)13 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)9 Environment (org.wso2.carbon.apimgt.api.model.Environment)6 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)4 HttpResponse (org.apache.http.HttpResponse)3 HttpResponseException (org.apache.http.client.HttpResponseException)3 JSONArray (org.json.JSONArray)3 DeployerException (org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException)2 SolaceURLsDTO (org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO)2 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 List (java.util.List)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)1 AsyncProtocolEndpoint (org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)1 NotifierException (org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)1