use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addPolicy.
@Override
public void addPolicy(PolicyValidationData policyValidationData) throws GatewayException {
if (policyValidationData != null) {
PolicyEvent policyEvent = new PolicyEvent(APIMgtConstants.GatewayEventTypes.POLICY_CREATE);
policyEvent.setId(policyValidationData.getId());
policyEvent.setName(policyValidationData.getName());
policyEvent.setStopOnQuotaReach(policyValidationData.isStopOnQuotaReach());
publishToThrottleTopic(policyEvent);
if (log.isDebugEnabled()) {
log.debug("Policy : " + policyValidationData.getName() + " add event has been successfully published " + "to broker");
}
}
}
use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method deleteCompositeAPI.
@Override
public void deleteCompositeAPI(CompositeAPI api) throws GatewayException {
// build the message to send
APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
gatewayDTO.setLabels(api.getLabels());
APISummary apiSummary = new APISummary();
apiSummary.setName(api.getName());
apiSummary.setVersion(api.getVersion());
apiSummary.setContext(api.getContext());
apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
gatewayDTO.setApiSummary(apiSummary);
publishToPublisherTopic(gatewayDTO);
}
use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addAPISubscription.
@Override
public void addAPISubscription(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
SubscriptionEvent subscriptionAddEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_CREATE);
subscriptionAddEvent.setSubscriptionsList(subscriptionValidationDataList);
publishToStoreTopic(subscriptionAddEvent);
if (log.isDebugEnabled()) {
log.debug("Subscription created event has been successfully published to broker");
}
}
use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method updateEndpoint.
@Override
public void updateEndpoint(Endpoint endpoint) throws GatewayException {
EndpointEvent dto = new EndpointEvent(APIMgtConstants.GatewayEventTypes.ENDPOINT_UPDATE);
dto.setEndpoint(endpoint);
publishToPublisherTopic(dto);
}
use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.
the class BrokerUtil method publishToTopic.
/**
* Publish to broker topic
*
* @param topicName publishing topic name
* @param gatewayEvent topic message data object
*/
public static void publishToTopic(String topicName, GatewayEvent gatewayEvent) throws GatewayException {
TopicSession topicSession = null;
Topic topic = null;
TopicPublisher topicPublisher = null;
TopicConnection topicConnection = null;
try {
topicConnection = getTopicConnection();
topicConnection.start();
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = topicSession.createTopic(topicName);
topicPublisher = topicSession.createPublisher(topic);
TextMessage textMessage = topicSession.createTextMessage(new Gson().toJson(gatewayEvent));
topicPublisher.publish(textMessage);
} catch (JMSException e) {
String errorMessage = "Error occurred while publishing " + gatewayEvent.getEventType() + " event to JMS " + "topic :" + topicName;
log.error(errorMessage, e);
throw new GatewayException(errorMessage, ExceptionCodes.GATEWAY_EXCEPTION);
} catch (BrokerException e) {
String errorMessage = "Error occurred while obtaining broker topic connection for topic : " + topicName;
log.error(errorMessage, e);
throw new GatewayException(errorMessage, ExceptionCodes.GATEWAY_EXCEPTION);
} finally {
if (topicPublisher != null) {
try {
topicPublisher.close();
} catch (JMSException e) {
log.error("Error occurred while closing topic publisher for topic : " + topicName);
}
}
if (topicSession != null) {
try {
topicSession.close();
} catch (JMSException e) {
log.error("Error occurred while closing topic session for topic : " + topicName);
}
}
if (topicConnection != null) {
try {
topicConnection.close();
} catch (JMSException e) {
log.error("Error occurred while closing topic connection for topic : " + topicName);
}
}
}
}
Aggregations