Example usage for javax.json JsonString getString

List of usage examples for javax.json JsonString getString

Introduction

In this page you can find the example usage for javax.json JsonString getString.

Prototype

String getString();

Source Link

Document

Returns the JSON string value.

Usage

From source file:org.apache.unomi.services.services.SegmentServiceImpl.java

public static void dumpJSON(JsonValue tree, String key, String depthPrefix) {
    if (key != null)
        logger.info(depthPrefix + "Key " + key + ": ");
    switch (tree.getValueType()) {
    case OBJECT:/*w  w  w  .jav  a 2  s .c o  m*/
        logger.info(depthPrefix + "OBJECT");
        JsonObject object = (JsonObject) tree;
        for (String name : object.keySet())
            dumpJSON(object.get(name), name, depthPrefix + "  ");
        break;
    case ARRAY:
        logger.info(depthPrefix + "ARRAY");
        JsonArray array = (JsonArray) tree;
        for (JsonValue val : array)
            dumpJSON(val, null, depthPrefix + "  ");
        break;
    case STRING:
        JsonString st = (JsonString) tree;
        logger.info(depthPrefix + "STRING " + st.getString());
        break;
    case NUMBER:
        JsonNumber num = (JsonNumber) tree;
        logger.info(depthPrefix + "NUMBER " + num.toString());
        break;
    case TRUE:
    case FALSE:
    case NULL:
        logger.info(depthPrefix + tree.getValueType().toString());
        break;
    }
}

From source file:jp.co.yahoo.yconnect.core.oidc.IdTokenDecoder.java

/**
 * IdToken?/*from w w  w.  j  a v a2  s . c om*/
 * 
 * @return IdTokenObject
 * @throws DataFormatException
 */
public IdTokenObject decode() throws DataFormatException {

    HashMap<String, String> idToken = this.splitIdToken();

    // Header
    String jsonHeader = idToken.get("header");

    JsonReader jsonHeaderReader = Json.createReader(new StringReader(jsonHeader));
    JsonObject rootHeader = jsonHeaderReader.readObject();
    jsonHeaderReader.close();

    JsonString typeString = rootHeader.getJsonString("typ");
    String type = typeString.getString();

    JsonString algorithmString = rootHeader.getJsonString("alg");
    String algorithm = algorithmString.getString();

    // Payload
    String jsonPayload = idToken.get("payload");

    JsonReader jsonPayloadReader = Json.createReader(new StringReader(jsonPayload));

    JsonObject rootPayload = jsonPayloadReader.readObject();
    jsonPayloadReader.close();

    JsonString issString = rootPayload.getJsonString("iss");
    String iss = issString.getString();

    JsonString userIdString = rootPayload.getJsonString("user_id");
    String userId = userIdString.getString();

    JsonString audString = rootPayload.getJsonString("aud");
    ArrayList<String> aud = new ArrayList<String>();
    aud.add(audString.getString());

    JsonNumber expString = rootPayload.getJsonNumber("exp");
    int exp = expString.intValue();

    JsonNumber iatString = rootPayload.getJsonNumber("iat");
    int iat = iatString.intValue();

    JsonString nonceString = rootPayload.getJsonString("nonce");
    String nonce = nonceString.getString();

    // signature
    String signature = idToken.get("signature");

    // ???
    return new IdTokenObject(type, algorithm, iss, userId, aud, nonce, exp, iat, signature);
}

From source file:com.dhenton9000.jersey.client.BasicTests.java

@Test
public void testGetRestaurantWithReadOnlyJsonApi() {
    ClientConfig config = new ClientConfig();

    Client client = ClientBuilder.newClient(config);

    WebTarget target = client.target(getBaseURI());

    JsonObject restaurantObject = this.getSingleRestaurant(4, target);
    JsonString restaurantName = restaurantObject.getJsonString("name");
    LOG.debug(restaurantName.getString());
    assertTrue(restaurantName.toString().toUpperCase().contains("ARBY"));
}

From source file:joachimeichborn.geotag.geocode.MapQuestGeocoder.java

private String getMatchingContent(final LocationType aLocationType, final JsonObject aAddressDetails) {
    for (final String identifier : aLocationType.getIdentifiers()) {
        final JsonString value = aAddressDetails.getJsonString(identifier);
        if (value != null) {
            return value.getString();
        }// w w w  .  ja  v  a2  s.  c  o m
    }

    return null;
}

From source file:fr.ortolang.diffusion.client.cmd.ReindexAllRootCollectionCommand.java

@Override
public void execute(String[] args) {
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;//from  ww w  . j a v  a2  s .c o  m
    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            help();
        }

        String[] credentials = getCredentials(cmd);
        String username = credentials[0];
        String password = credentials[1];

        boolean fakeMode = cmd.hasOption("F");

        OrtolangClient client = OrtolangClient.getInstance();
        if (username.length() > 0) {
            client.getAccountManager().setCredentials(username, password);
            client.login(username);
        }
        System.out.println("Connected as user: " + client.connectedProfile());
        System.out.println("Looking for root collection ...");

        // Looking for root collection
        List<String> rootCollectionKeys = new ArrayList<>();

        int offset = 0;
        int limit = 100;
        JsonObject listOfObjects = client.listObjects("core", "collection", "PUBLISHED", offset, limit);
        JsonArray keys = listOfObjects.getJsonArray("entries");

        while (!keys.isEmpty()) {
            for (JsonString objectKey : keys.getValuesAs(JsonString.class)) {
                JsonObject objectRepresentation = client.getObject(objectKey.getString());
                JsonObject objectProperty = objectRepresentation.getJsonObject("object");
                boolean isRoot = objectProperty.getBoolean("root");
                if (isRoot) {
                    rootCollectionKeys.add(objectKey.getString());
                }
            }
            offset += limit;
            listOfObjects = client.listObjects("core", "collection", "PUBLISHED", offset, limit);
            keys = listOfObjects.getJsonArray("entries");
        }

        System.out.println("Reindex keys : " + rootCollectionKeys);
        if (!fakeMode) {
            for (String key : rootCollectionKeys) {
                client.reindex(key);
            }
        }

        client.logout();
        client.close();

    } catch (ParseException e) {
        System.out.println("Failed to parse command line properties " + e.getMessage());
        help();
    } catch (OrtolangClientException | OrtolangClientAccountException e) {
        System.out.println("Unexpected error !!");
        e.printStackTrace();
    }
}

From source file:joachimeichborn.geotag.geocode.MapQuestGeocoder.java

private Geocoding extractLocationInformation(final JsonObject aJsonRepresentation) {
    final JsonString location = aJsonRepresentation.getJsonString("display_name");
    final JsonObject addressDetails = aJsonRepresentation.getJsonObject("address");

    return createTextualRepresentation(location.getString(), addressDetails);
}

From source file:io.bitgrillr.gocddockerexecplugin.DockerExecPlugin.java

private GoPluginApiResponse handleExecuteRequest(JsonObject requestBody) {
    final String image = requestBody.getJsonObject(CONFIG).getJsonObject(IMAGE).getString(VALUE);
    final String command = requestBody.getJsonObject(CONFIG).getJsonObject("COMMAND").getString(VALUE);
    final JsonString argumentsJson = requestBody.getJsonObject(CONFIG).getJsonObject("ARGUMENTS")
            .getJsonString(VALUE);//ww  w  .j  a v  a 2 s. com
    final String[] arguments;
    if (argumentsJson != null) {
        arguments = argumentsJson.getString().split("\\r?\\n");
    } else {
        arguments = new String[0];
    }
    Map<String, String> envVars = requestBody.getJsonObject("context").getJsonObject("environmentVariables")
            .entrySet().stream()
            .map(e -> new AbstractMap.SimpleEntry<>(e.getKey(), ((JsonString) e.getValue()).getString()))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    final String workingDir = requestBody.getJsonObject("context").getString("workingDirectory");
    final String pwd = Paths.get(System.getProperty("user.dir"), workingDir).toAbsolutePath().toString();

    final Map<String, Object> responseBody = new HashMap<>();
    try {
        final int exitCode = executeBuild(image, pwd, envVars, command, arguments);

        responseBody.put(MESSAGE,
                (new StringBuilder()).append("Command ")
                        .append(DockerUtils.getCommandString(command, arguments))
                        .append(" completed with status ").append(exitCode).toString());
        if (exitCode == 0) {
            responseBody.put(SUCCESS, Boolean.TRUE);
        } else {
            responseBody.put(SUCCESS, Boolean.FALSE);
        }
    } catch (DockerCleanupException dce) {
        responseBody.clear();
        responseBody.put(SUCCESS, Boolean.FALSE);
        if (dce.getNested() == null) {
            responseBody.put(MESSAGE, dce.getCause().getMessage());
        } else {
            responseBody.put(MESSAGE, dce.getNested().getMessage());
        }
    } catch (ImageNotFoundException infe) {
        responseBody.put(SUCCESS, Boolean.FALSE);
        responseBody.put(MESSAGE,
                (new StringBuilder()).append("Image '").append(image).append("' not found").toString());
    } catch (Exception e) {
        responseBody.clear();
        responseBody.put(SUCCESS, Boolean.FALSE);
        responseBody.put(MESSAGE, e.getMessage());
    }

    return DefaultGoPluginApiResponse.success(Json.createObjectBuilder(responseBody).build().toString());
}