Search in sources :

Example 21 with JSONObject

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));
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(net.minidev.json.JSONObject) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 22 with JSONObject

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();
    }
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 23 with JSONObject

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();
}
Also used : JSONObject(net.minidev.json.JSONObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with JSONObject

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());
}
Also used : Action(ddf.action.Action) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) JSONParser(net.minidev.json.parser.JSONParser) Test(org.junit.Test)

Example 25 with JSONObject

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;
}
Also used : JSONObject(net.minidev.json.JSONObject) HashMap(java.util.HashMap) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

JSONObject (net.minidev.json.JSONObject)254 JSONArray (net.minidev.json.JSONArray)49 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)23 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 ParseException (net.minidev.json.parser.ParseException)13 JSONConverterException (org.btrplace.json.JSONConverterException)13 SignedJWT (com.nimbusds.jwt.SignedJWT)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 JWSHeader (com.nimbusds.jose.JWSHeader)10 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)10 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9