use of net.sf.json.JSONException in project phabricator-jenkins-plugin by uber.
the class BuildResultProcessor method processLintResults.
/**
* Fetch remote lint violations from the build workspace and process
*
* @param lintFile the path pattern of the file
* @param lintFileSize maximum number of bytes to read from the remote file
*/
public void processLintResults(String lintFile, String lintFileSize) {
RemoteFileFetcher lintFetcher = new RemoteFileFetcher(workspace, logger, lintFile, lintFileSize);
try {
String input = lintFetcher.getRemoteFile();
if (input != null && input.length() > 0) {
lintResults = new LintResults();
BufferedReader reader = new BufferedReader(new StringReader(input));
String lint = "";
String line;
while ((line = reader.readLine()) != null) {
lint += line;
try {
JSONObject json = JSONObject.fromObject(lint);
lintResults.add(LintResult.fromJsonObject(json));
lint = "";
} catch (JSONException e) {
e.printStackTrace(logger.getStream());
}
}
}
} catch (InterruptedException e) {
e.printStackTrace(logger.getStream());
} catch (IOException e) {
e.printStackTrace(logger.getStream());
}
}
use of net.sf.json.JSONException in project sonar-scanner-jenkins by SonarSource.
the class SonarQubeWebHook method doIndex.
@RequirePOST
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException {
String payload = IOUtils.toString(req.getReader());
LOGGER.info("Received POST from " + req.getRemoteHost());
try {
JSONObject o = JSONObject.fromObject(payload);
LOGGER.fine(() -> "Full details of the POST was " + o.toString());
String taskId = o.getString("taskId");
String status = o.getString("status");
String qgStatus = null;
if (CETask.STATUS_SUCCESS.equals(status)) {
qgStatus = o.has("qualityGate") ? o.getJSONObject("qualityGate").getString("status") : "NONE";
}
for (Listener listener : listeners) {
listener.onTaskCompleted(taskId, status, qgStatus);
}
} catch (JSONException e) {
LOGGER.log(Level.WARNING, e, () -> "Invalid payload " + payload);
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON Payload");
}
rsp.setStatus(HttpServletResponse.SC_OK);
}
use of net.sf.json.JSONException in project sonar-scanner-jenkins by SonarSource.
the class WsClient method getCETask.
public CETask getCETask(String taskId) {
String url = serverUrl + API_CE_TASK + taskId;
String text = client.getHttp(url, token);
try {
JSONObject json = (JSONObject) JSONSerializer.toJSON(text);
JSONObject task = json.getJSONObject("task");
String status = task.getString(STATUS_ATTR);
String componentName = task.getString("componentName");
String componentKey = task.getString("componentKey");
// No analysisId if task is pending
String analysisId = task.optString("analysisId", null);
return new CETask(status, componentName, componentKey, url, analysisId);
} catch (JSONException e) {
throw new IllegalStateException("Unable to parse response from " + url + ":\n" + text, e);
}
}
use of net.sf.json.JSONException in project sonar-scanner-jenkins by SonarSource.
the class WsClient method requestQualityGateStatus.
public String requestQualityGateStatus(String analysisId) {
String url = serverUrl + API_PROJECT_STATUS_WITH_ANALYSISID + encode(analysisId);
String text = client.getHttp(url, token);
try {
JSONObject json = (JSONObject) JSONSerializer.toJSON(text);
JSONObject projectStatus = json.getJSONObject("projectStatus");
return projectStatus.getString(STATUS_ATTR);
} catch (JSONException e) {
throw new IllegalStateException("Unable to parse response from " + url + ":\n" + text, e);
}
}
use of net.sf.json.JSONException in project camel by apache.
the class XmlJsonExceptionsTest method testSendJsonToXML.
@Test
public void testSendJsonToXML() throws Exception {
String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";
MockEndpoint mockJSON = getMockEndpoint("mock:xml");
mockJSON.expectedMessageCount(0);
MockEndpoint mockException = getMockEndpoint("mock:exception");
mockException.expectedMessageCount(1);
try {
template.requestBody("direct:unmarshal", in);
fail("Exception expected");
} catch (CamelExecutionException e) {
assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
}
List<Exchange> exchs = mockException.getExchanges();
assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());
Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
assertNotNull("Exception expected", e);
assertEquals("JSONException expected", JSONException.class, e.getClass());
assertMockEndpointsSatisfied();
}
Aggregations