net.sf.json.JSONNull Java Examples

The following examples show how to use net.sf.json.JSONNull. 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: Engine.java    From acunetix-plugin with MIT License 6 votes vote down vote up
public String startScan(String scanningProfileId, String targetId, Boolean waitFinish) throws IOException {
    JSONObject jso = new JSONObject();
    jso.put("target_id", targetId);
    jso.put("profile_id", scanningProfileId);
    jso.put("user_authorized_to_scan", "yes");
    JSONObject jsoChild = new JSONObject();
    jsoChild.put("disable", false);
    jsoChild.put("start_date", JSONNull.getInstance());
    jsoChild.put("time_sensitive", false);
    jso.put("schedule", jsoChild);
    String scanId = doPostLoc(apiUrl + "/scans", jso.toString()).respStr;
    if (waitFinish) {
        while (!getScanStatus(scanId).equals("completed")) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    return scanId;
}
 
Example #2
Source File: HttpPanelJsonView.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@Override
public void dataChanged(HttpPanelViewModelEvent e) {
    String body = ((AbstractStringHttpPanelViewModel) e.getSource()).getData();
    try {
        JSON json = toJson(body);
        if (json instanceof JSONNull) {
            // avoid the string "null" for empty bodies
            httpPanelJsonArea.setText("");
        } else {
            httpPanelJsonArea.setText(json.toString(2));
        }
    } catch (JSONException ex) {
        httpPanelJsonArea.setText(body);
    }
    if (!isEditable()) {
        httpPanelJsonArea.discardAllEdits();
    }
    // TODO: scrolling to top when new message is opened
    // httpPanelJsonArea.setCaretPosition(0);
}
 
Example #3
Source File: PostCommentTask.java    From phabricator-jenkins-plugin with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void execute() {
    JSONObject postDifferentialCommentResult = postDifferentialComment(comment, SILENT,
            commentAction);
    if (postDifferentialCommentResult == null ||
            !(postDifferentialCommentResult.get("error_info") instanceof JSONNull)) {
        if (postDifferentialCommentResult != null) {
            info(String.format("Got error %s with action %s",
                    postDifferentialCommentResult.get("error_info"), commentAction));
        }

        info("Re-trying with action 'none'");
        postDifferentialComment(comment, SILENT, DEFAULT_COMMENT_ACTION);
    }
}
 
Example #4
Source File: HttpUtils.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Execute Http request and response code
 * @param request - HTTP Request
 * @param expectedCode - expected response code
 * @return - response in JSONObject
 */
public JSON query(HttpRequestBase request, int expectedCode) throws IOException {
    log.info("Requesting: " + request);
    addRequiredHeader(request);

    HttpParams requestParams = request.getParams();
    requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT * 1000);
    requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT * 1000);

    synchronized (httpClient) {
        String response;
        try {
            HttpResponse result = httpClient.execute(request);

            int statusCode = result.getStatusLine().getStatusCode();

            response = getResponseEntity(result);

            if (statusCode != expectedCode) {

                notifier.notifyAbout("Response with code " + statusCode + ": " + extractErrorMessage(response));
                throw new IOException("API responded with wrong status code: " + statusCode);
            } else {
                log.debug("Response: " + response);
            }
        } finally {
            request.abort();
        }

        if (response == null || response.isEmpty()) {
            return JSONNull.getInstance();
        } else {
            return JSONSerializer.toJSON(response, new JsonConfig());
        }
    }
}
 
Example #5
Source File: Engine.java    From acunetix-plugin with MIT License 5 votes vote down vote up
public String createIncScan(String scanningProfileId, String targetId) throws IOException {
    JSONObject jso = new JSONObject();
    jso.put("target_id", targetId);
    jso.put("profile_id", scanningProfileId);
    jso.put("user_authorized_to_scan", "yes");
    jso.put("incremental", true);
    JSONObject jsoChild = new JSONObject();
    jsoChild.put("disable", false);
    jsoChild.put("start_date", JSONNull.getInstance());
    jsoChild.put("time_sensitive", false);
    jsoChild.put("triggerable", true);
    jso.put("schedule", jsoChild);
    String scanId = doPostLoc(apiUrl + "/scans", jso.toString()).respStr;
    return scanId;
}
 
Example #6
Source File: ReadJSONStepExecution.java    From pipeline-utility-steps-plugin with MIT License 5 votes vote down vote up
private boolean isNull(Object value) {
    if (value instanceof JSONNull) {
        return true;
    }
    if (value instanceof JSONObject) {
        try {
            ((Map) value).get((Object) "somekey");
        } catch (JSONException e) {
            // JSONException is returned by verifyIsNull method in JSONObject when accessing one of its properties
            return true;
        }
    }
    return false;
}
 
Example #7
Source File: HttpPanelJsonView.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private static JSON toJson(String s) throws JSONException {
    JSON object;
    s = s.trim();

    if (s.isEmpty()) {
        object = JSONNull.getInstance();
    } else if (s.startsWith("{")) {
        object = JSONObject.fromObject(s);
    } else if (s.startsWith("[")) {
        object = JSONArray.fromObject(s);
    } else {
        throw new JSONException("Expected a '{', '[', or an empty message");
    }
    return object;
}
 
Example #8
Source File: SendHarbormasterResultTask.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
/**
 * Try to send a message to harbormaster
 *
 * @param unitResults the unit testing results to send
 * @param coverage the coverage data to send
 * @return false if an error was encountered
 */
private boolean sendMessage(UnitResults unitResults, Map<String, String> coverage, LintResults lintResults) throws
        IOException, ConduitAPIException {
    JSONObject result = diffClient.sendHarbormasterMessage(phid, harbormasterSuccess, unitResults, coverage,
            lintResults);

    if (result.containsKey("error_info") && !(result.get("error_info") instanceof JSONNull)) {
        info(String.format("Error from Harbormaster: %s", result.getString("error_info")));
        failTask();
        return false;
    } else {
        this.result = Result.SUCCESS;
    }
    return true;
}
 
Example #9
Source File: Differential.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
public String getRevisionID(boolean formatted) {
    Object rawRevisionIdObj = rawJSON.get("revisionID");
    String rawRevisionId = rawRevisionIdObj != null && !(rawRevisionIdObj instanceof net.sf.json.JSONNull) ? (String) rawRevisionIdObj : null;
    if (rawRevisionId == null || rawRevisionId.equals("")) {
        return null;
    }
    if (formatted) {
        return String.format("D%s", rawRevisionId);
    }
    return rawRevisionId;
}
 
Example #10
Source File: Differential.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
/**
 * Return the local branch name
 *
 * @return the name of the branch, or unknown
 */
public String getBranch() {
    Object branchName = rawJSON.get("branch");
    if (branchName instanceof JSONNull) {
        return "(none)";
    }
    try {
        return (String) branchName;
    } catch (ClassCastException e) {
        return "(unknown)";
    }
}
 
Example #11
Source File: UberallsClient.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
public CodeCoverageMetrics getParentCoverage(String sha) {
    if (sha == null) {
        return null;
    }
    try {
        String coverageJSON = getCoverage(sha);
        JsonSlurper jsonParser = new JsonSlurper();
        JSON responseJSON = jsonParser.parseText(coverageJSON);
        if (responseJSON instanceof JSONNull) {
            return null;
        }
        JSONObject coverage = (JSONObject) responseJSON;

        return new CodeCoverageMetrics(
                ((Double) coverage.getDouble(PACKAGE_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(FILES_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(CLASSES_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(METHOD_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(LINE_COVERAGE_KEY)).floatValue(),
                ((Double) coverage.getDouble(CONDITIONAL_COVERAGE_KEY)).floatValue(),
                (coverage.getLong(LINES_COVERED_KEY)),
                (coverage.getLong(LINES_TESTED_KEY)));
    } catch (Exception e) {
        e.printStackTrace(logger.getStream());
    }

    return null;
}
 
Example #12
Source File: DifferentialTest.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
@Test
public void testGetBranchWithEmptyResponse() throws Exception {
    JSONObject empty = new JSONObject();
    empty.put("branch", JSONNull.getInstance());
    Differential diff = new Differential(empty);
    assertEquals("(none)", diff.getBranch());
}
 
Example #13
Source File: JiraConverter.java    From benten with MIT License 4 votes vote down vote up
public ValueTuple(String type, Object value) {
    this.type = type;
    this.value = (value != null ? value : JSONNull.getInstance());
}
 
Example #14
Source File: Http.java    From BotLibre with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public Vertex convertElement(Object json, Network network) {
	try {
		if (json == null) {
			return null;
		}
		Vertex object = null;
		if (json instanceof JSONObject) {
			object = network.createVertex();
			for (Iterator iterator = ((JSONObject)json).keys(); iterator.hasNext(); ) {
				String name = (String)iterator.next();
				Object value = ((JSONObject)json).get(name);
				if (value == null) {
					continue;
				}
				Primitive key = new Primitive(name);
				Vertex target = convertElement(value, network);
				object.addRelationship(key, target);
			}
		} else if (json instanceof JSONArray) {
			object = network.createInstance(Primitive.ARRAY);
			JSONArray array = (JSONArray)json;
			for (int index = 0; index < array.size(); index++) {
				Vertex element = convertElement(array.get(index), network);
				object.addRelationship(Primitive.ELEMENT, element, index);
			}
		} else if (json instanceof JSONNull) {
			object = network.createInstance(Primitive.NULL);
		} else if (json instanceof String) {
			object = network.createVertex(json);
		} else if (json instanceof Number) {
			object = network.createVertex(json);
		} else if (json instanceof Date) {
			object = network.createVertex(json);
		} else if (json instanceof Boolean) {
			object = network.createVertex(json);
		} else {
			log("Unknown JSON object", Level.INFO, json);
		}
		return object;
	} catch (Exception exception) {
		log(exception);
		return null;
	}
}