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;
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations