Example usage for javax.json JsonObject getString

List of usage examples for javax.json JsonObject getString

Introduction

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

Prototype

String getString(String name);

Source Link

Document

A convenience method for getJsonString(name).getString()

Usage

From source file:co.runrightfast.vertx.core.RunRightFastVerticleId.java

public RunRightFastVerticleId(@NonNull final JsonObject json) {
    this(json.getString("group"), json.getString("name"), json.getString("version"));
}

From source file:org.ocelotds.integration.AbstractOcelotTest.java

/**
 * Becareful result is not unmarshalled//  w ww.j av  a2 s.  c  om
 *
 * @param json
 * @return
 */
protected static MessageToClient mtcFromJson(String json) {
    try (JsonReader reader = Json.createReader(new StringReader(json))) {
        JsonObject root = reader.readObject();
        MessageToClient message = new MessageToClient();
        message.setId(root.getString(Constants.Message.ID));
        message.setTime(root.getInt(Constants.Message.TIME));
        message.setType(MessageType.valueOf(root.getString(Constants.Message.TYPE)));
        message.setDeadline(root.getInt(Constants.Message.DEADLINE));
        if (null != message.getType()) {
            switch (message.getType()) {
            case FAULT:
                JsonObject faultJs = root.getJsonObject(Constants.Message.RESPONSE);
                Fault f = Fault.createFromJson(faultJs.toString());
                message.setFault(f);
                break;
            case MESSAGE:
                message.setResult("" + root.get(Constants.Message.RESPONSE));
                message.setType(MessageType.MESSAGE);
                break;
            case CONSTRAINT:
                JsonArray result = root.getJsonArray(Constants.Message.RESPONSE);
                List<ConstraintViolation> list = new ArrayList<>();
                for (JsonValue jsonValue : result) {
                    list.add(getJava(ConstraintViolation.class, ((JsonObject) jsonValue).toString()));
                }
                message.setConstraints(list.toArray(new ConstraintViolation[] {}));
                break;
            default:
                message.setResult("" + root.get(Constants.Message.RESPONSE));
                break;
            }
        }
        return message;
    }
}

From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavendependency.MavenDependencyDeleteAction.java

@Override
public void handle(Request request, Response response) throws Exception {
    JsonReader jsonReader = Json//from  w  w  w .jav  a 2 s. c  o m
            .createReader(new StringReader(request.param(MavenDependencyConfiguration.PARAM)));
    JsonObject jsonObject = jsonReader.readObject();
    jsonReader.close();

    if (StringUtils.isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY))) {
        mavenDependencySettingsService
                .deleteMavenDependency(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY));
        LOGGER.info(MavenDependencyConfiguration.INFO_DELETE_SUCCESS + jsonObject.toString());
        response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK);
    } else {
        LOGGER.error(MavenDependencyConfiguration.ERROR_DELETE_INVALID_INPUT + jsonObject.toString());
        response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED);
    }
}

From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavenlicense.MavenLicenseDeleteAction.java

@Override
public void handle(Request request, Response response) throws Exception {
    JsonReader jsonReader = Json.createReader(new StringReader(request.param(MavenLicenseConfiguration.PARAM)));
    JsonObject jsonObject = jsonReader.readObject();
    jsonReader.close();//ww  w  . j  av  a 2 s .  c  o  m

    if (StringUtils.isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX))) {
        mavenLicenseSettingsService
                .deleteMavenLicense(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX));
        LOGGER.info(MavenLicenseConfiguration.INFO_DELETE_SUCCESS + jsonObject.toString());
        mavenLicenseSettingsService.sortMavenLicenses();
        response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK);
    } else {
        LOGGER.error(MavenLicenseConfiguration.ERROR_DELETE_INVALID_INPUT + jsonObject.toString());
        response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED);
    }
}

From source file:org.wildfly.test.integration.microprofile.health.MicroProfileHealthHTTPEndpointTestCase.java

void checkGlobalOutcome(ManagementClient managementClient, boolean mustBeUP, String probeName)
        throws IOException {

    final String healthURL = "http://" + managementClient.getMgmtAddress() + ":"
            + managementClient.getMgmtPort() + "/health";

    try (CloseableHttpClient client = HttpClients.createDefault()) {

        CloseableHttpResponse resp = client.execute(new HttpGet(healthURL));
        assertEquals(mustBeUP ? 200 : 503, resp.getStatusLine().getStatusCode());

        String content = getContent(resp);
        resp.close();//  w  ww  .  j a  v a2  s . c o  m

        try (JsonReader jsonReader = Json.createReader(new StringReader(content))) {
            JsonObject payload = jsonReader.readObject();
            String outcome = payload.getString("outcome");
            assertEquals(mustBeUP ? "UP" : "DOWN", outcome);

            if (probeName != null) {
                for (JsonValue check : payload.getJsonArray("checks")) {
                    if (probeName.equals(check.asJsonObject().getString("name"))) {
                        // probe name found
                        assertEquals(mustBeUP ? "UP" : "DOWN", check.asJsonObject().getString("state"));
                        return;
                    }
                }
                fail("Probe named " + probeName + " not found in " + content);
            }
        }
    }
}

From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavendependency.MavenDependencyAddAction.java

@Override
public void handle(Request request, Response response) throws Exception {
    JsonReader jsonReader = Json// www .j  av a  2 s  . c  om
            .createReader(new StringReader(request.param(MavenDependencyConfiguration.PARAM)));
    JsonObject jsonObject = jsonReader.readObject();
    jsonReader.close();

    boolean keyIsNotBlank = StringUtils
            .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY));
    boolean licenseIsNotBlank = StringUtils
            .isNotBlank(jsonObject.getString(MavenDependencyConfiguration.PROPERTY_LICENSE));

    if (keyIsNotBlank && licenseIsNotBlank) {
        boolean success = mavenDependencySettingsService.addMavenDependency(
                jsonObject.getString(MavenDependencyConfiguration.PROPERTY_KEY),
                jsonObject.getString(MavenDependencyConfiguration.PROPERTY_LICENSE));

        if (success) {
            LOGGER.info(MavenDependencyConfiguration.INFO_ADD_SUCCESS + jsonObject.toString());
            response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK);
        } else {
            LOGGER.error(MavenDependencyConfiguration.ERROR_ADD_ALREADY_EXISTS + jsonObject.toString());
            response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED);
        }
    } else {
        LOGGER.error(MavenDependencyConfiguration.INFO_ADD_SUCCESS + jsonObject.toString());
        response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED);
    }
}

From source file:at.porscheinformatik.sonarqube.licensecheck.webservice.mavenlicense.MavenLicenseAddAction.java

@Override
public void handle(Request request, Response response) throws Exception {
    JsonReader jsonReader = Json.createReader(new StringReader(request.param(MavenLicenseConfiguration.PARAM)));
    JsonObject jsonObject = jsonReader.readObject();
    jsonReader.close();/*from   w  w  w .j  ava 2s .  c om*/

    boolean keyIsNotBlank = StringUtils
            .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_KEY));
    boolean regexIsNotBlank = StringUtils
            .isNotBlank(jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX));

    if (keyIsNotBlank && regexIsNotBlank) {
        boolean success = mavenLicenseSettingsService.addMavenLicense(
                jsonObject.getString(MavenLicenseConfiguration.PROPERTY_REGEX),
                jsonObject.getString(MavenLicenseConfiguration.PROPERTY_KEY));

        if (success) {
            LOGGER.info(MavenLicenseConfiguration.INFO_ADD_SUCCESS + jsonObject.toString());
            mavenLicenseSettingsService.sortMavenLicenses();
            response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_OK);
        } else {
            LOGGER.error(MavenLicenseConfiguration.ERROR_ADD_ALREADY_EXISTS + jsonObject.toString());
            response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED);
        }
    } else {
        LOGGER.error(MavenLicenseConfiguration.ERROR_ADD_INVALID_INPUT + jsonObject.toString());
        response.stream().setStatus(HTTPConfiguration.HTTP_STATUS_NOT_MODIFIED);
    }
}

From source file:service.NewServlet.java

@POST
@Consumes("application/json")
@Produces("application/json")

public Response doPost(JsonObject obj) {

    //JSONObject obj = new JSONObject();
    String name = obj.getString("name");
    String quantity = String.valueOf(obj.getInt("quantity"));
    String description = obj.getString("description");

    doUpdate("INSERT INTO product (name,description,quantity) VALUES (?,?,?)", name, description, quantity);

    return Response.ok(obj).build();

}

From source file:org.jboss.set.aphrodite.JsonStreamService.java

private Map<String, StreamComponent> parseStreamCodebases(JsonArray codebases) throws NotFoundException {
    Map<String, StreamComponent> codebaseMap = new HashMap<>();
    for (JsonValue value : codebases) {
        JsonObject json = (JsonObject) value;
        String componentName = json.getString("component_name");
        String codebaseName = json.getString("codebase");
        URL repositoryUrl = parseUrl(json.getString("repository_url"));

        Repository repository = aphrodite.getRepository(repositoryUrl);
        Codebase codebase = new Codebase(codebaseName);

        if (!repository.getCodebases().contains(codebase))
            throw new NotFoundException("The specified codebase '" + codebaseName + "' "
                    + "does not belong to the Repository at " + repository.getURL());

        StreamComponent component = new StreamComponent(componentName, repository, codebase);
        codebaseMap.put(component.getName(), component);
    }//  w  w  w  .j  a  va  2  s.com
    return codebaseMap;
}

From source file:br.com.argonavis.jaspictut.service.FacebookConnectService.java

@Override
public UserData authenticate(Map<String, String> credentials, HttpServletRequest request,
        HttpServletResponse response) throws AuthenticationException {

    String token = credentials.get("accessToken");

    // If already authenticated via client API -
    // just retrieve token to set data object to
    // set the principal and group-mapping
    String authDataUrl = "https://graph.facebook.com/me" + "?access_token=" + token + "&appsecret_proof="
            + calculateAppSecretProof(token, facebookAppSecret) + "&fields=id,name,email,picture";

    HttpURLConnection connection = null;
    try {/* w ww .  j  av a  2 s.c  om*/
        URL url = new URL(authDataUrl);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
    } catch (IOException ex) {
        Logger.getLogger(FacebookConnectService.class.getName()).log(Level.SEVERE, null, ex);
    }

    try (InputStream is = connection.getInputStream(); JsonReader rdr = Json.createReader(is)) {

        JsonObject data = rdr.readObject();
        String userid = data.getString("id");
        String email = data.getString("email");
        String name = data.getString("name");
        String picture = data.getJsonObject("picture").getJsonObject("data").getString("url");

        System.out.println("userid: " + userid);
        System.out.println("email: " + email);
        System.out.println("name: " + name);
        System.out.println("picture: " + picture);

        UserData userData = new UserData();

        userData.setUserid(email); // in our app we are using the email as the principal
        userData.setEmail(email);
        userData.setAvatar(picture);
        userData.setName(name);

        request.getSession().setAttribute("userData", userData);

        return userData;
    } catch (IOException ex) {
        Logger.getLogger(FacebookConnectService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}