use of org.forgerock.json.resource.RequestType in project OpenAM by OpenRock.
the class AuditFilter method getDetail.
/**
* Provides additional details (e.g. failure description or summary of the payload) relating to the a successful
* {@link Response} to a {@link Request}. This information is logged in the access audit log.
*
* @param request The {@link Request} instance from which details may be taken. Cannot be null.
* @param response The {@link Response} instance from which details may be taken. Cannot be null.
* @return {@link JsonValue} free-form details, or null to indicate no details.
*/
private JsonValue getDetail(Request request, Response response) {
Reject.ifNull(request, "request cannot be null.");
Reject.ifNull(request, "response cannot be null.");
RequestType requestType = request.getRequestType();
switch(requestType) {
case CREATE:
return getCreateSuccessDetail((CreateRequest) request, (ResourceResponse) response);
case READ:
return getReadSuccessDetail((ReadRequest) request, (ResourceResponse) response);
case UPDATE:
return getUpdateSuccessDetail((UpdateRequest) request, (ResourceResponse) response);
case DELETE:
return getDeleteSuccessDetail((DeleteRequest) request, (ResourceResponse) response);
case PATCH:
return getPatchSuccessDetail((PatchRequest) request, (ResourceResponse) response);
case ACTION:
return getActionSuccessDetail((ActionRequest) request, (ActionResponse) response);
case QUERY:
return getQuerySuccessDetail((QueryRequest) request, (QueryResponse) response);
default:
throw new IllegalStateException("Unknown RequestType");
}
}
use of org.forgerock.json.resource.RequestType in project OpenAM by OpenRock.
the class EntitlementsExceptionMappingHandlerTest method shouldApplyRequestTypeOverrides.
@Test
public void shouldApplyRequestTypeOverrides() {
// Given
Map<RequestType, Map<Integer, Integer>> overrides = new HashMap<RequestType, Map<Integer, Integer>>();
RequestType requestType = RequestType.CREATE;
overrides.put(requestType, Collections.singletonMap(ResourceException.NOT_FOUND, ResourceException.BAD_REQUEST));
EntitlementsExceptionMappingHandler errorHandler = new EntitlementsExceptionMappingHandler(Collections.singletonMap(ERROR_CODE, ResourceException.NOT_FOUND), overrides, Collections.<Integer, Integer>emptyMap());
EntitlementException error = exception(ERROR_CODE, ERROR_MESSAGE);
Request request = mock(Request.class);
given(request.getRequestType()).willReturn(requestType);
// When
ResourceException result = errorHandler.handleError(request, error);
// Then
assertThat(result).isInstanceOf(BadRequestException.class).hasMessage(ERROR_MESSAGE);
}
Aggregations