Search in sources :

Example 31 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.

/**
 * Get a list of all threat protection policies
 *
 * @param request
 * @return List of threat protection policies
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
        ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
        for (ThreatProtectionPolicy policy : policyList) {
            listDTO.addListItem(MappingUtil.toThreatProtectionPolicyDTO(policy));
        }
        return Response.ok().entity(listDTO).build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 32 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesThreatProtectionPolicyIdGet.

/**
 * Get a specific threat protection policy
 *
 * @param threatProtectionPolicyId ID of the policy to be retrieved
 * @param request
 * @return Threat protection policy
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesThreatProtectionPolicyIdGet(String threatProtectionPolicyId, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        ThreatProtectionPolicyDTO dto = ThreatProtectionMappingUtil.toThreatProtectionPolicyDTO(apiMgtAdminService.getThreatProtectionPolicy(threatProtectionPolicyId));
        return Response.ok().entity(dto).build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 33 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesThreatProtectionPolicyIdDelete.

/**
 * Delete a threat protection policy
 *
 * @param threatProtectionPolicyId ID of the threat protection policy
 * @param request
 * @return HTTP status 200, 500 if failed to delete the policy
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesThreatProtectionPolicyIdDelete(String threatProtectionPolicyId, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        apiMgtAdminService.deleteThreatProtectionPolicy(threatProtectionPolicyId);
        return Response.ok().build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 34 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesPost.

/**
 * Add a new threat protection policy
 *
 * @param threatProtectionPolicy Threat protection policy
 * @param request
 * @return HTTP Status 200, 500 if there was an error adding policy
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesPost(ThreatProtectionPolicyDTO threatProtectionPolicy, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        apiMgtAdminService.addThreatProtectionPolicy(ThreatProtectionMappingUtil.toThreatProtectionPolicy(threatProtectionPolicy));
        return Response.ok().build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 35 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.

/**
 * Get a list of all threat protection policies
 *
 * @param request
 * @return List of threat protection policies
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
        ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
        for (ThreatProtectionPolicy policy : policyList) {
            listDTO.addListItem(ThreatProtectionMappingUtil.toThreatProtectionPolicyDTO(policy));
        }
        return Response.ok().entity(listDTO).build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 HashMap (java.util.HashMap)8 File (java.io.File)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)7 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)6 CharonException (org.wso2.charon3.core.exceptions.CharonException)6 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)6 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)6 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)6 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)6 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 Test (org.testng.annotations.Test)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)5 AutomationFrameworkException (org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException)5 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)4 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)4