use of org.wso2.carbon.apimgt.core.api.Broker in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method getThirdPartySolaceBrokerEnvironmentNameOfAPIDeployment.
/**
* Get third party Solace broker environment Name for API deployment
*
* @param api Name of the API
* @return String of the name of environment in Solace broker
* @throws APIManagementException is error occurs when getting the name of the environment name
*/
private String getThirdPartySolaceBrokerEnvironmentNameOfAPIDeployment(API api) throws APIManagementException {
apiMgtDAO = ApiMgtDAO.getInstance();
Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
List<APIRevisionDeployment> deployments = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(api.getUuid());
for (APIRevisionDeployment deployment : deployments) {
String environmentName = deployment.getDeployment();
if (gatewayEnvironments.containsKey(environmentName)) {
Environment deployedEnvironment = gatewayEnvironments.get(environmentName);
if (SolaceConstants.SOLACE_ENVIRONMENT.equalsIgnoreCase(deployedEnvironment.getProvider())) {
return environmentName;
}
}
}
return null;
}
use of org.wso2.carbon.apimgt.core.api.Broker 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.core.api.Broker 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");
}
}
use of org.wso2.carbon.apimgt.core.api.Broker in project carbon-apimgt by wso2.
the class TokenRevocationNotifierImpl method sendMessageOnRealtime.
/**
* Method to publish the revoked token on to the realtime message broker
*
* @param revokedToken requested revoked token
* @param properties realtime notifier properties read from the config
*/
@Override
public void sendMessageOnRealtime(String revokedToken, Properties properties) {
// Variables related to Realtime Notifier
String realtimeNotifierTTL = realTimeNotifierProperties.getProperty("ttl", DEFAULT_TTL);
long expiryTimeForJWT = Long.parseLong(properties.getProperty("expiryTime"));
String eventId = properties.getProperty(APIConstants.NotificationEvent.EVENT_ID);
String tokenType = properties.getProperty(APIConstants.NotificationEvent.TOKEN_TYPE);
int tenantId = (int) properties.get(APIConstants.NotificationEvent.TENANT_ID);
Object[] objects = new Object[] { eventId, revokedToken, realtimeNotifierTTL, expiryTimeForJWT, tokenType, tenantId };
EventPublisherEvent tokenRevocationEvent = new EventPublisherEvent(APIConstants.TOKEN_REVOCATION_STREAM_ID, System.currentTimeMillis(), objects);
APIUtil.publishEvent(EventPublisherType.TOKEN_REVOCATION, tokenRevocationEvent, tokenRevocationEvent.toString());
}
use of org.wso2.carbon.apimgt.core.api.Broker in project carbon-apimgt by wso2.
the class WebhooksSubscriptionEventHandler method populateProperties.
/**
* Method to publish the subscription request on to the realtime message broker
*
* @param subscriptionEvent subscription event
* @return Properties subscription properties
*/
private Properties populateProperties(WebhooksSubscriptionEvent subscriptionEvent) throws APIManagementException {
Properties properties = new Properties();
properties.put(APIConstants.Webhooks.API_UUID, subscriptionEvent.getApiUUID());
properties.put(APIConstants.Webhooks.APP_ID, subscriptionEvent.getAppID());
properties.put(APIConstants.Webhooks.TENANT_DOMAIN, subscriptionEvent.getTenantDomain());
properties.put(APIConstants.Webhooks.TENANT_ID, subscriptionEvent.getTenantId());
properties.put(APIConstants.Webhooks.CALLBACK, subscriptionEvent.getCallback());
properties.put(APIConstants.Webhooks.TOPIC, subscriptionEvent.getTopic());
putIfNotNull(properties, APIConstants.Webhooks.SECRET, subscriptionEvent.getSecret());
String leaseSeconds = subscriptionEvent.getLeaseSeconds();
putIfNotNull(properties, APIConstants.Webhooks.LEASE_SECONDS, leaseSeconds);
Date currentTime = new Date();
Timestamp updatedTimestamp = new Timestamp(currentTime.getTime());
subscriptionEvent.setUpdatedTime(updatedTimestamp);
properties.put(APIConstants.Webhooks.UPDATED_AT, updatedTimestamp);
long expiryTime = 0;
if (!StringUtils.isEmpty(leaseSeconds)) {
long leaseSecondsInLong;
try {
leaseSecondsInLong = Long.parseLong(leaseSeconds);
} catch (NumberFormatException e) {
throw new APIManagementException("Error while parsing leaseSeconds param", e);
}
expiryTime = updatedTimestamp.toInstant().plusSeconds(leaseSecondsInLong).toEpochMilli();
}
subscriptionEvent.setExpiryTime(expiryTime);
properties.put(APIConstants.Webhooks.EXPIRY_AT, "" + expiryTime);
properties.put(APIConstants.Webhooks.TIER, "" + subscriptionEvent.getTier());
return properties;
}
Aggregations