Search in sources :

Example 16 with APIManagementException

use of org.wso2.carbon.apimgt.core.exception.APIManagementException 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 APIManagementException

use of org.wso2.carbon.apimgt.core.exception.APIManagementException 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 APIManagementException

use of org.wso2.carbon.apimgt.core.exception.APIManagementException 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 APIManagementException

use of org.wso2.carbon.apimgt.core.exception.APIManagementException 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 APIManagementException

use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.

the class RestCallUtilImpl method putRequest.

/**
 * {@inheritDoc}
 */
@Override
public HttpResponse putRequest(URI uri, MediaType acceptContentType, List<String> cookies, Entity entity, MediaType payloadContentType) throws APIManagementException {
    if (uri == null) {
        throw new IllegalArgumentException("The URI must not be null");
    }
    if (entity == null) {
        throw new IllegalArgumentException("Entity must not be null");
    }
    if (payloadContentType == null) {
        throw new IllegalArgumentException("Payload content type must not be null");
    }
    HttpURLConnection httpConnection = null;
    try {
        httpConnection = (HttpURLConnection) uri.toURL().openConnection();
        httpConnection.setRequestMethod(APIMgtConstants.FunctionsConstants.PUT);
        httpConnection.setRequestProperty(APIMgtConstants.FunctionsConstants.CONTENT_TYPE, payloadContentType.toString());
        httpConnection.setDoOutput(true);
        if (acceptContentType != null) {
            httpConnection.setRequestProperty(APIMgtConstants.FunctionsConstants.ACCEPT, acceptContentType.toString());
        }
        if (cookies != null && !cookies.isEmpty()) {
            for (String cookie : cookies) {
                httpConnection.addRequestProperty(APIMgtConstants.FunctionsConstants.COOKIE, cookie.split(";", 2)[0]);
            }
        }
        OutputStream outputStream = httpConnection.getOutputStream();
        outputStream.write(entity.toString().getBytes(StandardCharsets.UTF_8));
        outputStream.flush();
        outputStream.close();
        return getResponse(httpConnection);
    } catch (IOException e) {
        throw new APIManagementException("Connection not established properly ", e);
    } finally {
        if (httpConnection != null) {
            httpConnection.disconnect();
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)432 Test (org.testng.annotations.Test)353 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)233 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)202 API (org.wso2.carbon.apimgt.core.models.API)200 Test (org.junit.Test)164 Response (javax.ws.rs.core.Response)160 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)159 HashMap (java.util.HashMap)148 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)146 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)134 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)129 ArrayList (java.util.ArrayList)102 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)100 BeforeTest (org.testng.annotations.BeforeTest)82 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)80 Request (org.wso2.msf4j.Request)80 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)76 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)71