List of usage examples for javax.json JsonObjectBuilder add
JsonObjectBuilder add(String name, JsonArrayBuilder builder);
From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.UpdateRegisteredSEEsHandler.java
private Report updateSEE(SEE see) throws ClientProtocolException, IOException { String serviceName = "updateSEE"; JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); if (see.getSeeID() != null && !see.getSeeID().trim().isEmpty()) { jsonBuilder.add("seeId", see.getSeeID()); }// w w w . ja va2 s .co m if (see.getMESNodeID() != null && !see.getMESNodeID().trim().isEmpty()) { jsonBuilder.add("nodeId", see.getMESNodeID().replaceAll("ns", "").replaceAll("i", "").replace("=", "")); } if (see.getResource() != null) { jsonBuilder.add("assetTypeNames", see.getResource().getName()); } if (see.getOpcUAAddress() != null && !see.getOpcUAAddress().trim().isEmpty()) { jsonBuilder.add("opcuaAddress", see.getOpcUAAddress()); } jsonBuilder.add("simulation", see.isSimulation() + ""); if (see.getAmlDescription() != null && !see.getAmlDescription().trim().isEmpty()) { jsonBuilder.add("amlFile", see.getAmlDescription()); } HttpPost request = new HttpPost(AMSServiceUtility.serviceAddress + serviceName); request.setEntity(new StringEntity(jsonBuilder.build().toString(), "UTF-8")); System.out.println(request.getRequestLine() + " ====================================="); request.setHeader("Content-type", "application/json"); HttpClient client = HttpClientBuilder.create().build(); ; HttpResponse response = client.execute(request); String resp = EntityUtils.toString(response.getEntity()); return JSONUtility.convertToObject(resp, Report.class); }
From source file:com.product.ProductResource.java
@GET @Path("{id}") @Produces(MediaType.APPLICATION_JSON)/*w w w . j a v a 2 s. com*/ public String getproduct(@PathParam("id") int id) throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product where product_id = ?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); String result = ""; JsonArrayBuilder productArr = Json.createArrayBuilder(); while (rs.next()) { JsonObjectBuilder prodMap = Json.createObjectBuilder(); prodMap.add("productID", rs.getInt("product_id")); prodMap.add("name", rs.getString("name")); prodMap.add("description", rs.getString("description")); prodMap.add("quantity", rs.getInt("quantity")); productArr.add(prodMap); } result = productArr.build().toString(); return result; } }
From source file:org.rhwlab.dispim.nucleus.BHCNucleusData.java
public JsonObjectBuilder asJson() { JsonObjectBuilder ret = super.asJson(); ret.add("SourceNode", this.sourceNode); ret.add("Count", this.count); ret.add("Voxels", this.voxels); ret.add("Intensity", this.totalIntensity); return ret;//w w w. ja v a 2 s . c o m }
From source file:nl.sidn.dnslib.message.records.dnssec.NSEC3ResourceRecord.java
@Override public JsonObject toJSon() { JsonObjectBuilder builder = super.createJsonBuilder(); builder.add("rdata", Json.createObjectBuilder().add("hash-algorithm", hashAlgorithm.name()).add("flags", flags) .add("iterations", (int) iterations).add("salt-length", saltLength) .add("salt", Hex.encodeHexString(salt)).add("hash-length", (int) hashLength) .add("nxt-own-name", nexthashedownername)); JsonArrayBuilder typeBuilder = Json.createArrayBuilder(); for (TypeMap type : types) { typeBuilder.add(type.getType().name()); }//w w w. j av a 2 s. co m return builder.add("types", typeBuilder.build()).build(); }
From source file:co.runrightfast.core.application.event.AppEvent.java
private void addMessage(final JsonObjectBuilder json) { if (message != null) { json.add("msg", message); }/*from ww w .j a va2 s . c om*/ }
From source file:co.runrightfast.core.application.event.AppEvent.java
private void addVerticleId(final JsonObjectBuilder json) { if (verticleId != null) { json.add("verticleId", verticleId.toJson()); }/*from w ww . j a v a2 s . co m*/ }
From source file:co.runrightfast.core.application.event.AppEvent.java
private void addData(final JsonObjectBuilder json) { if (data == null) { return;//from w w w . j a va 2s . c o m } json.add("data", Json.createObjectBuilder().add(data.getType(), data.toJson())); }
From source file:com.assignment4.productdetails.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *///from www . j a v a2 s. co m @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (conn == null) { return "it is not connected"; } else { String query = "Select * from products"; PreparedStatement pstmt = conn.prepareStatement(query); ResultSet res = pstmt.executeQuery(); String results = ""; JsonArrayBuilder podtAr = Json.createArrayBuilder(); while (res.next()) { // Map pdtmap = new LinkedHashMap(); JsonObjectBuilder obj = Json.createObjectBuilder();//using json object for using json api obj.add("productID", res.getInt("product_id")); obj.add("name", res.getString("name")); obj.add("description", res.getString("description")); obj.add("quantity", res.getInt("quantity")); podtAr.add(obj); } results = podtAr.build().toString(); return results.replace("},", "},\n"); } }
From source file:org.piwik.java.tracking.PiwikTracker.java
/** * Send multiple requests in a single HTTP call. More efficient than sending * several individual requests. Specify the AuthToken if parameters that require * an auth token is used.//from w w w.j a v a 2 s. co m * @param requests the requests to send * @param authToken specify if any of the parameters use require AuthToken * @return the response from these requests * @throws IOException thrown if there was a problem with this connection */ public HttpResponse sendBulkRequest(Iterable<PiwikRequest> requests, String authToken) throws IOException { if (authToken != null && authToken.length() != PiwikRequest.AUTH_TOKEN_LENGTH) { throw new IllegalArgumentException( authToken + " is not " + PiwikRequest.AUTH_TOKEN_LENGTH + " characters long."); } JsonObjectBuilder ob = Json.createObjectBuilder(); JsonArrayBuilder ab = Json.createArrayBuilder(); for (PiwikRequest request : requests) { ab.add("?" + request.getQueryString()); } ob.add(REQUESTS, ab); if (authToken != null) { ob.add(AUTH_TOKEN, authToken); } HttpClient client = getHttpClient(); HttpPost post = new HttpPost(uriBuilder.build()); post.setEntity(new StringEntity(ob.build().toString(), ContentType.APPLICATION_JSON)); return client.execute(post); }
From source file:co.runrightfast.vertx.orientdb.ODatabaseDocumentTxHealthCheck.java
private void browseClass(final ODatabaseDocumentTx db, final Class<? extends DocumentObject> documentObject, final JsonObjectBuilder counts) { final String documentClassName = DocumentObject.documentClassName(documentObject); if (db.getMetadata().getSchema().getClass(documentClassName) == null) { counts.add(documentClassName, -1); return;/*w ww . java 2s . co m*/ } final ORecordIteratorClass<ODocument> it = db.browseClass(documentClassName); if (it.hasNext()) { it.next(); counts.add(documentClassName, 1); } else { counts.add(documentClassName, 0); } }