Example usage for javax.json JsonObject getJsonString

List of usage examples for javax.json JsonObject getJsonString

Introduction

In this page you can find the example usage for javax.json JsonObject getJsonString.

Prototype

JsonString getJsonString(String name);

Source Link

Document

Returns the string value to which the specified name is mapped.

Usage

From source file:org.acruxsource.sandbox.spring.jmstows.websocket.ChatHandler.java

@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    logger.info("New incoming message: " + message.getPayload());

    StringReader stringReader = new StringReader(message.getPayload());
    JsonReader jsonReader = Json.createReader(stringReader);
    JsonObject chatMessageObject = jsonReader.readObject();

    if (chatMessageObject.getJsonString("name") != null && chatMessageObject.getJsonString("message") != null) {
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.setName(chatMessageObject.getJsonString("name").getString());
        chatMessage.setMessage(chatMessageObject.getJsonString("message").getString());
        jmsMessageSender.sendMessage("websocket.out", chatMessage);
    } else {//from  www . ja  v a 2  s.  c o  m
        session.sendMessage(new TextMessage("Empty name or message"));
    }
}

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: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();
        }//from  w  ww .  j a  v a2 s  .  c  o m
    }

    return null;
}

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

/**
 * IdToken?//from   ww  w .  j a  va  2  s.  c  o  m
 * 
 * @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:de.tu_dortmund.ub.data.dswarm.Task.java

@Override
public String call() {

    // init logger
    PropertyConfigurator.configure(config.getProperty("service.log4j-conf"));

    logger.info("[" + config.getProperty("service.name") + "] " + "Starting 'Task' ...");

    // init IDs of the prototype project
    String dataModelID = config.getProperty("prototype.dataModelID");
    String projectID = config.getProperty("prototype.projectID");
    String outputDataModelID = config.getProperty("prototype.outputDataModelID");

    // init process values
    String inputResourceID = null;
    String message = null;/*from  w  ww  .  j av a 2  s  .  c  o m*/

    try {

        // get the resource id of the current data model >> updateResourceID replaces resourceID
        String updateResourceID = null;
        try {
            updateResourceID = getProjectResourceID(dataModelID);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        logger.info("[" + config.getProperty("service.name") + "] updateResourceID = " + updateResourceID);

        // upload resource and update a InputDataModel
        String inputResourceJson = uploadFileAndUpdateResource(updateResourceID, resource,
                "resource for project '" + resource, config.getProperty("project.name") + "' - case " + cnt);
        JsonReader jsonReader = Json.createReader(IOUtils.toInputStream(inputResourceJson, "UTF-8"));
        inputResourceID = jsonReader.readObject().getString("uuid");
        logger.info("[" + config.getProperty("service.name") + "] inputResourceID = " + inputResourceID);

        if (updateResourceID != null) {

            // update the datamodel (will use it's (update) resource)
            updateDataModel(dataModelID);

            // configuration and processing of the task
            String jsonResponse = executeTask(dataModelID, projectID, outputDataModelID);

            if (jsonResponse != null) {

                if (Boolean.parseBoolean(config.getProperty("results.persistInFolder"))) {

                    if (Boolean.parseBoolean(config.getProperty("results.writeDMPJson"))) {
                        // save DMP results in files
                        FileUtils.writeStringToFile(new File(config.getProperty("results.folder")
                                + File.separatorChar + dataModelID + "." + cnt + ".json"), jsonResponse);
                    }

                    // build rdf graph
                    ValueFactory factory = ValueFactoryImpl.getInstance();

                    Graph graph = new LinkedHashModel();

                    URI graphUri = factory.createURI(config.getProperty("results.rdf.graph"));

                    URI subject = null;
                    URI predicate = null;
                    URI object = null;
                    Literal literal = null;
                    Statement statement = null;

                    JsonReader dmpJsonResult = Json.createReader(IOUtils.toInputStream(jsonResponse, "UTF-8"));
                    JsonArray records = dmpJsonResult.readArray();

                    for (JsonObject record : records.getValuesAs(JsonObject.class)) {

                        subject = factory
                                .createURI(record.getJsonString("__record_id").toString().replaceAll("\"", ""));

                        for (JsonObject triple : record.getJsonArray("__record_data")
                                .getValuesAs(JsonObject.class)) {

                            for (String key : triple.keySet()) {

                                if (key.endsWith("rdf-syntax-ns#type")) {
                                    predicate = RDF.TYPE;
                                    object = factory.createURI(
                                            triple.getJsonString(key).toString().replaceAll("\"", ""));
                                    statement = factory.createStatement(subject, predicate, object, graphUri);
                                    graph.add(statement);
                                } else {

                                    predicate = factory.createURI(key);

                                    switch (triple.get(key).getValueType().toString()) {

                                    case "STRING": {

                                        try {
                                            object = factory.createURI(
                                                    triple.getJsonString(key).toString().replaceAll("\"", ""));
                                            statement = factory.createStatement(subject, predicate, object,
                                                    graphUri);
                                            graph.add(statement);
                                        } catch (Exception e) {
                                            literal = factory.createLiteral(
                                                    triple.getJsonString(key).toString().replaceAll("\"", ""));
                                            statement = factory.createStatement(subject, predicate, literal,
                                                    graphUri);
                                            graph.add(statement);
                                        }
                                        break;
                                    }
                                    case "ARRAY": {

                                        for (JsonString value : triple.getJsonArray(key)
                                                .getValuesAs(JsonString.class)) {

                                            try {
                                                object = factory
                                                        .createURI(value.toString().replaceAll("\"", ""));
                                                statement = factory.createStatement(subject, predicate, object,
                                                        graphUri);
                                                graph.add(statement);
                                            } catch (Exception e) {
                                                literal = factory
                                                        .createLiteral(value.toString().replaceAll("\"", ""));
                                                statement = factory.createStatement(subject, predicate, literal,
                                                        graphUri);
                                                graph.add(statement);
                                            }
                                        }
                                        break;
                                    }
                                    default: {

                                        logger.info("Unhandled ValueType: " + triple.get(key).getValueType());
                                    }
                                    }
                                }
                            }
                        }
                    }

                    if (graph.size() > 0) {
                        // save rdf data as 'results.rdf.format' in 'results.folder'
                        RDFFormat format = null;
                        switch (config.getProperty("results.rdf.format")) {

                        case "xml": {

                            format = RDFFormat.RDFXML;
                            break;
                        }
                        case "nquads": {

                            format = RDFFormat.NQUADS;
                            break;
                        }
                        case "jsonld": {

                            format = RDFFormat.JSONLD;
                            break;
                        }
                        case "ttl": {

                            format = RDFFormat.TURTLE;
                            break;
                        }
                        default: {

                            format = RDFFormat.RDFXML;
                        }
                        }

                        try {
                            FileOutputStream out = new FileOutputStream(
                                    config.getProperty("results.folder") + File.separatorChar + dataModelID
                                            + "." + cnt + ".rdf." + config.getProperty("results.rdf.format"));
                            RDFWriter writer = Rio.createWriter(format, out);

                            writer.startRDF();
                            for (Statement st : graph) {
                                writer.handleStatement(st);
                            }
                            writer.endRDF();

                            out.close();

                        } catch (RDFHandlerException | IOException e) {
                            e.printStackTrace();
                        }

                        message = "'" + resource + "' transformed. results in '"
                                + config.getProperty("results.folder") + File.separatorChar + dataModelID + "."
                                + cnt + ".rdf." + config.getProperty("results.rdf.format") + "'";
                    } else {

                        message = "'" + resource + "' transformed but result is empty.";
                    }
                }
            } else {

                message = "'" + resource + "' not transformed: error in task execution.";
            }
        }
    } catch (Exception e) {

        logger.error("[" + config.getProperty("service.name") + "] Processing resource '" + resource
                + "' failed with a " + e.getClass().getSimpleName());
        e.printStackTrace();
    }

    return message;
}

From source file:org.rhwlab.dispim.nucleus.NucleusData.java

public NucleusData(JsonObject jsonObj) {
    this.time = jsonObj.getInt("Time");
    this.name = jsonObj.getString("Name");
    String precString = jsonObj.getJsonString("Precision").getString();
    this.A = precisionFromString(precString);
    this.xC = jsonObj.getJsonNumber("X").longValue();
    this.yC = jsonObj.getJsonNumber("Y").longValue();
    this.zC = jsonObj.getJsonNumber("Z").longValue();
    this.exp = jsonObj.getJsonNumber("Expression").longValue();

    this.eigenA = new EigenDecomposition(A);
    this.adjustedA = this.A.copy();
    this.adjustedEigenA = new EigenDecomposition(adjustedA);

    double[] adj = new double[3];
    adj[0] = adj[1] = adj[2] = 1.0;//from   w w  w  .j  a va 2 s. c om
    this.setAdjustment(adj);
}