use of com.zimbra.common.soap.SoapProtocol in project zm-mailbox by Zimbra.
the class ItemAction method handleCommon.
protected String handleCommon(Map<String, Object> context, Element request, String opAttr, MailItem.Type type) throws ServiceException {
Element action = request.getElement(MailConstants.E_ACTION);
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
SoapProtocol responseProto = zsc.getResponseProtocol();
// determine the requested operation
boolean flagValue = !opAttr.startsWith("!");
String opStr = getOperation(opAttr);
// figure out which items are local and which ones are remote, and proxy accordingly
List<Integer> local = new ArrayList<Integer>();
Map<String, StringBuilder> remote = new HashMap<String, StringBuilder>();
partitionItems(zsc, action.getAttribute(MailConstants.A_ID), local, remote);
if (remote.isEmpty() && local.isEmpty()) {
return "";
}
// for moves/copies, make sure that we're going to receive notifications from the target folder
Account remoteNotify = forceRemoteSession(zsc, context, octxt, opStr, action);
// handle referenced items living on other servers
StringBuilder successes = proxyRemoteItems(action, remote, request, context);
// handle referenced items living on this server
if (!local.isEmpty()) {
String constraint = action.getAttribute(MailConstants.A_TARGET_CONSTRAINT, null);
TargetConstraint tcon = TargetConstraint.parseConstraint(mbox, constraint);
String localResults;
// set additional parameters (depends on op type)
if (opStr.equals(OP_TAG)) {
String tagName = action.getAttribute(MailConstants.A_TAG_NAMES, null);
if (tagName == null) {
if (action.getAttribute(MailConstants.A_TAG) == null) {
throw ServiceException.INVALID_REQUEST("missing required attribute: " + MailConstants.A_TAG_NAMES, null);
}
tagName = TagUtil.tagIdToName(mbox, octxt, (int) action.getAttributeLong(MailConstants.A_TAG));
}
localResults = ItemActionHelper.TAG(octxt, mbox, responseProto, local, type, tagName, flagValue, tcon).getResult();
} else if (opStr.equals(OP_FLAG)) {
localResults = ItemActionHelper.FLAG(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
} else if (opStr.equals(OP_PRIORITY)) {
localResults = ItemActionHelper.PRIORITY(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
} else if (opStr.equals(OP_READ)) {
localResults = ItemActionHelper.READ(octxt, mbox, responseProto, local, type, flagValue, tcon).getResult();
} else if (opStr.equals(OP_COLOR)) {
Color color = getColor(action);
localResults = ItemActionHelper.COLOR(octxt, mbox, responseProto, local, type, tcon, color).getResult();
} else if (opStr.equals(OP_HARD_DELETE)) {
localResults = ItemActionHelper.HARD_DELETE(octxt, mbox, responseProto, local, type, tcon).getResult();
} else if (opStr.equals(OP_RECOVER)) {
ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER), zsc);
localResults = ItemActionHelper.RECOVER(octxt, mbox, responseProto, local, type, tcon, iidFolder).getResult();
} else if (opStr.equals(OP_DUMPSTER_DELETE)) {
localResults = ItemActionHelper.DUMPSTER_DELETE(octxt, mbox, responseProto, local, type, tcon).getResult();
} else if (opStr.equals(OP_TRASH)) {
localResults = handleTrashOperation(octxt, request, mbox, responseProto, local, type, tcon);
} else if (opStr.equals(OP_MOVE)) {
localResults = handleMoveOperation(zsc, octxt, request, action, mbox, responseProto, local, type, tcon);
} else if (opStr.equals(OP_COPY)) {
ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER), zsc);
localResults = ItemActionHelper.COPY(octxt, mbox, responseProto, local, type, tcon, iidFolder).getResult();
} else if (opStr.equals(OP_SPAM)) {
String defaultFolder = (flagValue ? Mailbox.ID_FOLDER_SPAM : Mailbox.ID_FOLDER_INBOX) + "";
ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER, defaultFolder), zsc);
localResults = ItemActionHelper.SPAM(octxt, mbox, responseProto, local, type, flagValue, tcon, iidFolder).getResult();
} else if (opStr.equals(OP_RENAME)) {
String name = action.getAttribute(MailConstants.A_NAME);
ItemId iidFolder = new ItemId(action.getAttribute(MailConstants.A_FOLDER, "-1"), zsc);
localResults = ItemActionHelper.RENAME(octxt, mbox, responseProto, local, type, tcon, name, iidFolder).getResult();
} else if (opStr.equals(OP_UPDATE)) {
String folderId = action.getAttribute(MailConstants.A_FOLDER, null);
ItemId iidFolder = new ItemId(folderId == null ? "-1" : folderId, zsc);
if (!iidFolder.belongsTo(mbox)) {
throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
} else if (folderId != null && iidFolder.getId() <= 0) {
throw MailServiceException.NO_SUCH_FOLDER(iidFolder.getId());
}
String name = action.getAttribute(MailConstants.A_NAME, null);
String flags = action.getAttribute(MailConstants.A_FLAGS, null);
String[] tags = TagUtil.parseTags(action, mbox, octxt);
Color color = getColor(action);
localResults = ItemActionHelper.UPDATE(octxt, mbox, responseProto, local, type, tcon, name, iidFolder, flags, tags, color).getResult();
} else if (opStr.equals(OP_LOCK)) {
localResults = ItemActionHelper.LOCK(octxt, mbox, responseProto, local, type, tcon).getResult();
} else if (opStr.equals(OP_UNLOCK)) {
localResults = ItemActionHelper.UNLOCK(octxt, mbox, responseProto, local, type, tcon).getResult();
} else if (opStr.equals(OP_INHERIT)) {
mbox.alterTag(octxt, ArrayUtil.toIntArray(local), type, Flag.FlagInfo.NO_INHERIT, false, tcon);
localResults = Joiner.on(",").join(local);
} else if (opStr.equals(OP_MUTE) && type == MailItem.Type.CONVERSATION) {
// note that "mute" ignores the tcon value
localResults = ItemActionHelper.TAG(octxt, mbox, responseProto, local, type, Flag.FlagInfo.MUTED.toString(), flagValue, null).getResult();
if (flagValue) {
// when marking muted, items are also marked read
ItemActionHelper.READ(octxt, mbox, responseProto, local, type, flagValue, null).getResult();
}
} else {
throw ServiceException.INVALID_REQUEST("unknown operation: " + opStr, null);
}
successes.append(successes.length() > 0 ? "," : "").append(localResults);
}
// for moves/copies, make sure that we received notifications from the target folder
if (remoteNotify != null) {
proxyRequest(zsc.createElement(MailConstants.NO_OP_REQUEST), context, remoteNotify.getId());
}
return successes.toString();
}
use of com.zimbra.common.soap.SoapProtocol in project zm-mailbox by Zimbra.
the class TestJaxb method sendReq.
private Object sendReq(String requestBody, String requestCommand) throws HttpException, IOException, ServiceException {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(TestUtil.getSoapUrl() + requestCommand);
post.setRequestEntity(new StringRequestEntity(requestBody, "application/soap+xml", "UTF-8"));
int respCode = HttpClientUtil.executeMethod(client, post);
Assert.assertEquals(200, respCode);
Element envelope = W3cDomUtil.parseXML(post.getResponseBodyAsStream());
SoapProtocol proto = SoapProtocol.determineProtocol(envelope);
Element doc = proto.getBodyElement(envelope);
return JaxbUtil.elementToJaxb(doc);
}
Aggregations