Search in sources :

Example 76 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project ORCID-Source by ORCID.

the class SalesForceAdapter method extractObjectListFromRecords.

private List<JSONObject> extractObjectListFromRecords(JSONObject object) throws JSONException {
    List<JSONObject> objects = new ArrayList<>();
    JSONArray records = object.getJSONArray("records");
    for (int i = 0; i < records.length(); i++) {
        objects.add(records.getJSONObject(i));
    }
    return objects;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray)

Example 77 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project wildfly by wildfly.

the class InboundBridgeTestCase method testRollbackWithTwoParticipants.

@Test
public void testRollbackWithTwoParticipants() throws Exception {
    txSupport.startTx();
    enlistLoggingRestATParticipant();
    enlistInboundBridgeResource();
    txSupport.rollbackTx();
    JSONArray participantResourceInvocations = getLoggingRestATParticipantInvocations();
    JSONArray xaResourceInvocations = getInboundBridgeResourceInvocations();
    Assert.assertEquals(1, participantResourceInvocations.length());
    Assert.assertEquals("LoggingRestATResource.terminateParticipant(" + TxStatusMediaType.TX_ROLLEDBACK + ")", participantResourceInvocations.get(0));
    Assert.assertEquals(3, xaResourceInvocations.length());
    Assert.assertEquals("LoggingXAResource.start", xaResourceInvocations.get(0));
    Assert.assertEquals("LoggingXAResource.end", xaResourceInvocations.get(1));
    Assert.assertEquals("LoggingXAResource.rollback", xaResourceInvocations.get(2));
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 78 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project wildfly by wildfly.

the class InboundBridgeTestCase method testRollback.

@Test
public void testRollback() throws Exception {
    txSupport.startTx();
    enlistInboundBridgeResource();
    txSupport.rollbackTx();
    JSONArray jsonArray = getInboundBridgeResourceInvocations();
    Assert.assertEquals(3, jsonArray.length());
    Assert.assertEquals("LoggingXAResource.start", jsonArray.get(0));
    Assert.assertEquals("LoggingXAResource.end", jsonArray.get(1));
    Assert.assertEquals("LoggingXAResource.rollback", jsonArray.get(2));
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 79 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project wildfly by wildfly.

the class InboundBridgeTestCase method testCommit.

@Test
public void testCommit() throws Exception {
    txSupport.startTx();
    enlistInboundBridgeResource();
    txSupport.commitTx();
    final JSONArray jsonArray = getInboundBridgeResourceInvocations();
    Assert.assertEquals(4, jsonArray.length());
    Assert.assertEquals("LoggingXAResource.start", jsonArray.get(0));
    Assert.assertEquals("LoggingXAResource.end", jsonArray.get(1));
    Assert.assertEquals("LoggingXAResource.prepare", jsonArray.get(2));
    Assert.assertEquals("LoggingXAResource.commit", jsonArray.get(3));
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 80 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project apex-core by apache.

the class StramUtils method getStackTrace.

public static JSONObject getStackTrace() {
    Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
    JSONObject jsonObject = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    for (Map.Entry<Thread, StackTraceElement[]> elements : stackTraces.entrySet()) {
        JSONObject jsonThread = new JSONObject();
        Thread thread = elements.getKey();
        try {
            jsonThread.put("name", thread.getName());
            jsonThread.put("state", thread.getState());
            jsonThread.put("id", thread.getId());
            JSONArray stackTraceElements = new JSONArray();
            for (StackTraceElement stackTraceElement : elements.getValue()) {
                stackTraceElements.put(stackTraceElement.toString());
            }
            jsonThread.put("stackTraceElements", stackTraceElements);
            jsonArray.put(jsonThread);
        } catch (Exception ex) {
            LOG.warn("Getting stack trace for the thread " + thread.getName() + " failed.");
            continue;
        }
    }
    try {
        jsonObject.put("threads", jsonArray);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    return jsonObject;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) Map(java.util.Map) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

JSONArray (org.codehaus.jettison.json.JSONArray)338 JSONObject (org.codehaus.jettison.json.JSONObject)280 Test (org.junit.Test)123 WebResource (com.sun.jersey.api.client.WebResource)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)64 JSONException (org.codehaus.jettison.json.JSONException)64 ArrayList (java.util.ArrayList)38 Test (org.testng.annotations.Test)30 Map (java.util.Map)23 HashMap (java.util.HashMap)22 Vertex (com.tinkerpop.blueprints.Vertex)20 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)20 Produces (javax.ws.rs.Produces)17 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)14 GET (javax.ws.rs.GET)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 IOException (java.io.IOException)12 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)12 HashSet (java.util.HashSet)10 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)9