当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.put方法代码示例

本文整理汇总了Java中us.monoid.json.JSONObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.put方法的具体用法?Java JSONObject.put怎么用?Java JSONObject.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在us.monoid.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.put方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: accquireToken

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
private String accquireToken() throws RestClientException {
	String securityToken = null;
	if (!isServiceRunning()) {
		throw new RestClientException("Id service is not currently running at URL:" + idServiceUrl);
	}
	LOGGER.info("Id service rest client logs in to get a new security token." );
	try {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("username", this.userName);
		jsonObject.put("password", this.password);
		securityToken = (String) resty.json(urlHelper.getLoginUrl(), RestyHelper.content(jsonObject)).get(TOKEN);
		LOGGER.info("Security token is acquired successfully:" + securityToken );
	} catch (Exception e) {
		throw new RestClientException("Failed to login for user name:" + this.userName, e);
	}
	return securityToken;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:18,代码来源:IdServiceRestClientImpl.java

示例2: isTokenValid

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
private boolean isTokenValid(String token) {
	if (token == null) {
		return false;
	}
	boolean isValid = false;
	try {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put(TOKEN, token);
		JSONResource response = resty.json(urlHelper.getTokenAuthenticationUrl(), RestyHelper.content(jsonObject,APPLICATION_JSON));
		if (response != null) {
			if (HttpStatus.SC_OK == (response.getHTTPStatus())) {
				isValid = true;
			} else {
				LOGGER.info("Inavlid token with failure reason from id server:" + response.get(MESSAGE));
			}
		}
	} catch (Exception e) {
		LOGGER.error("Failed to valid token:" + token, e);
	}
	return isValid;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:22,代码来源:IdServiceRestClientImpl.java

示例3: logOut

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public void logOut() throws RestClientException {
	currentSessions.getAndDecrement();
	synchronized (LOCK) {
		if (token != null) {
			LOGGER.info("Total current sessions:" + currentSessions.get());
			if (currentSessions.get() == 0) {
				try {
					JSONObject jsonObject = new JSONObject();
					jsonObject.put(TOKEN, token);
					resty.json(urlHelper.getLogoutUrl(), RestyHelper.content((jsonObject)));
					LOGGER.info("Id service rest client logs out successfully with token:" + token );
					token = null;
				} catch (Exception e) {
					throw new RestClientException("Failed to login out " + this.userName, e);
				}
			}
		}
	}
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:21,代码来源:IdServiceRestClientImpl.java

示例4: getOrCreateSctId

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public Long getOrCreateSctId(UUID componentUuid, Integer namespaceId, String partitionId, String comment) throws RestClientException {
	Long result = null;
	int attempt = 1;
	while (result == null) {
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(NAMESPACE, namespaceId.intValue());
				requestData.put(PARTITION_ID, partitionId);
				requestData.put(SYSTEM_ID, componentUuid.toString());
				requestData.put(SOFTWARE, SRS);
				requestData.put(GENERATE_LEGACY_IDS, "false");
				requestData.put(COMMENT, comment);
				JSONResource response = resty.json(urlHelper.getSctIdGenerateUrl(token), RestyHelper.content((requestData),APPLICATION_JSON));
				if ( response != null && HttpStatus.SC_OK == (response.getHTTPStatus()) ){
					 result = new Long((String)response.get(SCTID));
				} else {
					throw new RestClientException(getFailureMessage(response));
				}
			} catch (Exception e) {
				
				if (attempt < maxTries) {
					LOGGER.warn("Id service failed on attempt {}. Waiting {} seconds before retrying.", attempt, retryDelaySeconds, e);
					attempt++;
					try {
						Thread.sleep(retryDelaySeconds * 1000);
					} catch (InterruptedException ie) {
						LOGGER.warn("Retry dealy interrupted.",e);
					}
				} else {
					throw new RestClientException("Failed to create sctId for uuid:" + componentUuid.toString(), e);
				}
			}
	}
	
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:38,代码来源:IdServiceRestClientImpl.java

示例5: reserveSctIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public List<Long> reserveSctIds(Integer namespaceId, int totalToReserve, String partitionId, String comment) throws RestClientException {
	long startTime = new Date().getTime();
	List<Long> result = new ArrayList<>();
	try {
		JSONObject requestData = new JSONObject();
		requestData.put(NAMESPACE, namespaceId.intValue());
		requestData.put(SOFTWARE, SRS);
		requestData.put(QUANTITY, totalToReserve);
		requestData.put(PARTITION_ID, partitionId);
		requestData.put(COMMENT, comment);
		JSONResource response = resty.json(urlHelper.getSctIdBulkReserveUrl(token), RestyHelper.content((requestData),APPLICATION_JSON));
		if ( HttpStatus.SC_OK == response.getHTTPStatus()) {
			String jobId =  response.get("id").toString();
			LOGGER.info("Bulk job id:" + jobId + " with batch size:" + totalToReserve);
			if (BULK_JOB_STATUS.COMPLETED_WITH_SUCCESS.getCode() == waitForCompleteStatus(jobId, getTimeOutInSeconds())) {
				JSONArray items = resty.json(urlHelper.getBulkJobResultUrl(jobId, token)).array();
				for (int i =0;i < items.length();i++) {
					
					result.add(new Long((String)items.getJSONObject(i).get(SCTID)));
				}
			}
		} else {
			String statusMsg = getFailureMessage(response);
			LOGGER.error(statusMsg);
			throw new RestClientException(statusMsg);
		}
	} catch (Exception e) {
		String message = "Bulk reserving sctIds job failed.";
		LOGGER.error(message, e);
		throw new RestClientException(message,e);
	}
	LOGGER.debug("End reserving sctIds with batch size {} for namespace {}", totalToReserve, namespaceId);
	LOGGER.info("Time taken in seconds:" + (new Date().getTime() - startTime) /1000);
	
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:38,代码来源:IdServiceRestClientImpl.java

示例6: generateSctIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public List<Long> generateSctIds(Integer namespaceId, int totalToGenerate, String partitionId, String comment) throws RestClientException {
	long startTime = new Date().getTime();
	List<Long> result = new ArrayList<>();
	try {
		JSONObject requestData = new JSONObject();
		requestData.put(NAMESPACE, namespaceId.intValue());
		requestData.put(SOFTWARE, SRS);
		requestData.put(QUANTITY, totalToGenerate);
		requestData.put(PARTITION_ID, partitionId);
		requestData.put(GENERATE_LEGACY_IDS, "false");
		requestData.put(COMMENT, comment);
		JSONResource response = resty.json(urlHelper.getSctIdBulkGenerateUrl(token), RestyHelper.content((requestData),APPLICATION_JSON));
		if ( HttpStatus.SC_OK == response.getHTTPStatus()) {
			String jobId =  response.get("id").toString();
			LOGGER.info("Bulk job id:" + jobId + " with batch size:" + totalToGenerate);
			if (BULK_JOB_STATUS.COMPLETED_WITH_SUCCESS.getCode() == waitForCompleteStatus(jobId, getTimeOutInSeconds())) {
				JSONArray items = resty.json(urlHelper.getBulkJobResultUrl(jobId, token)).array();
				for (int i =0;i < items.length();i++) {
					result.add(new Long((String)items.getJSONObject(i).get(SCTID)));
				}
			}
		} else {
			String statusMsg = getFailureMessage(response);
			LOGGER.error(statusMsg);
			throw new RestClientException(statusMsg);
		}
	} catch (Exception e) {
		String message = "Bulk generating sctIds job failed.";
		LOGGER.error(message, e);
		throw new RestClientException(message,e);
	}
	
	LOGGER.debug("End generating sctIds with batch size {} for namespace {}", totalToGenerate, namespaceId);
	LOGGER.info("Time taken in seconds:" + (new Date().getTime() - startTime) /1000);
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:38,代码来源:IdServiceRestClientImpl.java

示例7: getStatusForSctIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public Map<Long,String> getStatusForSctIds(Collection<Long> sctIds) throws RestClientException {
	Map<Long,String> result = new HashMap<>();
	if (sctIds == null || sctIds.isEmpty()) {
		return result;
	}
	StringBuilder scdStrList = new StringBuilder();
	boolean isFirst = true;
	for (Long id : sctIds) {
		if (!isFirst) {
			scdStrList.append(",");
		}
		if (isFirst) {
			isFirst = false;
		}
		scdStrList.append(id.toString());
	}
	int attempt = 1;
	boolean isDone = false;
	while (!isDone) {
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(SCTIDS, scdStrList.toString());
				JSONResource response = resty.json(urlHelper.getSctIdBulkUrl(token),RestyHelper.content(requestData, APPLICATION_JSON));
				if ( response != null && HttpStatus.SC_OK == (response.getHTTPStatus()) ){
					JSONArray items = response.array();
					for (int i =0; i < items.length();i++) {
						result.put(new Long((String)items.getJSONObject(i).get(SCTID)), (String)items.getJSONObject(i).get(STATUS));
					}
				} else {
					throw new RestClientException(getFailureMessage(response));
				}
				isDone = true;
			} catch (Exception e) {
				
				if (attempt < maxTries) {
					LOGGER.warn("Id service failed on attempt {}. Waiting {} seconds before retrying.", attempt, retryDelaySeconds, e);
					attempt++;
					try {
						Thread.sleep(retryDelaySeconds * 1000);
					} catch (InterruptedException ie) {
						LOGGER.warn("Retry dealy interrupted.",e);
					}
				} else {
					throw new RestClientException("Failed to get sctIds for batch size:" + sctIds.size(), e);
				}
			}
	}
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:51,代码来源:IdServiceRestClientImpl.java

示例8: getOrCreateSctIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public HashMap<UUID,Long> getOrCreateSctIds(List<UUID> uuids,Integer namespaceId,String partitionId, String comment) throws RestClientException {
	LOGGER.debug("Start creating sctIds with batch size {} for namespace {} and partitionId {}", uuids.size(), namespaceId, partitionId);
	HashMap<UUID, Long> result = new HashMap<>();
	if (uuids == null || uuids.isEmpty()) {
		LOGGER.warn("Empty UUIDs submitted for requesting sctIds");
		return result;
	}
	long startTime = new Date().getTime();
	List<String> batchJob = null;
	int counter=0;
	for (UUID uuid : uuids) {
		if (batchJob == null) {
			batchJob = new ArrayList<>();
		}
		batchJob.add(uuid.toString());
		counter++;
		if (counter % batchSize == 0 || counter == uuids.size()) {
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(NAMESPACE, namespaceId.intValue());
				requestData.put(PARTITION_ID, partitionId);
				requestData.put(QUANTITY,batchJob.size());
				requestData.put(SYSTEM_IDS, batchJob.toArray());
				requestData.put(SOFTWARE, SRS);
				requestData.put(GENERATE_LEGACY_IDS, "false");
				requestData.put(COMMENT, comment);
				JSONResource response = resty.json(urlHelper.getSctIdBulkGenerateUrl(token), RestyHelper.content((requestData),APPLICATION_JSON));
				if ( HttpStatus.SC_OK == response.getHTTPStatus()) {
					String jobId =  response.get("id").toString();
					LOGGER.info("Bulk job id:" + jobId + " with batch size:" + batchJob.size());
					if (BULK_JOB_STATUS.COMPLETED_WITH_SUCCESS.getCode() == waitForCompleteStatus(jobId, getTimeOutInSeconds())) {
						JSONArray items = resty.json(urlHelper.getBulkJobResultUrl(jobId, token)).array();
						for (int i =0;i < items.length();i++) {
							result.put(UUID.fromString((String)items.getJSONObject(i).get(SYSTEM_ID)), new Long((String)items.getJSONObject(i).get(SCTID)));
						}
					}
				} else {
					String statusMsg = getFailureMessage(response);
					LOGGER.error(statusMsg);
					throw new RestClientException(statusMsg);
				}
			} catch (Exception e) {
				String message = "Bulk getOrCreateSctIds job failed.";
				LOGGER.error(message, e);
				throw new RestClientException(message,e);
			}
			batchJob = null;
		}
	}
	LOGGER.debug("End creating sctIds with batch size {} for namespace {} and partitionId {}", uuids.size(), namespaceId, partitionId);
	LOGGER.info("Time taken in seconds:" + (new Date().getTime() - startTime) /1000);
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:55,代码来源:IdServiceRestClientImpl.java

示例9: getOrCreateSchemeIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public Map<UUID, String> getOrCreateSchemeIds(List<UUID> uuids, SchemeIdType schemeType, String comment) throws RestClientException {
	LOGGER.debug("Start creating scheme id {} with batch size {} ", schemeType, uuids.size());
	HashMap<UUID, String> result = new HashMap<>();
	if (uuids == null || uuids.isEmpty()) {
		LOGGER.warn("Empty UUIDs submitted for requesting schemeIdType:" + schemeType);
		return result;
	}
	long startTime = new Date().getTime();
	List<String> batchJob = null;
	int counter=0;
	for (UUID uuid : uuids) {
		if (batchJob == null) {
			batchJob = new ArrayList<>();
		}
		batchJob.add(uuid.toString());
		counter++;
		if (counter % batchSize == 0 || counter == uuids.size()) {
			//processing batch
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(QUANTITY,batchJob.size());
				requestData.put(SYSTEM_IDS, batchJob.toArray());
				requestData.put(SOFTWARE, SRS);
				requestData.put(COMMENT, comment);
				JSONResource response = resty.json(urlHelper.getSchemeIdBulkGenerateUrl(token, schemeType), RestyHelper.content((requestData),APPLICATION_JSON));
				if ( HttpStatus.SC_OK == response.getHTTPStatus()) {
					String jobId =  response.get("id").toString();
					LOGGER.info("Scheme ids bulk job id:" + jobId + " with batch size:" + batchJob.size());
					if (BULK_JOB_STATUS.COMPLETED_WITH_SUCCESS.getCode() == waitForCompleteStatus(jobId, getTimeOutInSeconds())) {
						JSONArray items = resty.json(urlHelper.getBulkJobResultUrl(jobId, token)).array();
						for (int i =0;i < items.length();i++) {
							result.put(UUID.fromString((String)items.getJSONObject(i).get(SYSTEM_ID)), (String)items.getJSONObject(i).get(SCHEME_ID));
						}
					}
				} else {
					throw new RestClientException(getFailureMessage(response));
				}
			} catch (Exception e) {
				String message = "Bulk job getOrCreateSchemeIds failed for schemetype:" + schemeType;
				LOGGER.error(message, e);
				throw new RestClientException(message, e);
			}
			batchJob = null;
		}
	}
	LOGGER.debug("End creating scheme id {} with batch size {} ", schemeType, uuids.size());
	LOGGER.info("Time taken in seconds:" + (new Date().getTime() - startTime) /1000);
	return result;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:51,代码来源:IdServiceRestClientImpl.java

示例10: publishSctIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public boolean publishSctIds(List<Long> sctIds, Integer namespaceId, String comment) throws RestClientException {
	LOGGER.debug("Start publishing sctIds with batch size {} for namespace {}", sctIds.size(), namespaceId);
	if (sctIds == null || sctIds.isEmpty()) {
		return true;
	}
	boolean isPublished = false;
	long startTime = new Date().getTime();
	List<String> batchJob = null;
	int counter=0;
	for (Long sctId : sctIds) {
		if (batchJob == null) {
			batchJob = new ArrayList<>();
		}
		batchJob.add(String.valueOf(sctId));
		counter++;
		if (counter % batchSize == 0 || counter == sctIds.size()) {
			//processing batch
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(SCTIDS, batchJob.toArray());
				requestData.put(NAMESPACE, namespaceId.intValue());
				requestData.put(SOFTWARE, SRS);
				requestData.put(COMMENT, comment);
				JSONResource response = resty.put(urlHelper.getSctIdBulkPublishingUrl(token), requestData, APPLICATION_JSON);
				if ( HttpStatus.SC_OK == response.getHTTPStatus()) {
					String jobId =  response.get("id").toString();
					LOGGER.info("Bulk job id:" + jobId + " for publishing sctIds with batch size:" + batchJob.size());
					if (BULK_JOB_STATUS.COMPLETED_WITH_SUCCESS.getCode() == waitForCompleteStatus(jobId, getTimeOutInSeconds())) {
						isPublished = true;
					}
				} else {
					String statusMsg = "Received http status code from id service:" + response.getHTTPStatus();
					LOGGER.error(statusMsg);
					throw new RestClientException(statusMsg);
				}
			} catch (Exception e) {
				String message = "Bulk publishSctIds job failed.";
				LOGGER.error(message, e);
				throw new RestClientException(message, e);
			}
			batchJob = null;
		}
	}
	LOGGER.debug("End publishing sctIds with batch size {} for namespace {}", sctIds.size(), namespaceId);
	LOGGER.info("Time taken in seconds:" + (new Date().getTime() - startTime) /1000);
	return isPublished;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:49,代码来源:IdServiceRestClientImpl.java

示例11: publishSchemeIds

import us.monoid.json.JSONObject; //导入方法依赖的package包/类
@Override
public boolean publishSchemeIds(List<String> schemeIds, SchemeIdType schemeType, String comment) throws RestClientException {
	LOGGER.debug("Start publishing scheme ids with batch size {} for scheme type {}", schemeIds.size(), schemeType);
	if (schemeIds == null || schemeIds.isEmpty()) {
		return true;
	}
	boolean isPublished = false;
	long startTime = new Date().getTime();
	List<String> batchJob = null;
	int counter=0;
	for (String schemeId : schemeIds) {
		if (batchJob == null) {
			batchJob = new ArrayList<>();
		}
		batchJob.add(schemeId);
		counter++;
		if (counter % batchSize == 0 || counter == schemeIds.size()) {
			//processing batch
			try {
				JSONObject requestData = new JSONObject();
				requestData.put(SCHEME_IDS, batchJob.toArray());
				requestData.put(SOFTWARE, SRS);
				requestData.put(COMMENT, comment);
				JSONResource response = resty.put(urlHelper.getSchemeIdBulkPublishingUrl(schemeType,token), requestData, APPLICATION_JSON);
				if ( HttpStatus.SC_OK == response.getHTTPStatus()) {
					String jobId =  response.get("id").toString();
					LOGGER.info("Bulk job id:" + jobId + " for publishing scheme ids with batch size:" + batchJob.size());
					if (BULK_JOB_STATUS.COMPLETED_WITH_SUCCESS.getCode() == waitForCompleteStatus(jobId, getTimeOutInSeconds())){
						isPublished = true;
					}
				} else {
					String statusMsg = "Received http status code from id service:" + response.getHTTPStatus() + " message:" + response.get(MESSAGE);
					LOGGER.error(statusMsg);
					throw new RestClientException(statusMsg);
				}
			} catch (Exception e) {
				String message = "Bulk publish scheme ids job failed.";
				LOGGER.error(message, e);
				throw new RestClientException(message, e);
			}
			batchJob = null;
		}
	}
	LOGGER.debug("End publishing scheme ids with batch size {}", schemeIds.size());
	LOGGER.info("Time taken in seconds:" + (new Date().getTime() - startTime) /1000);
	return isPublished;
}
 
开发者ID:IHTSDO,项目名称:snomed-release-service,代码行数:48,代码来源:IdServiceRestClientImpl.java


注:本文中的us.monoid.json.JSONObject.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。