tx.sendResponse(HTTP_OK, "application/json", connection.toString());
}
else
{ // In this block we are dealing with resources associated with a specified connectionName.
// path describes the resources specifically related to "/qpid/connection/<connectionName>"
Console console = connection.getConsole();
if (path.startsWith("console/objects/"))
{ // Get information about specified objects.
path = path.substring(16);
sendGetObjectsResponse(tx, console, path);
}
else if (path.startsWith("console/objects") && path.length() == 15)
{ // If objects is unspecified treat as a synonym for classes.
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getClasses()));
}
else if (path.startsWith("console/address/"))
{ // Get the Console AMQP Address
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAddress()));
}
else if (path.startsWith("console/address") && path.length() == 15)
{ // Get the Console AMQP Address
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAddress()));
}
else if (path.startsWith("console/workItemCount/"))
{ // Returns the count of pending WorkItems that can be retrieved.
tx.sendResponse(HTTP_OK, "text/plain", "" + console.getWorkitemCount());
}
else if (path.startsWith("console/workItemCount") && path.length() == 21)
{ // Returns the count of pending WorkItems that can be retrieved.
tx.sendResponse(HTTP_OK, "text/plain", "" + console.getWorkitemCount());
}
else if (path.startsWith("console/nextWorkItem/"))
{ // Obtains the next pending work item, or null if none available.
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getNextWorkitem()));
}
else if (path.startsWith("console/nextWorkItem") && path.length() == 20)
{ // Obtains the next pending work item, or null if none available.
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getNextWorkitem()));
}
else if (path.startsWith("console/agents") && path.length() == 14)
{ // Get information about all available Agents.
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAgents()));
}
else if (path.startsWith("console/agent/"))
{ // Get information about a specified Agent.
Agent agent = console.getAgent(path.substring(14));
if (agent == null)
{
tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
}
else
{
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(agent));
}
}
else if (path.startsWith("console/agent") && path.length() == 13)
{ // If agent is unspecified treat as a synonym for agents.
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getAgents()));
}
else if (path.startsWith("console/classes/"))
{ // Get information about the classes for a specified Agent
path = path.substring(16); // Get Agent name
// TODO handle getClasses() for specified Agent
tx.sendResponse(HTTP_NOT_IMPLEMENTED, "text/plain", "501 getClasses() for specified Agent not yet implemented.");
}
else if (path.startsWith("console/classes") && path.length() == 15)
{ // Get information about all the classes for all Agents
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getClasses()));
}
else if (path.startsWith("console/packages/"))
{ // Get information about the packages for a specified Agent
path = path.substring(17); // Get Agent name
// TODO handle getPackages() for specified Agent.
tx.sendResponse(HTTP_NOT_IMPLEMENTED, "text/plain", "501 getPackages() for specified Agent not yet implemented.");
}
else if (path.startsWith("object/"))
{
/**
* This is the REST implementation of getObjects(oid) it is also the equivalent of
* the QmfConsoleData refresh() method where an object can update its state.
* N.B. that the ManagementAgent on the broker appears not to set the timestamp properties
* in the response to this call, which means that they get set to current time in the
* QmfConsoleData, this is OK for _update_ts but not for _create_ts and _delete_ts
* users of this call should be aware of that in their own code.
*/
path = path.substring(7);
// The ObjectId has been passed in the URI, create a real ObjectId
ObjectId oid = new ObjectId(path);
List<QmfConsoleData> objects = console.getObjects(oid);
if (objects.size() == 0)
{
tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
}
else
{
// Not that in a departure from the QMF2 API this returns the QmfConsoleData object
// rather than a list of size one. Perhaps the APIs should be completely consistent
// but this response seems more convenient.
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(objects.get(0)));
}
}
else if (path.startsWith("console/packages") && path.length() == 16)
{ // Get information about all the packages for all Agents
tx.sendResponse(HTTP_OK, "application/json", JSON.fromObject(console.getPackages()));
}
else
{
tx.sendResponse(HTTP_NOT_FOUND, "text/plain", "404 Not Found.");
}