Search in sources :

Example 6 with GatewayException

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");
        }
    }
}
Also used : PolicyEvent(org.wso2.carbon.apimgt.core.models.events.PolicyEvent)

Example 7 with GatewayException

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);
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary) APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 8 with GatewayException

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");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Example 9 with GatewayException

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);
}
Also used : EndpointEvent(org.wso2.carbon.apimgt.core.models.events.EndpointEvent)

Example 10 with GatewayException

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);
            }
        }
    }
}
Also used : TopicSession(javax.jms.TopicSession) BrokerException(org.wso2.carbon.apimgt.core.exception.BrokerException) TopicPublisher(javax.jms.TopicPublisher) GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) Gson(com.google.gson.Gson) JMSException(javax.jms.JMSException) Topic(javax.jms.Topic) TopicConnection(javax.jms.TopicConnection) TextMessage(javax.jms.TextMessage)

Aggregations

GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)13 API (org.wso2.carbon.apimgt.core.models.API)12 HashMap (java.util.HashMap)7 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)7 ArrayList (java.util.ArrayList)6 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)6 APIEvent (org.wso2.carbon.apimgt.core.models.events.APIEvent)6 Test (org.junit.Test)5 Broker (org.wso2.carbon.apimgt.core.api.Broker)5 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)4 Test (org.testng.annotations.Test)3 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)3 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)3 ApplicationEvent (org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)3 PolicyEvent (org.wso2.carbon.apimgt.core.models.events.PolicyEvent)3 ThreatProtectionEvent (org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)3