Search in sources :

Example 56 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.

the class DayCounterInfo method toJSON.

// Static --------------------------------------------------------
public static String toJSON(final DayCounterInfo[] infos) {
    JsonObjectBuilder json = JsonLoader.createObjectBuilder();
    JsonArrayBuilder counters = JsonLoader.createArrayBuilder();
    for (DayCounterInfo info : infos) {
        JsonArrayBuilder counter = JsonLoader.createArrayBuilder();
        for (long c : info.getCounters()) {
            counter.add(c);
        }
        JsonObjectBuilder dci = JsonLoader.createObjectBuilder().add("date", info.getDate()).add("counters", counter);
        counters.add(dci);
    }
    json.add("dayCounters", counters);
    return json.build().toString();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 57 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.

the class JsonUtilTest method testAddByteArrayToJsonArray.

@Test
public void testAddByteArrayToJsonArray() {
    JsonArrayBuilder jsonArrayBuilder = JsonLoader.createArrayBuilder();
    byte[] bytes = { 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f };
    JsonUtil.addToArray(bytes, jsonArrayBuilder);
    JsonArray jsonArray = jsonArrayBuilder.build();
    Assert.assertEquals(1, jsonArray.size());
}
Also used : JsonArray(javax.json.JsonArray) JsonArrayBuilder(javax.json.JsonArrayBuilder) Test(org.junit.Test)

Example 58 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method listConnectionsAsJSON.

@Override
public String listConnectionsAsJSON() throws Exception {
    checkStarted();
    clearIO();
    try {
        JsonArrayBuilder array = JsonLoader.createArrayBuilder();
        Set<RemotingConnection> connections = server.getRemotingService().getConnections();
        for (RemotingConnection connection : connections) {
            JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("connectionID", connection.getID().toString()).add("clientAddress", connection.getRemoteAddress()).add("creationTime", connection.getCreationTime()).add("implementation", connection.getClass().getSimpleName()).add("sessionCount", server.getSessions(connection.getID().toString()).size());
            array.add(obj);
        }
        return array.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 59 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method listNetworkTopology.

@Override
public String listNetworkTopology() throws Exception {
    checkStarted();
    clearIO();
    try {
        JsonArrayBuilder brokers = JsonLoader.createArrayBuilder();
        ClusterManager clusterManager = server.getClusterManager();
        if (clusterManager != null) {
            Set<ClusterConnection> clusterConnections = clusterManager.getClusterConnections();
            for (ClusterConnection clusterConnection : clusterConnections) {
                Topology topology = clusterConnection.getTopology();
                Collection<TopologyMemberImpl> members = topology.getMembers();
                for (TopologyMemberImpl member : members) {
                    JsonObjectBuilder obj = JsonLoader.createObjectBuilder();
                    TransportConfiguration live = member.getLive();
                    if (live != null) {
                        obj.add("nodeID", member.getNodeId()).add("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
                        TransportConfiguration backup = member.getBackup();
                        if (backup != null) {
                            obj.add("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
                        }
                    }
                    brokers.add(obj);
                }
            }
        }
        return brokers.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : TopologyMemberImpl(org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JsonArrayBuilder(javax.json.JsonArrayBuilder) Topology(org.apache.activemq.artemis.core.client.impl.Topology) JsonObjectBuilder(javax.json.JsonObjectBuilder) ClusterManager(org.apache.activemq.artemis.core.server.cluster.ClusterManager)

Example 60 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method getConnectorsAsJSON.

@Override
public String getConnectorsAsJSON() throws Exception {
    checkStarted();
    clearIO();
    try {
        JsonArrayBuilder array = JsonLoader.createArrayBuilder();
        for (TransportConfiguration config : configuration.getConnectorConfigurations().values()) {
            array.add(config.toJson());
        }
        return array.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Aggregations

JsonArrayBuilder (javax.json.JsonArrayBuilder)177 JsonObjectBuilder (javax.json.JsonObjectBuilder)103 JsonObject (javax.json.JsonObject)36 Map (java.util.Map)29 Path (javax.ws.rs.Path)26 GET (javax.ws.rs.GET)24 HashMap (java.util.HashMap)19 JsonArray (javax.json.JsonArray)18 ArrayList (java.util.ArrayList)15 List (java.util.List)15 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)12 IOException (java.io.IOException)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)10 Dataset (edu.harvard.iq.dataverse.Dataset)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 JsonValue (javax.json.JsonValue)9 StringWriter (java.io.StringWriter)8 JsonString (javax.json.JsonString)7 Date (java.util.Date)6 JsonException (javax.json.JsonException)6