List of usage examples for javax.json Json createObjectBuilder
public static JsonObjectBuilder createObjectBuilder()
From source file:com.seniorproject.semanticweb.services.WebServices.java
public String prepareResultWithCount(ArrayList<String> in) throws IOException { Multiset<String> multiset = HashMultiset.create(); for (int i = 0; i < in.size(); i++) { if (in.get(i).length() > 0 && !in.get(i).equals("\"\"")) { multiset.add(in.get(i));/*from w w w. ja v a 2 s . co m*/ } } JsonArrayBuilder out = Json.createArrayBuilder(); JsonObjectBuilder resultObject = Json.createObjectBuilder(); for (Multiset.Entry<String> entry : multiset.entrySet()) { List<String> matchList = new ArrayList<>(); Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'"); Matcher regexMatcher = regex.matcher(entry.getElement()); while (regexMatcher.find()) { matchList.add(regexMatcher.group()); } resultObject.add("elem", matchList.get(0)); resultObject.add("count", entry.getCount()); if (matchList.size() >= 2) { String label = ""; for (int j = 1; j < matchList.size(); j++) { label += matchList.get(j); } resultObject.add("label", label); } else { resultObject.add("label", ""); } out.add(resultObject); } return out.build().toString(); }
From source file:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java
/** * Archive a product sku./*from w w w .j a va 2 s . c o m*/ * * Archiving a SKU allows the retailer to "deactivate" a SKU from the catalog. * At any point in time, a retailer may decide to "reactivate" the SKU * @param sku * @param isArchived Indicates whether the specified SKU is archived. 'true' - SKU is inactive 'false' - SKU is potentially sellable * @return * @throws APIException * @throws JetException */ @Override public IJetAPIResponse sendPutArchiveSku(final String sku, final boolean isArchived) throws APIException, JetException { checkSku(sku); APILog.info(LOG, "Sending archive sku:", sku); final IJetAPIResponse response = put(config.getArchiveSkuURL(sku), Json.createObjectBuilder().add("is_archived", isArchived).build().toString(), getJSONHeaderBuilder().build()); return response; }
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
private JsonObject idToJsonObject() { JsonObjectBuilder ob = Json.createObjectBuilder(); ob.add("id", enrollmentID); ob.add("type", type); if (null != maxEnrollments) { ob.add("max_enrollments", maxEnrollments); }/* ww w. j a v a2 s . c om*/ if (affiliation != null) { ob.add("affiliation", affiliation); } JsonArrayBuilder ab = Json.createArrayBuilder(); for (Attribute attr : attrs) { ab.add(attr.toJsonObject()); } ob.add("attrs", ab.build()); if (this.secret != null) { ob.add("secret", secret); } if (client.getCAName() != null) { ob.add(HFCAClient.FABRIC_CA_REQPROP, client.getCAName()); } return ob.build(); }
From source file:io.bitgrillr.gocddockerexecplugin.DockerExecPluginTest.java
@Test public void handleExecuteImageNotFound() throws Exception { UnitTestUtils.mockJobConsoleLogger(); PowerMockito.mockStatic(DockerUtils.class); PowerMockito.doThrow(new ImageNotFoundException("idont:exist")).when(DockerUtils.class); DockerUtils.pullImage(anyString());//w w w.j a v a 2s. c om DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, "execute"); JsonObject requestBody = Json.createObjectBuilder() .add("config", Json.createObjectBuilder() .add("IMAGE", Json.createObjectBuilder().add("value", "idont:exist").build()) .add("COMMAND", Json.createObjectBuilder().add("value", "ls").build()) .add("ARGUMENTS", Json.createObjectBuilder().build()).build()) .add("context", Json.createObjectBuilder().add("workingDirectory", "pipelines/test") .add("environmentVariables", Json.createObjectBuilder().build()).build()) .build(); request.setRequestBody(requestBody.toString()); final GoPluginApiResponse response = new DockerExecPlugin().handle(request); assertEquals("Expected 2xx response", DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE, response.responseCode()); final JsonObject responseBody = Json.createReader(new StringReader(response.responseBody())).readObject(); assertEquals("Expected failure", Boolean.FALSE, responseBody.getBoolean("success")); assertEquals("Message wrong", "Image 'idont:exist' not found", responseBody.getString("message")); }
From source file:edu.harvard.iq.dataverse.mydata.MyDataFinder.java
/** * "publication_statuses" : [ name 1, name 2, etc.] * /*from ww w.ja v a 2 s . c o m*/ * @return */ public JsonObjectBuilder getSelectedFilterParamsAsJSON() { JsonObjectBuilder jsonData = Json.createObjectBuilder(); jsonData.add("publication_statuses", this.filterParams.getListofSelectedPublicationStatuses()) .add("role_names", this.getListofSelectedRoles()); return jsonData; }
From source file:skillpro.asset.views.wizardpages.ConfirmationPage.java
private void registerSEE(SEE see) throws ClientProtocolException, IOException { System.out.println("SEE[seeID: " + see.getSeeID() + ", opcuaMES: " + see.getMESCommunication().getSecondElement() + "opcua: " + see.getOpcUAAddress() + ", amlFile: " + !see.getAmlDescription().isEmpty() + "]"); String serviceName = "registerSEE"; JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); if (see.getSeeID() != null && !see.getSeeID().trim().isEmpty()) { jsonBuilder.add("seeId", see.getSeeID() == null ? UUID.randomUUID().toString() : see.getSeeID()); }/*from w ww . j a v a 2 s .com*/ if (see.getMESCommunication().getFirstElement() == MESCommType.OPCUA) { jsonBuilder.add("opcuaAddress", see.getMESCommunication().getSecondElement()); } if (see.getResource() != null) { jsonBuilder.add("assetTypeNames", see.getResource().getName()); } 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(); ; client.execute(request); }
From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java
/** Create an access point for a version, for a SPARQL endpoint. * Don't duplicate it, if it already exists. * @param version The version for which the access point is to be created. * @param portalUri The URI to put into the portalData. * @param source The source of the endpoint, either SYSTEM_SOURCE * or USER_SOURCE.// ww w . j a va2 s . c o m */ public static void createApiSparqlAccessPoint(final Version version, final String portalUri, final String source) { List<AccessPoint> aps = getAccessPointsForVersionAndType(version, AccessPoint.API_SPARQL_TYPE); for (AccessPoint ap : aps) { if (portalUri.equals(getPortalUri(ap))) { // Already exists. Don't bother checking the source. return; } } // No existing access point for this file, so create a new one. AccessPoint ap = new AccessPoint(); ap.setVersionId(version.getId()); ap.setType(AccessPoint.API_SPARQL_TYPE); JsonObjectBuilder jobPortal = Json.createObjectBuilder(); JsonObjectBuilder jobToolkit = Json.createObjectBuilder(); jobPortal.add("uri", portalUri); jobPortal.add("source", source); ap.setPortalData(jobPortal.build().toString()); ap.setToolkitData(jobToolkit.build().toString()); AccessPointUtils.saveAccessPoint(ap); }
From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java
@Override public String browseEventLogRecords(int skip, int limit) { final CompletableFuture<GetEvents.Response> future = new CompletableFuture<>(); vertx.eventBus().send(EventBusAddress.eventBusAddress(EventLogRepository.VERTICLE_ID, GetEvents.class), GetEvents.Request.newBuilder().setSkip(skip).setLimit(limit).build(), new DeliveryOptions().setSendTimeout(2000L), responseHandler(future, GetEvents.Response.class)); try {//from w w w .ja va 2 s . c o m final GetEvents.Response response = future.get(2, TimeUnit.SECONDS); return JsonUtils.toVertxJsonObject(Json.createObjectBuilder().add("count", response.getEventsCount()) .add("records", ProtobufUtils.protobuMessageToJson(response)).build()).encodePrettily(); } catch (final InterruptedException | ExecutionException | TimeoutException ex) { log.logp(SEVERE, getClass().getName(), "createEventLogRecord", "failed", ex); throw new RuntimeException("Failed to create event log record : " + ex.getMessage()); } }
From source file:eu.forgetit.middleware.component.Extractor.java
public void videoNDDAnalysis(Exchange exchange) { logger.debug("New message retrieved"); JsonObject jsonBody = MessageTools.getBody(exchange); JsonObjectBuilder job = Json.createObjectBuilder(); for (Entry<String, JsonValue> entry : jsonBody.entrySet()) { job.add(entry.getKey(), entry.getValue()); }/* w w w . j a v a2 s. c o m*/ if (jsonBody != null) { //String videoPaths = getVideoPath(jsonBody); String videoPath = jsonBody.getString("videoPath"); logger.debug("Retrieved Video Path: " + videoPath); job.add("videoPath", videoPath); //String method = jsonBody.getString("method"); //System.out.println("Retrieved VAM: "+method); // ONE video per call if (videoPath != null && !videoPath.isEmpty()) { logger.debug("Executing Video Analysis Method: Near Duplicate Detection"); String response_tmp = service.video_ndd_request(videoPath); logger.debug("Video NDD Analysis method result:\n" + response_tmp); // call id is returned at the response String callid; String[] callid_tmp = response_tmp.split("::"); callid = callid_tmp[1].trim(); String response = service.video_ndd_result(callid); logger.debug("Video NDD result:\n" + response); job.add("result", response); } else { logger.debug("Unable to process video, wrong request"); job.add("result", "Unable to process video, wrong request"); } exchange.getOut().setBody(job.build().toString()); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); } }
From source file:com.yoshio3.modules.AzureADServerAuthModule.java
private String[] getGroupList(AzureADUserPrincipal userPrincipal) { String authString = "Bearer " + userPrincipal.getAuthenticationResult().getAccessToken(); System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); String graphURL = String.format("https://%s/%s/users/%s/getMemberGroups", graphServer, tenant, userPrincipal.getName());//from ww w.j a v a2 s . c o m JsonObject model = Json.createObjectBuilder().add("securityEnabledOnly", "false").build(); StringWriter stWriter = new StringWriter(); try (JsonWriter jsonWriter = Json.createWriter(stWriter)) { jsonWriter.writeObject(model); } String jsonData = stWriter.toString(); Future<Response> response = getConnectionFactory().target(graphURL).request().header("Host", graphServer) .header("Accept", "application/json, text/plain, */*").header("Content-Type", "application/json") .header("api-version", "1.6").header("Authorization", authString).async() .post(Entity.json(jsonData)); try { ADUserMemberOfGroups memberOfGrups; memberOfGrups = response.get().readEntity(ADUserMemberOfGroups.class); LOGGER.log(Level.INFO, memberOfGrups.toString()); return memberOfGrups.getValue(); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(AzureADServerAuthModule.class.getName()).log(Level.SEVERE, null, ex); return null; } }