Java Code Examples for net.sf.json.JSONObject#getJSONObject()
The following examples show how to use
net.sf.json.JSONObject#getJSONObject() .
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: DescriptorImpl.java From qy-wechat-notification-plugin with Apache License 2.0 | 6 votes |
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { config.webhookUrl = json.getString("webhookUrl"); config.topicName = json.getString("topicName"); config.mentionedId = json.getString("mentionedId"); config.mentionedMobile = json.getString("mentionedMobile"); config.useProxy = json.get("useProxy")!=null; if(config.useProxy && json.get("useProxy") instanceof JSONObject){ JSONObject jsonObject = json.getJSONObject("useProxy"); config.proxyHost = jsonObject.getString("proxyHost"); config.proxyPort = jsonObject.getInt("proxyPort"); config.proxyUsername = jsonObject.getString("proxyUsername"); config.proxyPassword = Secret.fromString(jsonObject.getString("proxyPassword")); } save(); return super.configure(req, json); }
Example 2
Source File: MarathonRecorderTest.java From marathon-plugin with Apache License 2.0 | 6 votes |
/** * Test that Labels are properly put through replace macro. * * @throws Exception */ @Test public void testRecorderLabelsMacro() throws Exception { final List<MarathonLabel> labels = new ArrayList<>(2); final MarathonRecorder marathonRecorder = new MarathonRecorder(TestUtils.getHttpAddresss(httpServer)); labels.add(new MarathonLabel("foo", "bar-${BUILD_NUMBER}")); labels.add(new MarathonLabel("fizz", "buzz-$BUILD_NUMBER")); marathonRecorder.setLabels(labels); final FreeStyleProject project = basicSetup(marathonRecorder); final FreeStyleBuild build = basicRunWithSuccess(project); assertEquals("Only 1 request should be made", 1, httpServer.getRequestCount()); final JSONObject jsonRequest = TestUtils.jsonFromRequest(httpServer); final JSONObject jsonLabel = jsonRequest.getJSONObject("labels"); final String buildNumber = String.valueOf(build.getNumber()); assertEquals("'foo' label failed", "bar-" + buildNumber, jsonLabel.getString("foo")); assertEquals("'fizz1' label failed", "buzz-" + buildNumber, jsonLabel.getString("fizz")); }
Example 3
Source File: Slack.java From BotLibre with Eclipse Public License 1.0 | 6 votes |
public void processSlackEvent(String json) { JSONObject root = (JSONObject)JSONSerializer.toJSON(json); JSONObject event = root.getJSONObject("event"); String token = root.getString("token"); if(event.getString("type").equals("message")) { String user = event.getString("user"); String channel = event.getString("channel"); String text = event.getString("text"); String reply = this.processMessage(null, user, channel, text, token); if (reply == null || reply.isEmpty()) { return; } String data = "token=" + this.appToken; data += "&channel=" + channel; data += "&text=" + "@" + user + " " + reply; this.callSlackWebAPI("chat.postMessage", data); } }
Example 4
Source File: MarathonRecorderTest.java From marathon-plugin with Apache License 2.0 | 6 votes |
/** * Test that Vars are properly put through the replace macro. * * @throws Exception */ @Test public void testRecorderEnvMacro() throws Exception { final List<MarathonVars> envs = new ArrayList<>(2); final MarathonRecorder marathonRecorder = new MarathonRecorder(TestUtils.getHttpAddresss(httpServer)); envs.add(new MarathonVars("foo", "bar-${BUILD_NUMBER}")); envs.add(new MarathonVars("fizz", "buzz-$BUILD_NUMBER")); marathonRecorder.setEnv(envs); final FreeStyleProject project = basicSetup(marathonRecorder); final FreeStyleBuild build = basicRunWithSuccess(project); assertEquals("Only 1 request should be made", 1, httpServer.getRequestCount()); final JSONObject jsonRequest = TestUtils.jsonFromRequest(httpServer); final JSONObject jsonEnv = jsonRequest.getJSONObject("env"); final String buildNumber = String.valueOf(build.getNumber()); assertEquals("'foo' label failed", "bar-" + buildNumber, jsonEnv.getString("foo")); assertEquals("'fizz1' label failed", "buzz-" + buildNumber, jsonEnv.getString("fizz")); }
Example 5
Source File: NotifierSettings.java From build-notifications-plugin with MIT License | 6 votes |
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { JSONObject config = json.getJSONObject("base"); brokenMSG = config.getString("brokenMSG"); stillBrokenMSG = config.getString("stillBrokenMSG"); fixedMSG = config.getString("fixedMSG"); successMSG = config.getString("successMSG"); abortedRES = config.getString("abortedRES"); failureRES = config.getString("failureRES"); notBuildRES = config.getString("notBuildRES"); successRES = config.getString("successRES"); unstableRES = config.getString("unstableRES"); save(); return true; }
Example 6
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 7
Source File: BlazeMeterHttpUtils.java From jmeter-bzm-plugins with Apache License 2.0 | 6 votes |
@Override protected String extractErrorMessage(String response) { if (response != null && !response.isEmpty()) { try { JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig()); if (jsonResponse instanceof JSONObject) { JSONObject object = (JSONObject) jsonResponse; JSONObject errorObj = object.getJSONObject("error"); if (errorObj.containsKey("message")) { return errorObj.getString("message"); } } } catch (JSONException ex) { log.debug("Cannot parse JSON error response: " + response); } } return response; }
Example 8
Source File: JsonSecurityRule.java From ipst with Mozilla Public License 2.0 | 5 votes |
public static SecurityRule fromJSON(JSONObject json) { return new JsonSecurityRule( new RuleId(RuleAttributeSet.valueOf(json.getString("algoType")), new SecurityIndexId(json.getString("contingencyId"), SecurityIndexType.fromLabel(json.getString("indexType")))), json.getString("workflowId"), (float) json.getDouble("quality"), json.getInt("treeSize"), (float) json.getDouble("criticality"), json.getJSONObject("tree") ); }
Example 9
Source File: GithubWebhookBuildTriggerPluginBuilder.java From jenkins-github-webhook-build-trigger-plugin with MIT License | 5 votes |
@Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { json = json.getJSONObject("config"); webhookSecret = json.getString("webhookSecret"); save(); return true; }
Example 10
Source File: ChangeBasedEvent.java From gerrit-events with MIT License | 5 votes |
/** * Takes a JSON object and fills its internal data-structure. * * @param json the JSON Object. */ public void fromJson(JSONObject json) { super.fromJson(json); if (json.containsKey(CHANGE)) { change = new Change(json.getJSONObject(CHANGE)); } if (json.containsKey(PATCH_SET)) { patchSet = new PatchSet(json.getJSONObject(PATCH_SET)); } else if (json.containsKey(PATCHSET)) { patchSet = new PatchSet(json.getJSONObject(PATCHSET)); } }
Example 11
Source File: GeoServerGetCoverageStoreCommand.java From geowave with Apache License 2.0 | 5 votes |
@Override public String computeResults(final OperationParams params) throws Exception { if (parameters.size() != 1) { throw new ParameterException("Requires argument: <coverage store name>"); } if ((workspace == null) || workspace.isEmpty()) { workspace = geoserverClient.getConfig().getWorkspace(); } csName = parameters.get(0); final Response getCvgStoreResponse = geoserverClient.getCoverageStore(workspace, csName, false); if (getCvgStoreResponse.getStatus() == Status.OK.getStatusCode()) { final JSONObject jsonResponse = JSONObject.fromObject(getCvgStoreResponse.getEntity()); final JSONObject cvgstore = jsonResponse.getJSONObject("coverageStore"); return "\nGeoServer coverage store info for '" + csName + "': " + cvgstore.toString(2); } final String errorMessage = "Error getting GeoServer coverage store info for '" + csName + "': " + getCvgStoreResponse.readEntity(String.class) + "\nGeoServer Response Code = " + getCvgStoreResponse.getStatus(); return handleError(getCvgStoreResponse, errorMessage); }
Example 12
Source File: NERTool.java From Criteria2Query with Apache License 2.0 | 5 votes |
public String nerByDicLookUp(String str){ System.out.println("======nerByDicLookUp====="); String res=str; if(str.trim().toLowerCase().equals("male")||str.trim().toLowerCase().equals("female")||str.trim().toLowerCase().equals("women")||str.trim().toLowerCase().equals("men")||str.trim().toLowerCase().equals("man")||str.trim().toLowerCase().equals("woman")){ res="<"+"Demographic"+">"+str+"</"+"Demographic"+">"; return res; } JSONObject jo=new JSONObject(); jo.accumulate("term", str); String result=HttpUtil.doPost(diclookup, jo.toString()); System.out.println("result="+result); JSONObject bestconcept=JSONObject.fromObject(result); try{ System.out.println("matchScore="+bestconcept.getDouble("matchScore")); if(bestconcept.getDouble("matchScore")>0.75) { JSONObject concept_jo=bestconcept.getJSONObject("concept"); String domain=concept_jo.getString("domainId"); res="<"+domain+">"+str+"</"+domain+">"; } }catch(Exception ex){ } System.out.println("dic_result="+res); return res; }
Example 13
Source File: RequiredResourcesProperty.java From lockable-resources-plugin with MIT License | 5 votes |
@Override public RequiredResourcesProperty newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (formData.containsKey("required-lockable-resources")) { return (RequiredResourcesProperty) super.newInstance(req, formData.getJSONObject("required-lockable-resources")); } return null; }
Example 14
Source File: JwGroupManangerAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 根据分组ID获取分组信息 * @return */ public static GroupDetailInfo getByGroupId(String newAccessToken, Integer group_id) { if (newAccessToken != null) { String requestUrl = getid_group_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"group_id\": "+group_id+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); // 正常返回 GroupDetailInfo groupDetailInfo = null; JSONObject info = result.getJSONObject("group_detail"); groupDetailInfo = (GroupDetailInfo)JSONObject.toBean(info, GroupDetailInfo.class); return groupDetailInfo; } return null; }
Example 15
Source File: JwDeliveryMoneyAPI.java From jeewx-api with Apache License 2.0 | 5 votes |
/** * 获取指定ID的邮费模板 * @param template_id * @return */ public static DeliveryMoney getByIdExpress(String newAccessToken, Integer template_id) { if (newAccessToken != null) { String requestUrl = get_postage_url.replace("ACCESS_TOKEN", newAccessToken); String json = "{\"template_id\": "+template_id+"}"; JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", json); // 正常返回 DeliveryMoney postage = null; JSONObject info = result.getJSONObject("template_info"); postage = (DeliveryMoney)JSONHelper.toBean(info, DeliveryMoney.class); return postage; } return null; }
Example 16
Source File: CommentAdded.java From gerrit-events with MIT License | 5 votes |
@Override public void fromJson(JSONObject json) { super.fromJson(json); comment = getString(json, COMMENT); if (json.containsKey(AUTHOR)) { account = new Account(json.getJSONObject(AUTHOR)); } if (json.containsKey(APPROVALS)) { JSONArray eventApprovals = json.getJSONArray(APPROVALS); for (int i = 0; i < eventApprovals.size(); i++) { approvals.add(new Approval(eventApprovals.getJSONObject(i))); } } }
Example 17
Source File: Test.java From jmeter-bzm-plugins with Apache License 2.0 | 4 votes |
private JSONObject sendStartTest(String uri, int expectedRC) throws IOException { JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, ""), expectedRC); return response.getJSONObject("result"); }
Example 18
Source File: PRReviewGHEventSubscriber.java From github-pr-comment-build-plugin with MIT License | 4 votes |
/** * Handles updates of pull requests. * @param event only PULL_REQUEST_REVIEW events * @param payload payload of gh-event. Never blank */ @Override protected void onEvent(GHEvent event, String payload) { JSONObject json = JSONObject.fromObject(payload); JSONObject pullRequest = json.getJSONObject("pull_request"); final String pullRequestUrl = pullRequest.getString("html_url"); Integer pullRequestId = pullRequest.getInt("number"); // Set some values used below final Pattern pullRequestJobNamePattern = Pattern.compile("^PR-" + pullRequestId + "\\b.*$", Pattern.CASE_INSENSITIVE); // Make sure the repository URL is valid String repoUrl = json.getJSONObject("repository").getString("html_url"); Matcher matcher = REPOSITORY_NAME_PATTERN.matcher(repoUrl); if (!matcher.matches()) { LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl); return; } final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl); if (changedRepository == null) { LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl); return; } LOGGER.log(Level.FINE, "Received review on PR {1} for {2}", new Object[] { pullRequestId, repoUrl }); ACL.impersonate(ACL.SYSTEM, new Runnable() { @Override public void run() { boolean jobFound = false; for (final SCMSourceOwner owner : SCMSourceOwners.all()) { for (SCMSource source : owner.getSCMSources()) { if (!(source instanceof GitHubSCMSource)) { continue; } GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source; if (gitHubSCMSource.getRepoOwner().equalsIgnoreCase(changedRepository.getUserName()) && gitHubSCMSource.getRepository().equalsIgnoreCase(changedRepository.getRepositoryName())) { for (Job<?, ?> job : owner.getAllJobs()) { if (pullRequestJobNamePattern.matcher(job.getName()).matches()) { if (!(job.getParent() instanceof MultiBranchProject)) { continue; } boolean propFound = false; for (BranchProperty prop : ((MultiBranchProject) job.getParent()).getProjectFactory(). getBranch(job).getProperties()) { if (!(prop instanceof TriggerPRReviewBranchProperty)) { continue; } propFound = true; ParameterizedJobMixIn.scheduleBuild2(job, 0, new CauseAction(new GitHubPullRequestReviewCause(pullRequestUrl))); break; } if (!propFound) { LOGGER.log(Level.FINE, "Job {0} for {1}:{2}/{3} does not have a trigger PR review branch property", new Object[] { job.getFullName(), changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName() } ); } jobFound = true; } } } } } if (!jobFound) { LOGGER.log(Level.FINE, "PR review on {0}:{1}/{2} did not match any job", new Object[] { changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName() } ); } } }); }
Example 19
Source File: MainController.java From ApiManager with GNU Affero General Public License v3.0 | 4 votes |
/** * 获取系统最新信息 * * @return * @throws Exception */ @RequestMapping("/admin/property.do") @AuthPassport(authority = C_AUTH_SETTING) @ResponseBody public JsonResult property() throws Exception { Map<String, Object> returnMap = new HashMap<>(); Map<String, Object> properties = new HashMap<>(); properties.put("domain", Tools.getUrlPath()); properties.put("openRegister", Config.openRegister); properties.put("luceneSearchNeedLogin", Config.luceneSearchNeedLogin); properties.put("openRegister", Config.openRegister); properties.put("canRepeatUrl", Config.canRepeatUrl); properties.put("cacheTime", Config.cacheTime); properties.put("loginInforTime", Config.loginInforTime); properties.put("fileSize", Config.fileSize); properties.put("fileType", Config.fileType); properties.put("imageType", Config.imageType); properties.put("mail", Config.mail); properties.put("clientID", Config.clientID); returnMap.put("properties", properties); // 从crapApi获取版本信息 try { String crapApiInfo = HttpPostGet.get("http://api.crap.cn/mock/trueExam.do?id=c107b205-c365-4050-8fa9-dbb7a38b3d11&cache=true", null, null); JSONObject json = JSONObject.fromObject(crapApiInfo); if (json.getInt("success") == 1) { json = json.getJSONObject("data"); returnMap.put("crapApiInfo", Tools.getStrMap("latestVersion", json.getString("latestVersion"), "latestVersion", json.getString("latestVersion"), "addFunction", json.getString("addFunction"), "updateUrl", json.getString("updateUrl"), "noticeUrl", json.getString("noticeUrl"), "notice", json.getString("notice"))); } } catch (Exception e) { e.printStackTrace(); } return new JsonResult(1, returnMap); }
Example 20
Source File: Common.java From pdf-extract with GNU General Public License v3.0 | 4 votes |
public JSONObject getJSONObject(JSONObject json, String name) { if (json != null && json.has(name)) return json.getJSONObject(name); else return null; }