Search in sources :

Example 11 with ErrorMessage

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

the class PolicyDAOImpl method addApiPolicy.

@Override
public void addApiPolicy(APIPolicy policy) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            addApiPolicy(policy, connection);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String errorMessage = "Error in adding API policy, policy name: " + policy.getPolicyName();
            log.error(errorMessage, e);
            throw new APIMgtDAOException(errorMessage, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String errorMsg = "Error in obtaining DB connection";
        log.error(errorMsg, e);
        throw new APIMgtDAOException(errorMsg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 12 with ErrorMessage

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

the class PolicyDAOImpl method addApplicationPolicy.

@Override
public void addApplicationPolicy(ApplicationPolicy policy) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            addApplicationPolicy(policy, connection);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String errorMessage = "Error in adding Application policy, policy name: " + policy.getPolicyName();
            log.error(errorMessage, e);
            throw new APIMgtDAOException(errorMessage, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String errorMsg = "Error in obtaining DB connection";
        log.error(errorMsg, e);
        throw new APIMgtDAOException(errorMsg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 13 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 addApiPolicy.

@Override
public String addApiPolicy(APIPolicy 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.addApiPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
        apiGateway.addPolicy(policyValidationData);
        return policyUuid;
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't add API 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 14 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 updateBlockConditionStateByUUID.

@Override
public boolean updateBlockConditionStateByUUID(String uuid, Boolean state) throws APIManagementException {
    try {
        if (policyDAO.updateBlockConditionStateByUUID(uuid, state)) {
            BlockConditions blockConditions = getBlockConditionByUUID(uuid);
            apiGateway.updateBlockCondition(blockConditions);
            return true;
        } else {
            return false;
        }
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't update block condition with UUID: " + uuid + ", state: " + state;
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions)

Example 15 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 addApplicationPolicy.

@Override
public String addApplicationPolicy(ApplicationPolicy 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.addApplicationPolicy(policy);
        PolicyValidationData policyValidationData = new PolicyValidationData(policyUuid, policy.getPolicyName(), false);
        apiGateway.addPolicy(policyValidationData);
        return policyUuid;
    } catch (APIMgtDAOException e) {
        String errorMessage = "Couldn't add Application 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)

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