Search in sources :

Example 6 with Representation

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;
}
Also used : Status(org.restlet.data.Status) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation)

Example 7 with 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"));
}
Also used : Status(org.restlet.data.Status) Response(org.restlet.Response) Request(org.restlet.Request) Representation(org.restlet.representation.Representation) Test(org.testng.annotations.Test)

Example 8 with Representation

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\""));
}
Also used : Response(org.restlet.Response) Status(org.restlet.data.Status) Request(org.restlet.Request) ResourceException(org.forgerock.json.resource.ResourceException) Representation(org.restlet.representation.Representation) Test(org.testng.annotations.Test)

Example 9 with Representation

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>"));
}
Also used : Status(org.restlet.data.Status) Response(org.restlet.Response) Request(org.restlet.Request) Representation(org.restlet.representation.Representation) Test(org.testng.annotations.Test)

Example 10 with Representation

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;
}
Also used : BufferingRepresentation(org.restlet.representation.BufferingRepresentation) AuditException(org.forgerock.audit.AuditException) BufferingRepresentation(org.restlet.representation.BufferingRepresentation) Representation(org.restlet.representation.Representation)

Aggregations

Representation (org.restlet.representation.Representation)101 HashMap (java.util.HashMap)28 Test (org.testng.annotations.Test)27 StringRepresentation (org.restlet.representation.StringRepresentation)24 Request (org.restlet.Request)23 Response (org.restlet.Response)23 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)23 ResourceException (org.restlet.resource.ResourceException)21 Reference (org.restlet.data.Reference)19 StringWriter (java.io.StringWriter)17 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)16 IOException (java.io.IOException)14 Map (java.util.Map)14 Form (org.restlet.data.Form)14 VCellApiApplication (org.vcell.rest.VCellApiApplication)14 User (org.vcell.util.document.User)13 Configuration (freemarker.template.Configuration)10 StringReader (java.io.StringReader)10 ZNRecord (org.apache.helix.ZNRecord)10 TypeReference (org.codehaus.jackson.type.TypeReference)10