use of net.minidev.json.JSONObject in project ddf by codice.
the class TestGeoCoderEndpoint method testNearbyLocation.
@Test
public void testNearbyLocation() throws ParseException {
Response response = geoCoderEndpoint.getNearbyCities("POINT(10 30)");
if (response != null) {
String responseString = (String) response.getEntity();
if (responseString != null) {
JSONObject jsonObject = (JSONObject) jsonParser.parse(responseString);
assertThat(jsonObject.get("name"), is("Phoenix"));
assertThat(jsonObject.get("direction"), is("N"));
assertThat(jsonObject.get("distance"), is(23.45));
}
}
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoCoderEndpoint method getNearbyCities.
@GET
@Path("nearby/cities/{wkt}")
public Response getNearbyCities(@PathParam("wkt") String wkt) {
GeoCoder geoCoder = geoCoderFactory.getService();
try {
NearbyLocation nearbyLocation = geoCoder.getNearbyCity(wkt);
if (nearbyLocation != null) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("direction", nearbyLocation.getCardinalDirection());
jsonObject.put("distance", nearbyLocation.getDistance());
jsonObject.put("name", nearbyLocation.getName());
return Response.ok(jsonObject.toJSONString()).build();
} else {
return Response.status(Response.Status.NO_CONTENT).build();
}
} catch (GeoEntryQueryException e) {
LOGGER.debug("Error querying GeoNames resource with wkt:{}", wkt, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class PlatformUiConfiguration method getConfig.
@GET
@Path("/config/ui")
@Produces("application/json")
public String getConfig() {
JSONObject jsonObject = new JSONObject();
if (systemUsageEnabled) {
jsonObject.put(SYSTEM_USAGE_TITLE, systemUsageTitle);
jsonObject.put(SYSTEM_USAGE_MESSAGE, systemUsageMessage);
jsonObject.put(SYSTEM_USAGE_ONCE_PER_SESSION, systemUsageOncePerSession);
}
jsonObject.put(HEADER, this.header);
jsonObject.put(FOOTER, this.footer);
jsonObject.put(COLOR, this.color);
jsonObject.put(BACKGROUND, this.background);
jsonObject.put(TITLE, getTitle());
jsonObject.put(VERSION, getVersion());
jsonObject.put(PRODUCT_IMAGE, getProductImage());
jsonObject.put(FAV_ICON, getFavIcon());
return jsonObject.toJSONString();
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class TestLogoutService method testLogout.
@Test
public void testLogout() throws IOException, ParseException, SecurityServiceException {
KarafLogoutAction karafLogoutActionProvider = new KarafLogoutAction();
LdapLogoutAction ldapLogoutActionProvider = new LdapLogoutAction();
Action karafLogoutAction = karafLogoutActionProvider.getAction(null);
Action ldapLogoutAction = ldapLogoutActionProvider.getAction(null);
LogoutService logoutService = new LogoutService();
logoutService.setHttpSessionFactory(sessionFactory);
logoutService.setSecurityManager(sm);
logoutService.setLogoutActionProviders(Arrays.asList(karafLogoutActionProvider, ldapLogoutActionProvider));
String responseMessage = IOUtils.toString((ByteArrayInputStream) logoutService.getActionProviders(null).getEntity());
JSONArray actionProperties = (JSONArray) new JSONParser().parse(responseMessage);
assertEquals(2, actionProperties.size());
JSONObject karafActionProperty = ((JSONObject) actionProperties.get(0));
assertEquals(karafActionProperty.get("description"), karafLogoutAction.getDescription());
assertEquals(karafActionProperty.get("realm"), karafLogoutAction.getId().substring(karafLogoutAction.getId().lastIndexOf(".") + 1));
assertEquals(karafActionProperty.get("title"), karafLogoutAction.getTitle());
assertEquals(karafActionProperty.get("url"), karafLogoutAction.getUrl().toString());
JSONObject ldapActionProperty = ((JSONObject) actionProperties.get(1));
assertEquals(ldapActionProperty.get("description"), ldapLogoutAction.getDescription());
assertEquals(ldapActionProperty.get("realm"), ldapLogoutAction.getId().substring(ldapLogoutAction.getId().lastIndexOf(".") + 1));
assertEquals(ldapActionProperty.get("title"), ldapLogoutAction.getTitle());
assertEquals(ldapActionProperty.get("url"), ldapLogoutAction.getUrl().toString());
}
use of net.minidev.json.JSONObject in project knox by apache.
the class AmbariClientCommon method getActiveServiceConfigurations.
Map<String, Map<String, AmbariCluster.ServiceConfiguration>> getActiveServiceConfigurations(String discoveryAddress, String clusterName, String discoveryUser, String discoveryPwdAlias) {
Map<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfigurations = new HashMap<>();
String serviceConfigsURL = String.format("%s" + AMBARI_SERVICECONFIGS_URI, discoveryAddress, clusterName);
JSONObject serviceConfigsJSON = restClient.invoke(serviceConfigsURL, discoveryUser, discoveryPwdAlias);
if (serviceConfigsJSON != null) {
// Process the service configurations
JSONArray serviceConfigs = (JSONArray) serviceConfigsJSON.get("items");
for (Object serviceConfig : serviceConfigs) {
String serviceName = (String) ((JSONObject) serviceConfig).get("service_name");
JSONArray configurations = (JSONArray) ((JSONObject) serviceConfig).get("configurations");
for (Object configuration : configurations) {
String configType = (String) ((JSONObject) configuration).get("type");
String configVersion = String.valueOf(((JSONObject) configuration).get("version"));
Map<String, String> configProps = new HashMap<>();
JSONObject configProperties = (JSONObject) ((JSONObject) configuration).get("properties");
for (Entry<String, Object> entry : configProperties.entrySet()) {
configProps.put(entry.getKey(), String.valueOf(entry.getValue()));
}
if (!serviceConfigurations.containsKey(serviceName)) {
serviceConfigurations.put(serviceName, new HashMap<>());
}
serviceConfigurations.get(serviceName).put(configType, new AmbariCluster.ServiceConfiguration(configType, configVersion, configProps));
}
}
}
return serviceConfigurations;
}
Aggregations