use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromHeaderConditionToDTO.
/**
* Converts a Header Condition model object into a DTO
*
* @param headerCondition Header Condition model object
* @return DTO object that was derived from Header Condition model object
*/
public static ThrottleConditionDTO fromHeaderConditionToDTO(HeaderCondition headerCondition) {
ThrottleConditionDTO throttleConditionDTO = new ThrottleConditionDTO();
throttleConditionDTO.setType(PolicyConstants.HEADER_CONDITION_TYPE);
throttleConditionDTO.setHeaderCondition(new HeaderConditionDTO());
throttleConditionDTO = updateFieldsFromConditionToDTO(headerCondition, throttleConditionDTO);
throttleConditionDTO.getHeaderCondition().setHeaderName(headerCondition.getHeaderName());
throttleConditionDTO.getHeaderCondition().setHeaderValue(headerCondition.getValue());
return throttleConditionDTO;
}
use of org.wso2.carbon.messaging.Header 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();
}
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingAdvancedIdGet.
/**
* Get policy by id
* @param Id Uuid of the Advanced policy.
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingAdvancedIdGet(String Id, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.info("Received Advanced Policy Get request. Policy uuid: " + Id);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
APIPolicy policy = apiMgtAdminService.getApiPolicyByUuid(Id);
return Response.status(Response.Status.OK).entity(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(policy)).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while getting Advanced Policy. policy uuid: " + Id;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingCustomPost.
/**
* Add a Custom Policy.
*
* @param body DTO of new policy to be created
* @param request msf4j request object
* @return Created policy along with the location of it with Location header
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingCustomPost(CustomRuleDTO body, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Custom Policy POST request " + body);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
CustomPolicy customPolicy = CustomPolicyMappingUtil.fromCustomPolicyDTOToModel(body);
String uuid = apiMgtAdminService.addCustomRule(customPolicy);
return Response.status(Response.Status.CREATED).entity(CustomPolicyMappingUtil.fromCustomPolicyToDTO(apiMgtAdminService.getCustomRuleByUUID(uuid))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while adding custom policy, policy name: " + body.getPolicyName();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.messaging.Header in project carbon-apimgt by wso2.
the class BlacklistApiServiceImpl method blacklistConditionIdDelete.
/**
* Delete blacklist condition using ID
*
* @param conditionId condition ID of the block condition
* @param ifMatch IF-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Response Object
* @throws NotFoundException Iif an error occurred when particular resource does not exits in the system.
*/
@Override
public Response blacklistConditionIdDelete(String conditionId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Blacklist Condition DELETE request with id: " + conditionId);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
apiMgtAdminService.deleteBlockConditionByUuid(conditionId);
return Response.ok().build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while deleting blacklist condition with UUID " + conditionId;
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();
}
}
Aggregations