Java Code Examples for org.wso2.carbon.apimgt.api.APIProvider#getGlobalMediationPolicy()

The following examples show how to use org.wso2.carbon.apimgt.api.APIProvider#getGlobalMediationPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PoliciesApiServiceImpl.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a specific global mediation policy by identifier
 *
 * @param mediationPolicyId Mediation policy uuid
 * @param accept            Accept header value
 * @param ifNoneMatch       If-None-Match header value
 * @param ifModifiedSince   If-Modified-Since header value
 * @return returns the matched mediation
 */
@Override
public Response policiesMediationMediationPolicyIdGet(String mediationPolicyId, String accept, String ifNoneMatch
        , String ifModifiedSince, MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
        //Get given global mediation policy
        Mediation mediation = apiProvider.getGlobalMediationPolicy(mediationPolicyId);
        if (mediation != null) {
            MediationDTO mediationDTO = MediationMappingUtil.fromMediationToDTO(mediation);
            return Response.ok().entity(mediationDTO).build();
        } else {
            //If global mediation policy not exists
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_POLICY, mediationPolicyId, log);
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving the global mediation policy with id " + mediationPolicyId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
 
Example 2
Source File: PoliciesApiServiceImpl.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a specific global mediation policy by identifier
 *
 * @param mediationPolicyId Mediation policy uuid
 * @param accept            Accept header value
 * @param ifNoneMatch       If-None-Match header value
 * @param ifModifiedSince   If-Modified-Since header value
 * @return returns the matched mediation
 */
@Override
public Response policiesMediationMediationPolicyIdGet(String mediationPolicyId, String accept,
                                                      String ifNoneMatch, String ifModifiedSince) {
    try {
        APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
        //Get given global mediation policy
        Mediation mediation = apiProvider.getGlobalMediationPolicy(mediationPolicyId);
        if (mediation != null) {
            MediationDTO mediationDTO =
                    MediationMappingUtil.fromMediationToDTO(mediation);
            return Response.ok().entity(mediationDTO).build();
        } else {
            //If global mediation policy not exists
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_POLICY, mediationPolicyId, log);
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving the global mediation policy with id "
                + mediationPolicyId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}