use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpoint method createEmptyResponse.
private Representation createEmptyResponse() {
Representation representation = new EmptyRepresentation();
getResponse().setStatus(new Status(204));
return representation;
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class JSONRestStatusServiceTest method shouldGetJsonResourceException.
@Test
public void shouldGetJsonResourceException() throws IOException {
//Given
Status status = Status.CLIENT_ERROR_BAD_REQUEST;
Request request = mock(Request.class);
Response response = mock(Response.class);
//When
Representation representation = restStatusService.toRepresentation(status, request, response);
//Then
assertTrue(representation.getText().contains("\"code\":400"));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class JSONRestStatusServiceTest method shouldReturnThrowableJsonValueIfResourceException.
@Test
public void shouldReturnThrowableJsonValueIfResourceException() throws IOException {
//Given
Request request = mock(Request.class);
Response response = mock(Response.class);
ResourceException exception = ResourceException.newResourceException(401);
exception.setDetail(json(object(field("bing", "bong"))));
Status status = new Status(exception.getCode(), exception);
//When
Representation representation = restStatusService.toRepresentation(status, request, response);
//Then
assertTrue(representation.getText().contains("\"bing\":\"bong\""));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class XMLRestStatusServiceTest method shouldGetXmlResourceException.
@Test
public void shouldGetXmlResourceException() throws IOException {
//Given
Status status = Status.CLIENT_ERROR_BAD_REQUEST;
Request request = mock(Request.class);
Response response = mock(Response.class);
//When
Representation representation = restStatusService.toRepresentation(status, request, response);
//Then
assertTrue(representation.getText().contains("<code>400</code>"));
}
use of org.restlet.representation.Representation in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilter method beforeHandle.
@Override
protected int beforeHandle(Request request, Response response) {
try {
Representation representation = request.getEntity();
// buffer in order to read from it during the event logging and later during authentication
if (representation.isTransient()) {
request.setEntity(new BufferingRepresentation(request.getEntity()));
}
auditAccessAttempt(request);
} catch (AuditException e) {
debug.error("Unable to publish {} audit event '{}' due to error: {} [{}]", ACCESS_TOPIC, EventName.AM_ACCESS_ATTEMPT, e.getMessage(), e);
}
return CONTINUE;
}
Aggregations