Java Code Examples for net.sf.json.JSONObject#has()
The following examples show how to use
net.sf.json.JSONObject#has() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取素材总数 * * @param accesstoken * @param accesstoken * * @return WxCountResponse 素材数目返回结果 * @throws WexinReqException */ public static WxCountResponse getMediaCount(String accesstoken) throws WexinReqException { WxCountResponse wxCountResponse = null; if (accesstoken != null) { String requestUrl = material_get_materialcount_url.replace("ACCESS_TOKEN", accesstoken); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST",null); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")) { logger.error("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { wxCountResponse = new WxCountResponse(); wxCountResponse.setImage_count(result.getString("image_count")); wxCountResponse.setNews_count(result.getString("news_count")); wxCountResponse.setVideo_count(result.getString("video_count")); wxCountResponse.setVoice_count(result.getString("voice_count")); } } return wxCountResponse; }
Example 2
Source File: AWSCodePipelinePublisher.java From aws-codepipeline-plugin-for-jenkins with Apache License 2.0 | 6 votes |
@DataBoundConstructor public AWSCodePipelinePublisher(final JSONArray outputLocations) { buildOutputs = new ArrayList<>(); outputArtifacts = new ArrayList<>(); if (outputLocations != null) { for (final Object outputLocation : outputLocations) { final JSONObject jsonObject = (JSONObject) outputLocation; if (jsonObject.has(JELLY_KEY_LOCATION) && jsonObject.has(JELLY_KEY_ARTIFACT_NAME)) { final String locationValue = jsonObject.getString(JELLY_KEY_LOCATION); final String artifactName = jsonObject.getString(JELLY_KEY_ARTIFACT_NAME); this.outputArtifacts.add(new OutputArtifact( Validation.sanitize(locationValue.trim()), Validation.sanitize(artifactName.trim()) )); } } } awsClientFactory = new AWSClientFactory(); Validation.numberOfOutPutsIsValid(outputArtifacts); }
Example 3
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 6 votes |
/** * 获取永久素材 * * @param accesstoken * @param wxArticles * 图文集合,数量不大于10 * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ public static List<WxNewsArticle> getArticlesByMaterialNews(String accesstoken,String mediaId) throws WexinReqException { List<WxNewsArticle> wxArticleList = null; if (accesstoken != null) { String requestUrl = material_get_material_url.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = new JSONObject(); obj.put("media_id", mediaId); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); if (result.has("errcode")) { logger.error("获取永久素材 失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); } else { logger.info("====获取永久素材成功====result:"+result.toString()); JSONArray newsItemJsonArr = result.getJSONArray("news_item"); wxArticleList = JSONArray.toList(newsItemJsonArr, WxNewsArticle.class); } } return wxArticleList; }
Example 4
Source File: TemplateImplementationProperty.java From ez-templates with Apache License 2.0 | 6 votes |
@Override public JobProperty<?> newInstance(StaplerRequest request, JSONObject formData) throws FormException { if (formData.size() > 0 && formData.has("useTemplate")) { JSONObject useTemplate = formData.getJSONObject("useTemplate"); String templateJobName = useTemplate.getString("templateJobName"); boolean syncMatrixAxis = useTemplate.getBoolean("syncMatrixAxis"); boolean syncDescription = useTemplate.getBoolean("syncDescription"); boolean syncBuildTriggers = useTemplate.getBoolean("syncBuildTriggers"); boolean syncDisabled = useTemplate.getBoolean("syncDisabled"); boolean syncSecurity = useTemplate.getBoolean("syncSecurity"); boolean syncScm = useTemplate.getBoolean("syncScm"); boolean syncOwnership = useTemplate.getBoolean("syncOwnership"); boolean syncAssignedLabel = useTemplate.getBoolean("syncAssignedLabel"); return new TemplateImplementationProperty(templateJobName, syncMatrixAxis, syncDescription, syncBuildTriggers, syncDisabled, syncSecurity, syncScm, syncOwnership, syncAssignedLabel); } return null; }
Example 5
Source File: PackerPublisher.java From packer-plugin with MIT License | 5 votes |
@Override public PackerPublisher newInstance(StaplerRequest req, JSONObject formData) throws hudson.model.Descriptor.FormException { PackerPublisher packer = (PackerPublisher) req.bindJSON(clazz, formData); if (formData.has(TEMPLATE_MODE)) { JSONObject opt = formData.getJSONObject(TEMPLATE_MODE); packer.setTemplateMode(opt.getString("value")); packer.setJsonTemplate(opt.optString("jsonTemplate")); packer.setJsonTemplateText(opt.optString("jsonTemplateText")); } return packer; }
Example 6
Source File: DefaultPointer.java From logsniffer with GNU Lesser General Public License v3.0 | 5 votes |
public static DefaultPointer fromJSON(final String data) { JSONObject json = JSONObject.fromObject(data); if (json.has("o") && json.has("s")) { return new DefaultPointer(json.getLong("o"), json.getLong("s")); } else { return null; } }
Example 7
Source File: ContentReviewServiceTurnitinOC.java From sakai with Educational Community License v2.0 | 5 votes |
public ArrayList<Webhook> getWebhooks() throws Exception { ArrayList<Webhook> webhooks = new ArrayList<>(); HashMap<String, Object> response = makeHttpCall("GET", getNormalizedServiceUrl() + "webhooks", BASE_HEADERS, null, null); // Get response: int responseCode = !response.containsKey(RESPONSE_CODE) ? 0 : (int) response.get(RESPONSE_CODE); String responseMessage = !response.containsKey(RESPONSE_MESSAGE) ? "" : (String) response.get(RESPONSE_MESSAGE); String responseBody = !response.containsKey(RESPONSE_BODY) ? "" : (String) response.get(RESPONSE_BODY); if(StringUtils.isNotEmpty(responseBody) && responseCode >= 200 && responseCode < 300 && !"[]".equals(responseBody)) { // Loop through response via JSON, convert objects to Webhooks JSONArray webhookList = JSONArray.fromObject(responseBody); for (int i=0; i < webhookList.size(); i++) { JSONObject webhookJSON = webhookList.getJSONObject(i); if (webhookJSON.has("id") && webhookJSON.has("url")) { webhooks.add(new Webhook(webhookJSON.getString("id"), webhookJSON.getString("url"))); } } }else { log.info("getWebhooks: " + responseMessage); } return webhooks; }
Example 8
Source File: JwThirdAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 3、使用授权码换取公众号的授权信息 * @param appid * @param appscret * @return kY9Y9rfdcr8AEtYZ9gPaRUjIAuJBvXO5ZOnbv2PYFxox__uSUQcqOnaGYN1xc4N1rI7NDCaPm_0ysFYjRVnPwCJHE7v7uF_l1hI6qi6QBsA * @throws WexinReqException */ public static JSONObject getApiQueryAuthInfo(String component_appid,String authorization_code,String component_access_token) throws WexinReqException{ String requestUrl = api_query_auth_url.replace("xxxx", component_access_token); Map<String,String> mp = new HashMap<String,String>(); mp.put("component_appid", component_appid); mp.put("authorization_code", authorization_code); JSONObject obj = JSONObject.fromObject(mp); System.out.println("-------------------3、使用授权码换取公众号的授权信息---requestUrl------------------------"+requestUrl); JSONObject result = WxstoreUtils.httpRequest(requestUrl,"POST", obj.toString()); if (result.has("errcode")) { logger.error("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("获取第三方平台access_token!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } return result; }
Example 9
Source File: Facebook.java From BotLibre with Eclipse Public License 1.0 | 5 votes |
/** * Check the command JSON for a Facebook attachment object to append to a Facebook Messeneger message. */ public String createJSONAttachment(String command, String id, String text) { JSONObject root = (JSONObject)JSONSerializer.toJSON(command); if (!root.has("type") || !root.getString("type").equals("facebook")) { return ""; } JSONObject json = root.getJSONObject("attachment"); if (json == null) { return ""; } return json.toString(); }
Example 10
Source File: WXApi.java From WeChatEnterprise with Apache License 2.0 | 5 votes |
/** * 获取accessToken-阻塞式 * * @return accessToken */ public static String getAccessToken4Blocking() { // url final String url = String.format(WXApi.WX_GET_ACCESSTOKEN, CorpId, Secret); // request JSONObject object = WXHttpUtil.HttpRequest4Blocking(url, GET); // parse if (object != null && object.has("access_token")) // parse access_token return object.getString("access_token"); return null; }
Example 11
Source File: Common.java From pdf-extract with GNU General Public License v3.0 | 5 votes |
public JSONArray getJSONArray(JSONObject json, String parentname, String name) { if (json != null && json.has(parentname)) { JSONObject jobj = json.getJSONObject(parentname); if (jobj != null && jobj.has(name)) { return jobj.getJSONArray(name); } else { return null; } } else return null; }
Example 12
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 修改永久素材 * * @param accesstoken * @param wxUpdateArticle * @throws WexinReqException */ public static void updateArticlesByMaterialNews(String accesstoken,WxUpdateArticle wxUpdateArticle) throws WexinReqException { if (accesstoken != null) { String requestUrl = material_update_news_url.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = JSONObject.fromObject(wxUpdateArticle); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); if (result.has("errcode")&&result.getInt("errcode")!=0) { logger.error("修改永久素材失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException(result.getString("errcode")); }else{ logger.info("=====修改永久素材成功====="); } } }
Example 13
Source File: SparkJobServerClientImpl.java From SparkJobServerClient with Apache License 2.0 | 4 votes |
/** * Generates an instance of <code>SparkJobResult</code> according to the given contents. * * @param resContent the content of a http response * @return the corresponding <code>SparkJobResult</code> instance * @throws Exception error occurs when parsing the http response content */ private SparkJobResult parseResult(String resContent) throws Exception { JSONObject jsonObj = JSONObject.fromObject(resContent); SparkJobResult jobResult = new SparkJobResult(resContent); boolean completed = false; if(jsonObj.has(SparkJobBaseInfo.INFO_KEY_STATUS)) { jobResult.setStatus(jsonObj.getString(SparkJobBaseInfo.INFO_KEY_STATUS)); if (SparkJobBaseInfo.COMPLETED.contains(jobResult.getStatus())) { completed = true; } } else { completed = true; } if (completed) { //Job finished with results jobResult.setResult(jsonObj.get(SparkJobBaseInfo.INFO_KEY_RESULT).toString()); } else if (containsAsynjobStatus(jsonObj)) { //asynchronously started job only with status information setAsynjobStatus(jobResult, jsonObj); } else if (containsErrorInfo(jsonObj)) { String errorKey = null; if (jsonObj.containsKey(SparkJobBaseInfo.INFO_STATUS_ERROR)) { errorKey = SparkJobBaseInfo.INFO_STATUS_ERROR; } else if (jsonObj.containsKey(SparkJobBaseInfo.INFO_KEY_RESULT)) { errorKey = SparkJobBaseInfo.INFO_KEY_RESULT; } //Job failed with error details setErrorDetails(errorKey, jsonObj, jobResult); } else { //Other unknown kind of value needs application to parse itself Iterator<?> keyIter = jsonObj.keys(); while (keyIter.hasNext()) { String key = (String)keyIter.next(); if (SparkJobInfo.INFO_KEY_STATUS.equals(key)) { continue; } jobResult.putExtendAttribute(key, jsonObj.get(key)); } } return jobResult; }
Example 14
Source File: JwSendMessageAPI.java From jeewx-api with Apache License 2.0 | 4 votes |
/** * 上传图文消息素材 * * @param accesstoken * @param wxArticles * 图文集合,数量不大于10 * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ public static WxArticlesResponse uploadArticles(String accesstoken, List<WxArticle> wxArticles) throws WexinReqException { WxArticlesResponse wxArticlesResponse = null; if (wxArticles.size() == 0) { logger.error("没有上传的图文消息"); } else if (wxArticles.size() > 10) { logger.error("图文消息最多为10个图文"); } else { if (accesstoken != null) { String requestUrl = upload_article_url.replace("ACCESS_TOKEN", accesstoken); for (WxArticle article : wxArticles) { if (article.getFileName() != null && article.getFileName().length() > 0) { try { String mediaId = getFileMediaId(accesstoken, article); article.setThumb_media_id(mediaId); } catch (Exception e) { throw new WexinReqException(e); } } } WxArticlesRequest wxArticlesRequest = new WxArticlesRequest(); wxArticlesRequest.setArticles(wxArticles); JSONObject obj = JSONObject.fromObject(wxArticlesRequest); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")) { logger.error("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { wxArticlesResponse = new WxArticlesResponse(); wxArticlesResponse.setMedia_id(result.getString("media_id")); wxArticlesResponse.setType(result.getString("type")); wxArticlesResponse.setCreated_at(new Date(result.getLong("created_at") * 1000)); } } } return wxArticlesResponse; }
Example 15
Source File: ValidationServlet.java From WeChatEnterprise with Apache License 2.0 | 4 votes |
public void doGet(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8"); // type req.setAttribute("type", "validation"); // result String result = "1"; final String code = req.getParameter("code"); if (code != null) { System.out.println("validation start , code = " + code); // get access_token String access_token = WXApi.getAccessToken4Blocking(); System.out.println("validation start , access_token = " + access_token); if (access_token != null) { // get userid JSONObject userid_object = WXOAuth2.getCodeToUserId4Blocking( access_token, code); String userid = null; if (userid_object != null) { if (userid_object.has("UserId")) { userid = userid_object.getString("UserId"); } else { System.out .println("validation userid not exists , userid_object = " + userid_object.toString()); } } if (userid != null) { System.out.println("validation start , userid = " + userid); // get validation result JSONObject object = getValidationResult(access_token, userid); if(object!=null){ int errcode = object.getInt("errcode"); // validation success if (errcode == 0) { result = "0"; } // validation failed else{ // errcode req.setAttribute("errcode", errcode); } } } } } else { result = "1"; System.out.println("oauth2 failed , code = " + (code == null ? "null" : code)); } System.out.println(" "); System.out.println("*******************分割线************************"); System.out.println(" "); // result req.setAttribute("result", result); // 跳转到index.jsp req.getRequestDispatcher("index.jsp").forward(req, resp); }
Example 16
Source File: Common.java From pdf-extract with GNU General Public License v3.0 | 4 votes |
public JSONArray getJSONArray(JSONObject json, String name) { if (json != null && json.has(name)) return json.getJSONArray(name); else return null; }
Example 17
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 4 votes |
/** * 上传新增永久图文素材 (经测试,该方法不可用) * * @param accesstoken * @param wxArticles * 图文集合,数量不大于10 * @return WxArticlesResponse 上传图文消息素材返回结果 * @throws WexinReqException */ public static WxArticlesResponse uploadArticlesByMaterial(String accesstoken, List<WxArticle> wxArticles) throws WexinReqException { WxArticlesResponse wxArticlesResponse = null; if (wxArticles.size() == 0) { logger.error("没有上传的图文消息"); } else if (wxArticles.size() > 10) { logger.error("图文消息最多为10个图文"); } else { if (accesstoken != null) { String requestUrl = material_add_news_url.replace("ACCESS_TOKEN", accesstoken); for (WxArticle article : wxArticles) { if (article.getFileName() != null && article.getFileName().length() > 0) { try { String mediaId = JwSendMessageAPI.getFileMediaId(accesstoken, article); article.setThumb_media_id(mediaId); } catch (Exception e) { throw new WexinReqException(e); } } } WxArticlesRequest wxArticlesRequest = new WxArticlesRequest(); wxArticlesRequest.setArticles(wxArticles); JSONObject obj = JSONObject.fromObject(wxArticlesRequest); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); //System.out.println("微信返回的结果:" + result.toString()); if (result.has("errcode")) { logger.error("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); throw new WexinReqException("上传图文消息失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")); } else { wxArticlesResponse = new WxArticlesResponse(); wxArticlesResponse.setMedia_id(result.getString("media_id")); wxArticlesResponse.setType(result.getString("type")); wxArticlesResponse.setCreated_at(new Date(result.getLong("created_at") * 1000)); } } } return wxArticlesResponse; }
Example 18
Source File: JwMediaAPI.java From jeewx-api with Apache License 2.0 | 4 votes |
/** * 获取素材列表 * * @param accesstoken,type,offset,count * @param WxNews * @throws WexinReqException */ public static WxNews queryArticlesByMaterialNews(String accesstoken,String type,int offset,int count) throws WexinReqException { WxNews news = new WxNews(); if (accesstoken != null) { String requestUrl = material_batchget_material_url.replace("ACCESS_TOKEN", accesstoken); JSONObject obj = new JSONObject(); obj.put("type", type); obj.put("offset", offset); obj.put("count", count); JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", obj.toString()); if (result.has("errcode")&&result.getInt("errcode")!=0) { logger.error("=====获取素材列表失败!errcode=" + result.getString("errcode") + ",errmsg = " + result.getString("errmsg")+"====="); throw new WexinReqException(result.getString("errcode")); } else{ logger.info("=====获取素材列表成功!result:"+result.toString()+"====="); JSONArray jsonArray = result.getJSONArray("item"); Object[] itemArr = jsonArray.toArray(); List<WxItem> wxItems = new ArrayList<WxItem>(); for (int i = 0; i < itemArr.length; i++) { WxItem wxItem = new WxItem(); Object itemObj = itemArr[i]; JSONObject itemJson = JSONObject.fromObject(itemObj); String mediaId = itemJson.getString("media_id"); Object newsItemObj = itemJson.get("content"); JSONObject newsItemJson = JSONObject.fromObject(newsItemObj); JSONArray newsItemJsonArr = newsItemJson.getJSONArray("news_item"); List<WxNewsArticle> wxArticleList = JSONArray.toList(newsItemJsonArr, WxNewsArticle.class); wxItem.setContents(wxArticleList); wxItem.setMedia_id(mediaId); if(itemJson.containsKey("name")){ wxItem.setName("name"); } wxItem.setUpdate_time(itemJson.getString("update_time")); wxItems.add(wxItem); } news.setItems(wxItems); } } return news; }
Example 19
Source File: Common.java From pdf-extract with GNU General Public License v3.0 | 4 votes |
public String getJSONValue(JSONObject json, String name) { if (json != null && json.has(name)) return json.getString(name); else return null; }
Example 20
Source File: ContentReviewServiceTurnitinOC.java From sakai with Educational Community License v2.0 | 4 votes |
public String setupWebhook(String webhookUrl) throws Exception { String id = null; Map<String, Object> data = new HashMap<String, Object>(); List<String> types = new ArrayList<>(); types.add(SIMILARITY_UPDATED_EVENT_TYPE); types.add(SIMILARITY_COMPLETE_EVENT_TYPE); types.add(SUBMISSION_COMPLETE_EVENT_TYPE); data.put("signing_secret", base64Encode(apiKey)); data.put("url", webhookUrl); data.put("description", "Sakai " + sakaiVersion); data.put("allow_insecure", false); data.put("event_types", types); HashMap<String, Object> response = makeHttpCall("POST", getNormalizedServiceUrl() + "webhooks", WEBHOOK_SETUP_HEADERS, data, null); // Get response: int responseCode = !response.containsKey(RESPONSE_CODE) ? 0 : (int) response.get(RESPONSE_CODE); String responseMessage = !response.containsKey(RESPONSE_MESSAGE) ? "" : (String) response.get(RESPONSE_MESSAGE); String responseBody = !response.containsKey(RESPONSE_BODY) ? "" : (String) response.get(RESPONSE_BODY); String error = null; if ((responseCode >= 200) && (responseCode < 300) && (responseBody != null)) { // create JSONObject from responseBody JSONObject responseJSON = JSONObject.fromObject(responseBody); if (responseJSON.has("id")) { id = responseJSON.getString("id"); } else { error = "returned with no ID: " + responseJSON; } }else { error = responseMessage; } if(StringUtils.isEmpty(id)) { log.info("Error setting up webhook: " + error); } return id; }