Search in sources :

Example 21 with SoapProtocol

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();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) SoapProtocol(com.zimbra.common.soap.SoapProtocol) ArrayList(java.util.ArrayList) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Example 22 with SoapProtocol

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);
}
Also used : StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Element(com.zimbra.common.soap.Element) SoapProtocol(com.zimbra.common.soap.SoapProtocol)

Aggregations

SoapProtocol (com.zimbra.common.soap.SoapProtocol)22 Element (com.zimbra.common.soap.Element)18 SoapFaultException (com.zimbra.common.soap.SoapFaultException)11 Account (com.zimbra.cs.account.Account)11 SoapTransport (com.zimbra.common.soap.SoapTransport)9 CreateSignatureRequest (com.zimbra.soap.account.message.CreateSignatureRequest)9 Signature (com.zimbra.soap.account.type.Signature)9 Test (org.junit.Test)9 ServiceException (com.zimbra.common.service.ServiceException)3 AuthToken (com.zimbra.cs.account.AuthToken)3 AdminDocumentHandler (com.zimbra.cs.service.admin.AdminDocumentHandler)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 GetSignaturesRequest (com.zimbra.soap.account.message.GetSignaturesRequest)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2