use of com.zimbra.cs.rmgmt.RemoteManager in project zm-mailbox by Zimbra.
the class GetMailQueueInfo method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Element serverElem = request.getElement(AdminConstants.E_SERVER);
String serverName = serverElem.getAttribute(AdminConstants.A_NAME);
Server server = prov.get(Key.ServerBy.name, serverName);
if (server == null) {
throw ServiceException.INVALID_REQUEST("server with name " + serverName + " could not be found", null);
}
checkRight(zsc, context, server, Admin.R_manageMailQueue);
RemoteManager rmgr = RemoteManager.getRemoteManager(server);
RemoteResult rr = rmgr.execute(RemoteCommands.ZMQSTAT_ALL);
Map<String, String> queueInfo;
try {
queueInfo = RemoteResultParser.parseSingleMap(rr);
} catch (IOException ioe) {
throw ServiceException.FAILURE("exception occurred handling command", ioe);
}
if (queueInfo == null) {
throw ServiceException.FAILURE("server " + serverName + " returned no result", null);
}
Element response = zsc.createElement(AdminConstants.GET_MAIL_QUEUE_INFO_RESPONSE);
serverElem = response.addElement(AdminConstants.E_SERVER);
serverElem.addAttribute(AdminConstants.A_NAME, serverName);
for (String k : queueInfo.keySet()) {
Element queue = serverElem.addElement(AdminConstants.E_QUEUE);
queue.addAttribute(AdminConstants.A_NAME, k);
queue.addAttribute(AdminConstants.A_N, queueInfo.get(k));
}
return response;
}
Aggregations