Search in sources :

Example 6 with Request

use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.

the class WorkflowsApiServiceImplTestCase method getRequest.

// Sample request to be used by tests
private Request getRequest() throws Exception {
    HTTPCarbonMessage carbonMessage = Mockito.mock(HTTPCarbonMessage.class);
    Request request = new Request(carbonMessage);
    try {
        PowerMockito.whenNew(Request.class).withArguments(carbonMessage).thenReturn(request);
    } catch (Exception e) {
        throw new APIMgtSecurityException("Error while mocking Request Object ", e);
    }
    return request;
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) APIMgtSecurityException(org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException) Request(org.wso2.msf4j.Request) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIMgtSecurityException(org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 7 with Request

use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdPut.

/**
 * Updates/adds a new Application throttle policy to the system
 *
 * @param id          Uuid of the policy.
 * @param body              DTO object including the Policy meta information
 * @param ifMatch           If-Match header value
 * @param ifUnmodifiedSince If-Unmodified-Since header value
 * @param request           msf4j request object
 * @return Response object  response object with the updated application throttle policy resource
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingApplicationIdPut(String id, ApplicationThrottlePolicyDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.application;
    if (log.isDebugEnabled()) {
        log.info("Received Application Policy PUT request " + body + " with tierLevel = " + tierLevel);
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        ApplicationPolicy applicationPolicy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(body);
        applicationPolicy.setUuid(id);
        apiMgtAdminService.updateApplicationPolicy(applicationPolicy);
        return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(apiMgtAdminService.getApplicationPolicyByUuid(id))).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while updating Application Policy. policy uuid: " + id;
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 8 with Request

use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingCustomGet.

/**
 * Retrieves all custom policies.
 *
 * @param ifNoneMatch     If-None-Match header value
 * @param ifModifiedSince If-Modified-Since header value
 * @param request         msf4j request object
 * @return All matched Global Throttle policies to the given request
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingCustomGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    if (log.isDebugEnabled()) {
        log.debug("Received Custom Policy GET request.");
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        List<CustomPolicy> policies = apiMgtAdminService.getCustomRules();
        CustomRuleListDTO customRuleListDTO = CustomPolicyMappingUtil.fromCustomPolicyArrayToListDTO(policies);
        return Response.ok().entity(customRuleListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while retrieving custom policies";
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 9 with Request

use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.

the class WorkflowsApiServiceImpl method workflowsWorkflowReferenceIdGet.

@Override
public Response workflowsWorkflowReferenceIdGet(String workflowReferenceId, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        Workflow workflow = apiMgtAdminService.retrieveWorkflow(workflowReferenceId);
        WorkflowDTO workflowDTO = WorkflowMappingUtil.toWorkflowDTO(workflow);
        return Response.ok().entity(workflowDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while retrieving workflows list";
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow)

Example 10 with Request

use of org.wso2.msf4j.Request in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingCustomRuleIdDelete.

/**
 * Delete a custom rule specified by uuid.
 *
 * @param ruleId            uuid of the policy
 * @param ifMatch           If-Match header value
 * @param ifUnmodifiedSince If-Unmodified-Since header value
 * @param request           msf4j request object
 * @return 200 OK response if successfully deleted the policy
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingCustomRuleIdDelete(String ruleId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    if (log.isDebugEnabled()) {
        log.debug("Received Custom Policy DELETE request with rule ID = " + ruleId);
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        apiMgtAdminService.deleteCustomRule(ruleId);
        return Response.ok().build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while deleting a custom policy uuid : " + ruleId;
        Map<String, String> paramList = new HashMap<>();
        paramList.put(APIMgtConstants.ExceptionsConstants.TIER, ruleId);
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)194 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)143 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)136 Request (org.wso2.msf4j.Request)126 HashMap (java.util.HashMap)106 Response (javax.ws.rs.core.Response)94 Test (org.junit.Test)92 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)89 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)48 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)44 ArrayList (java.util.ArrayList)37 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)37 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)34 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)30 Map (java.util.Map)25 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)24 Application (org.wso2.carbon.apimgt.core.models.Application)23 Test (org.testng.annotations.Test)20 API (org.wso2.carbon.apimgt.core.models.API)17 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)16