Example usage for javax.json JsonObject getInt

List of usage examples for javax.json JsonObject getInt

Introduction

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

Prototype

int getInt(String name);

Source Link

Document

A convenience method for getJsonNumber(name).intValue()

Usage

From source file:mypackage.products.java

@POST
@Consumes("application/json")
public Response post(String str) {
    JsonObject json = Json.createReader(new StringReader(str)).readObject();
    String id = String.valueOf(json.getInt("productId"));
    String name = json.getString("name");
    String description = json.getString("description");
    String qty = String.valueOf(json.getInt("quantity"));
    int status = doUpdate("INSERT INTO PRODUCT (productId, name, description, quantity) VALUES (?, ?, ?, ?)",
            id, name, description, qty);
    if (status == 0) {
        return Response.status(500).build();
    } else {//from  w  w  w.  j  a  v a2s  . co m
        return Response.ok("http://localhost:8080/CPD-4414-Assignment-4/products/" + id, MediaType.TEXT_HTML)
                .build();
    }
}

From source file:co.runrightfast.vertx.orientdb.ODatabaseDocumentTxHealthCheck.java

private boolean isHealthy(final JsonObject healthcheckData) {
    if (documentObjects.isEmpty()) {
        return true;
    }//from  ww w  .  j  a  va2 s. c  o m

    final JsonObject counts = healthcheckData.getJsonObject("counts");
    return !documentObjects.stream()
            .filter(clazz -> counts.getInt(DocumentObject.documentClassName(clazz)) == -1).findFirst()
            .isPresent();
}

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:com.natixis.appdynamics.traitements.GetInfoLicense.java

public Map<String, Object> RetrieveInfoLicense() throws ClientProtocolException, IOException {
    Map<String, Object> myMapInfoLicense = new HashMap<String, Object>();

    HttpClient client = new DefaultHttpClient();

    String[] chaineUrl = GetParamApplication.urlApm.split("/" + "/");
    String hostApm = chaineUrl[1];

    URI uri = null;/*w  w w.  j a  v  a2s.  c  o  m*/
    try {
        uri = new URIBuilder().setScheme("http").setHost(hostApm).setPath(GetParamApplication.uriInfoLicense)
                .setParameter("startdate", GetDateInfoLicence()).setParameter("enddate", GetDateInfoLicence())
                .build();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(hostApm, 80),
            new UsernamePasswordCredentials(GetParamApplication.userApm, GetParamApplication.passwordApm));
    HttpGet request = new HttpGet(uri);
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    String jsonContent = EntityUtils.toString(entity);
    Reader stringReader = new StringReader(jsonContent);
    JsonReader rdr = Json.createReader(stringReader);
    JsonObject obj = rdr.readObject();
    JsonArray results = obj.getJsonArray("usages");

    for (JsonObject result : results.getValuesAs(JsonObject.class)) {
        BeanInfoLicense myBeanInfoLicense = new BeanInfoLicense(result.getString("agentType"),
                result.getInt("avgUnitsAllowed"), result.getInt("avgUnitsUsed"));
        myMapInfoLicense.put(result.getString("agentType"), myBeanInfoLicense);
        //System.out.println(result.getString("agentType")+","+result.getInt("avgUnitsAllowed")+","+result.getInt("avgUnitsUsed"));
    }

    return myMapInfoLicense;
}

From source file:service.NewServlet.java

@PUT
@Path("{productId}")
public Response doPut(@PathParam("productId") String id, JsonObject obj) {

    // JSONObject obj = (JSONObject) new JSONParser().parse(st);
    //  id =  obj.getString("productId");
    String name = obj.getString("name");
    String quantity = String.valueOf(obj.getInt("quantity"));
    String description = obj.getString("description");

    Connection conn = Connect.getConnection();
    doUpdate("UPDATE product SET name=?,description=?,quantity=? where productId=? ", name, description,
            quantity, id);//from  w  w  w.j  a  v a 2s. com

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

}

From source file:Servlet.newServlet.java

@POST
@Consumes("application/json")
@Produces("application/json")
public Response add(JsonObject json) {

    String name = json.getString("name");
    String description = json.getString("description");
    String quantity = String.valueOf(json.getInt("quantity"));

    System.out.println(name + '\t' + description + '\t' + quantity);

    int result = doUpdate("INSERT INTO product (name,description,quantity) VALUES (?,?,?)", name, description,
            quantity);/*from   w  w w  .j  a v  a2s .  c  om*/
    if (result <= 0) {
        return Response.status(500).build();
    } else {
        return Response.ok(json).build();
    }
}

From source file:Servlet.newServlet.java

@PUT
@Path("{id}")
@Consumes("application/json")
@Produces("application/json")
public Response updateData(@PathParam("id") String id, JsonObject json) {

    String name = json.getString("name");
    String description = json.getString("description");
    String quantity = String.valueOf(json.getInt("quantity"));

    System.out.println(name + '\t' + description + '\t' + quantity + '\t' + id);

    int result = doUpdate("UPDATE product SET name=?,description=?,quantity=? where productID=?", name,
            description, quantity, String.valueOf(id));
    if (result <= 0) {
        return Response.status(500).build();
    } else {/*from  ww w .  j  a v a2 s  .c o  m*/
        return Response.ok(json).build();
    }
}

From source file:eu.forgetit.middleware.component.Condensator.java

public void imageClustering_bkp(Exchange exchange) {

    logger.debug("New message retrieved");

    JsonObject headers = MessageTools.getHeaders(exchange);

    long taskId = headers.getInt("taskId");
    scheduler.updateTask(taskId, TaskStatus.RUNNING, "IMAGE CLUSTERING", null);

    MessageTools.setHeaders(exchange, headers);

    JsonObject jsonBody = MessageTools.getBody(exchange);

    if (jsonBody != null) {

        try {/*from w  ww .  jav  a2s.  c o m*/

            String jsonNofImagesElement = jsonBody.getString("numOfImages");
            String minCLusteringImages = headers.getString("minClusteringImages");

            int nofImages = 0;
            int minNofImages = 0;

            if (jsonNofImagesElement != null)
                nofImages = Integer.parseInt(jsonNofImagesElement);

            if (minCLusteringImages != null)
                minNofImages = Integer.parseInt(minCLusteringImages);
            else
                minNofImages = 0;

            String jsonImageAnalysisResult = jsonBody.getString("imageAnalysis-all");
            if (jsonImageAnalysisResult != null)
                imageAnalysisResult = jsonImageAnalysisResult;
            logger.debug("Retrieved Image Analysis Result: " + imageAnalysisResult);

            String jsonMetadataDir = jsonBody.getString("sipMetadataDir");
            if (jsonMetadataDir != null)
                sipMetadataDirPath = jsonMetadataDir;
            logger.debug("Retrieved SIP Metadata Directory: " + sipMetadataDirPath);

            if (nofImages >= minNofImages) {

                logger.debug("Executing Image Collection Clustering");

                String response = service.request(imageAnalysisResult);

                logger.debug("Clustering result:\n" + response);

                File resultFile = new File(sipMetadataDirPath, "clustering.xml");

                FileUtils.writeStringToFile(resultFile, response);

                JsonObjectBuilder job = Json.createObjectBuilder();

                job.add("clustering", resultFile.getAbsolutePath());

                for (Entry<String, JsonValue> entry : jsonBody.entrySet()) {
                    job.add(entry.getKey(), entry.getValue());
                }

                exchange.getIn().setBody(jsonBody.toString());

            } else {

                logger.debug("Found only " + nofImages + " images, below threshold (" + minCLusteringImages
                        + ")... skipping.");
            }

        } catch (NumberFormatException | IOException e) {

            e.printStackTrace();
        }

    } else {

        JsonObjectBuilder job = Json.createObjectBuilder().add("taskStatus", TaskStatus.FAILED.toString());

        for (Entry<String, JsonValue> entry : headers.entrySet()) {
            job.add(entry.getKey(), entry.getValue());
        }

        MessageTools.setHeaders(exchange, headers);

    }

}

From source file:com.rhcloud.javaee.movieinfo.business.actor.boundry.ActorResourceIT.java

@Test
public void get_all_actors() {

    Response getResponse = null;//from w w w .  j ava 2  s  . com

    try {
        getResponse = provider.target().path("/" + ACTORS_PATH).request(APPLICATION_JSON).get();
    } finally {
        System.out.println("Server responded ? " + (getResponse != null));
        assumeThat(getResponse, is(notNullValue()));
    }

    assertThat(getResponse, is(successful()));
    assertThat(getResponse.hasEntity(), is(true));

    JsonArray payload = getResponse.readEntity(JsonArray.class);
    assertThat(payload, is(notNullValue()));
    final int size = payload.size();
    assertThat(size, is(not(0)));

    JsonObject value = payload.getJsonObject(size - 1);
    assertThat(value, is(notNullValue()));
    assertThat(value.getInt("id") >= size, is(true));
}

From source file:mypackage.products.java

@PUT
@Path("{id}")
@Consumes("application/json")
public Response putData(String str, @PathParam("id") int id) {
    JsonObject json = Json.createReader(new StringReader(str)).readObject();
    String id1 = String.valueOf(id);
    String name = json.getString("name");
    String description = json.getString("description");
    String qty = String.valueOf(json.getInt("quantity"));
    int status = doUpdate(
            "UPDATE PRODUCT SET productId= ?, name = ?, description = ?, quantity = ? WHERE productId = ?", id1,
            name, description, qty, id1);
    if (status == 0) {
        return Response.status(500).build();
    } else {/*from   ww w  .  j a  va  2s.  co m*/
        return Response.ok("http://localhost:8080/CPD-4414-Assignment-4/products/" + id, MediaType.TEXT_HTML)
                .build();
    }
}