Search in sources :

Example 16 with ErrorMessage

use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImpl method updateApplicationPolicy.

@Override
public void updateApplicationPolicy(ApplicationPolicy policy) throws APIManagementException {
    try {
        policyDAO.updateApplicationPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policy.getUuid(), policy.getPolicyName(), false);
        apiGateway.updatePolicy(policyValidationData);
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't update Application policy for uuid: " + policy.getUuid();
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData)

Example 17 with ErrorMessage

use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImpl method updateSubscriptionPolicy.

@Override
public void updateSubscriptionPolicy(SubscriptionPolicy policy) throws APIManagementException {
    try {
        policyDAO.updateSubscriptionPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policy.getUuid(), policy.getPolicyName(), policy.isStopOnQuotaReach());
        apiGateway.updatePolicy(policyValidationData);
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't update Subscription policy for uuid: " + policy.getUuid();
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData)

Example 18 with ErrorMessage

use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImpl method deletePolicyByUuid.

@Override
public void deletePolicyByUuid(String uuid, PolicyLevel policyLevel) throws APIManagementException {
    try {
        policyDAO.deletePolicyByUuid(policyLevel, uuid);
        PolicyValidationData policyValidationData = new PolicyValidationData(uuid, "", false);
        apiGateway.deletePolicy(policyValidationData);
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't delete policy with id: " + uuid + ", level: " + policyLevel;
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData)

Example 19 with ErrorMessage

use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImpl method addSubscriptionPolicy.

@Override
public String addSubscriptionPolicy(SubscriptionPolicy policy) throws APIManagementException {
    try {
        String policyUuid = policy.getUuid();
        if (policyUuid == null) {
            if (log.isDebugEnabled()) {
                log.debug("Policy id is null, hence generating a new UUID for the policy with name: " + policy.getPolicyName());
            }
            policyUuid = UUID.randomUUID().toString();
            policy.setUuid(policyUuid);
        }
        policyDAO.addSubscriptionPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), policy.isStopOnQuotaReach());
        apiGateway.addPolicy(policyValidationData);
        return policyUuid;
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't add Subscription policy for uuid: " + policy.getUuid();
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData)

Example 20 with ErrorMessage

use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage 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

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)209 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)153 HashMap (java.util.HashMap)142 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)135 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)101 ArrayList (java.util.ArrayList)73 SQLException (java.sql.SQLException)65 IOException (java.io.IOException)63 Connection (java.sql.Connection)62 URISyntaxException (java.net.URISyntaxException)56 Map (java.util.Map)53 UserStoreException (org.wso2.carbon.user.api.UserStoreException)52 URI (java.net.URI)50 API (org.wso2.carbon.apimgt.api.model.API)46 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)43 PreparedStatement (java.sql.PreparedStatement)41 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)40 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)40 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)36 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)35