Search in sources :

Example 46 with Representation

use of org.restlet.representation.Representation in project pinot by linkedin.

the class PinotSegmentUploadRestletResource method get.

@Override
public Representation get() {
    Representation presentation = null;
    try {
        final String tableName = (String) getRequest().getAttributes().get("tableName");
        final String segmentName = (String) getRequest().getAttributes().get("segmentName");
        final String tableType = getReference().getQueryAsForm().getValues("type");
        if ((tableName == null) && (segmentName == null)) {
            return getAllSegments();
        } else if ((tableName != null) && (segmentName == null)) {
            return getSegmentsForTable(tableName, tableType);
        }
        presentation = getSegmentFile(tableName, segmentName);
    } catch (final Exception e) {
        presentation = exceptionToStringRepresentation(e);
        LOGGER.error("Caught exception while processing get request", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_SEGMENT_GET_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) FileRepresentation(org.restlet.representation.FileRepresentation) Representation(org.restlet.representation.Representation) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 47 with Representation

use of org.restlet.representation.Representation in project OpenAM by OpenRock.

the class PermissionRequestEndpointTest method shouldReturnPermissionTicket.

@Test
@SuppressWarnings("unchecked")
public void shouldReturnPermissionTicket() throws Exception {
    //Given
    JsonRepresentation entity = mock(JsonRepresentation.class);
    JSONObject requestBody = mock(JSONObject.class);
    given(entity.getJsonObject()).willReturn(requestBody);
    given(requestBody.toString()).willReturn("{\"resource_set_id\":\"RESOURCE_SET_ID\", " + "\"scopes\":[\"SCOPE_A\", \"SCOPE_B\"]}");
    setupResourceSetStore();
    PermissionTicket ticket = new PermissionTicket("abc", null, null, null);
    given(umaTokenStore.createPermissionTicket(eq("RESOURCE_SET_ID"), anySetOf(String.class), eq("CLIENT_ID"))).willReturn(ticket);
    //When
    Representation responseBody = endpoint.registerPermissionRequest(entity);
    //Then
    Map<String, String> permissionTicket = (Map<String, String>) new ObjectMapper().readValue(responseBody.getText(), Map.class);
    assertThat(permissionTicket).containsEntry("ticket", "abc");
    verify(permissionRequestFilter).onPermissionRequest(any(ResourceSetDescription.class), anySetOf(String.class), anyString());
    ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
    verify(response).setStatus(statusCaptor.capture());
    assertThat(statusCaptor.getValue().getCode()).isEqualTo(201);
}
Also used : Status(org.restlet.data.Status) JSONObject(org.json.JSONObject) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Map(java.util.Map) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 48 with Representation

use of org.restlet.representation.Representation in project OpenAM by OpenRock.

the class UmaWellKnownConfigurationEndpointTest method shouldGetRequiredUmaConfiguration.

@Test
@SuppressWarnings("unchecked")
public void shouldGetRequiredUmaConfiguration() throws Exception {
    //Given
    setupProviderSettings();
    //When
    Representation configuration = endpoint.getConfiguration();
    //Then
    Map<String, Object> configurationResponse = (Map<String, Object>) new ObjectMapper().readValue(configuration.getText(), Map.class);
    assertThat(configurationResponse).contains(entry("version", "VERSION"), entry("issuer", "ISSUER"), entry("pat_profiles_supported", Collections.singletonList("PAT_PROFILE")), entry("aat_profiles_supported", Collections.singletonList("AAT_PROFILE")), entry("rpt_profiles_supported", Collections.singletonList("RPT_PROFILE")), entry("pat_grant_types_supported", Collections.singletonList("PAT_GRANT_TYPE")), entry("aat_grant_types_supported", Collections.singletonList("AAT_GRANT_TYPE")), entry("token_endpoint", "TOKEN_ENDPOINT"), entry("authorization_endpoint", "AUTHORIZATION_ENDPOINT"), entry("introspection_endpoint", "TOKEN_INTROSPECTION_ENDPOINT"), entry("resource_set_registration_endpoint", "RESOURCE_SET_REGISTRATION_ENDPOINT"), entry("permission_registration_endpoint", "PERMISSION_REGISTRATION_ENDPOINT"), entry("rpt_endpoint", "RPT_ENDPOINT"));
    verifyZeroInteractions(response);
}
Also used : Representation(org.restlet.representation.Representation) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 49 with Representation

use of org.restlet.representation.Representation in project OpenAM by OpenRock.

the class UmaWellKnownConfigurationEndpointTest method shouldGetOptionalUmaConfiguration.

@Test
@SuppressWarnings("unchecked")
public void shouldGetOptionalUmaConfiguration() throws Exception {
    //Given
    setupProviderSettingsWithOptionalConfiguration();
    //When
    Representation configuration = endpoint.getConfiguration();
    //Then
    Map<String, Object> configurationResponse = (Map<String, Object>) new ObjectMapper().readValue(configuration.getText(), Map.class);
    assertThat(configurationResponse).contains(entry("version", "VERSION"), entry("issuer", "ISSUER"), entry("pat_profiles_supported", Collections.singletonList("PAT_PROFILE")), entry("aat_profiles_supported", Collections.singletonList("AAT_PROFILE")), entry("rpt_profiles_supported", Collections.singletonList("RPT_PROFILE")), entry("pat_grant_types_supported", Collections.singletonList("PAT_GRANT_TYPE")), entry("aat_grant_types_supported", Collections.singletonList("AAT_GRANT_TYPE")), entry("token_endpoint", "TOKEN_ENDPOINT"), entry("authorization_endpoint", "AUTHORIZATION_ENDPOINT"), entry("introspection_endpoint", "TOKEN_INTROSPECTION_ENDPOINT"), entry("resource_set_registration_endpoint", "RESOURCE_SET_REGISTRATION_ENDPOINT"), entry("permission_registration_endpoint", "PERMISSION_REGISTRATION_ENDPOINT"), entry("rpt_endpoint", "RPT_ENDPOINT"), entry("claim_token_profiles_supported", Collections.singletonList("CLAIM_TOKEN_PROFILE")), entry("uma_profiles_supported", Collections.singletonList("UMA_PROFILE")), entry("dynamic_client_endpoint", "DYNAMIC_CLIENT_ENDPOINT"), entry("requesting_party_claims_endpoint", "REQUESTING_PARTY_CLAIMS_ENDPOINT"));
    verifyZeroInteractions(response);
}
Also used : Representation(org.restlet.representation.Representation) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 50 with Representation

use of org.restlet.representation.Representation in project Xponents by OpenSextant.

the class XlayerClient method process.

/**
     * 
     * @param text
     * @return
     * @throws IOException
     * @throws JSONException
     */
public List<TextMatch> process(String docid, String text) throws IOException, JSONException {
    ClientResource client = new ClientResource(serviceContext, serviceURI);
    org.json.JSONObject content = new JSONObject();
    content.put("text", text);
    content.put("docid", docid);
    content.put("features", "places,coordinates,countries,persons,orgs,reverse-geocode");
    /* Coordinates mainly are XY locations; Reverse Geocode them to find what country the location resides */
    StringWriter data = new StringWriter();
    try {
        Representation repr = new JsonRepresentation(content.toString());
        repr.setCharacterSet(CharacterSet.UTF_8);
        //log.debug("CLIENT {} {}", serviceAddress, client);
        // Process and read response fully.
        Representation response = client.post(repr, MediaType.APPLICATION_JSON);
        response.write(data);
        response.exhaust();
        response.release();
        JSONObject json = new JSONObject(data.toString());
        log.debug("POST: response  {}", json.toString(2));
        JSONObject meta = json.getJSONObject("response");
        JSONArray annots = json.getJSONArray("annotations");
        List<TextMatch> matches = new ArrayList<TextMatch>();
        for (int x = 0; x < annots.length(); ++x) {
            Object m = annots.get(x);
            matches.add(Transforms.parseAnnotation(m));
        }
        return matches;
    } catch (ResourceException restErr) {
        if (restErr.getCause() instanceof IOException) {
            throw (IOException) restErr.getCause();
        } else {
            throw restErr;
        }
    } catch (java.net.SocketException err) {
        // This never happens. Restlet wraps everything.
        throw err;
    } finally {
        client.release();
    }
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Representation(org.restlet.representation.Representation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) TextMatch(org.opensextant.extraction.TextMatch) IOException(java.io.IOException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) StringWriter(java.io.StringWriter) ClientResource(org.restlet.resource.ClientResource) JSONObject(org.json.JSONObject) ResourceException(org.restlet.resource.ResourceException) JsonRepresentation(org.restlet.ext.json.JsonRepresentation)

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