Search in sources :

Example 1 with SoapFaultException

use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.

the class RemoteFreeBusyProvider method addResults.

@Override
public void addResults(Element response) {
    Provisioning prov = Provisioning.getInstance();
    for (Map.Entry<String, StringBuilder> entry : mRemoteAccountMap.entrySet()) {
        // String server = entry.getKey();
        String paramStr = entry.getValue().toString();
        String[] idStrs = paramStr.split(",");
        try {
            Element req = mSoapCtxt.getRequestProtocol().getFactory().createElement(MailConstants.GET_FREE_BUSY_REQUEST);
            req.addAttribute(MailConstants.A_CAL_START_TIME, mStart);
            req.addAttribute(MailConstants.A_CAL_END_TIME, mEnd);
            req.addAttribute(MailConstants.A_UID, paramStr);
            // hack: use the ID of the first user
            Account acct = prov.get(AccountBy.name, idStrs[0], mSoapCtxt.getAuthToken());
            if (acct == null)
                acct = prov.get(AccountBy.id, idStrs[0], mSoapCtxt.getAuthToken());
            if (acct != null) {
                Element remoteResponse = proxyRequest(req, acct.getId(), mSoapCtxt);
                for (Element thisElt : remoteResponse.listElements()) response.addElement(thisElt.detach());
            } else {
                ZimbraLog.fb.debug("Account " + idStrs[0] + " not found while searching free/busy");
            }
        } catch (SoapFaultException e) {
            ZimbraLog.fb.error("cannot get free/busy for " + idStrs[0], e);
            addFailedAccounts(response, idStrs);
        } catch (ServiceException e) {
            ZimbraLog.fb.error("cannot get free/busy for " + idStrs[0], e);
            addFailedAccounts(response, idStrs);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) HashMap(java.util.HashMap) Map(java.util.Map) Provisioning(com.zimbra.cs.account.Provisioning) SoapFaultException(com.zimbra.common.soap.SoapFaultException)

Example 2 with SoapFaultException

use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.

the class MailItemResource method moveORcopyWithOverwrite.

public void moveORcopyWithOverwrite(DavContext ctxt, Collection dest, String newName, boolean deleteOriginal) throws DavException {
    try {
        if (deleteOriginal)
            move(ctxt, dest, newName);
        else
            copy(ctxt, dest, newName);
    } catch (DavException e) {
        if (e.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
            // in case of name conflict, delete the existing mail item and
            // attempt the move operation again.
            // return if the error is not ALREADY_EXISTS
            ServiceException se = (ServiceException) e.getCause();
            int id = 0;
            try {
                if (se.getCode().equals(MailServiceException.ALREADY_EXISTS) == false)
                    throw e;
                else {
                    // get the conflicting item-id
                    if (se instanceof SoapFaultException) {
                        // destination belongs other mailbox.
                        String itemIdStr = ((SoapFaultException) se).getArgumentValue("id");
                        ItemId itemId = new ItemId(itemIdStr, dest.getItemId().getAccountId());
                        id = itemId.getId();
                    } else {
                        // destination belongs to same mailbox.
                        String name = null;
                        for (Argument arg : se.getArgs()) {
                            if (arg.name != null && arg.value != null && arg.value.length() > 0) {
                                if (arg.name.equals("name"))
                                    name = arg.value;
                            /* commented out since the exception is giving wrong itemId for copy.
                                       If the the item is conflicting with an existing item we want the
                                       id of the existing item. But, the exception has the proposed id of
                                       the new item which does not exist yet.
                                     else if (arg.mName.equals("itemId"))
                                        id = Integer.parseInt(arg.mValue);
                                     */
                            }
                        }
                        if (id <= 0) {
                            if (name == null && !deleteOriginal) {
                                // in case of copy get the id from source name since we don't support copy with rename.
                                name = ctxt.getItem();
                            }
                            if (name != null) {
                                Mailbox mbox = getMailbox(ctxt);
                                MailItem item = mbox.getItemByPath(ctxt.getOperationContext(), name, dest.getId());
                                id = item.getId();
                            } else
                                throw e;
                        }
                    }
                }
                deleteDestinationItem(ctxt, dest, id);
            } catch (ServiceException se1) {
                throw new DavException("cannot move/copy item", HttpServletResponse.SC_FORBIDDEN, se1);
            }
            if (deleteOriginal)
                move(ctxt, dest, newName);
            else
                copy(ctxt, dest, newName);
        } else {
            throw e;
        }
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Argument(com.zimbra.common.service.ServiceException.Argument) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) DavException(com.zimbra.cs.dav.DavException) ItemId(com.zimbra.cs.service.util.ItemId) SoapFaultException(com.zimbra.common.soap.SoapFaultException)

Example 3 with SoapFaultException

use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.

the class ImapServerListener method deleteWaitSet.

private void deleteWaitSet() throws ServiceException {
    ZimbraLog.imap.debug("Deleting waitset %s", wsID);
    cancelPendingRequest();
    if (wsID != null) {
        AdminDestroyWaitSetRequest req = new AdminDestroyWaitSetRequest(wsID);
        checkAuth();
        try {
            synchronized (soapProv) {
                try {
                    soapProv.invokeJaxbAsAdminWithRetry(req);
                } catch (SoapFaultException ex) {
                    if (AdminServiceException.NO_SUCH_WAITSET.equalsIgnoreCase(ex.getCode())) {
                        ZimbraLog.imap.debug("Caught NO_SUCH_WAITSET exception trying to delete a waitset. Waitset may have been deleted by sweeper. Ignoring.");
                    }
                } catch (ServiceException e) {
                    ZimbraLog.imap.error("Caught unexpected exception trying to delete a waitset.", e);
                }
            }
        } finally {
            wsID = null;
            unsetWaitSetIdOnMailboxes();
            lastSequence.set(0);
        }
    }
}
Also used : AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) ServiceException(com.zimbra.common.service.ServiceException) AdminServiceException(com.zimbra.cs.service.admin.AdminServiceException) SoapFaultException(com.zimbra.common.soap.SoapFaultException)

Example 4 with SoapFaultException

use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.

the class TestLockoutMailbox method testLockoutSufficientPermissions.

@Test
public void testLockoutSufficientPermissions() throws Exception {
    Mailbox mbox = TestUtil.getMailbox(MY_USER);
    TestUtil.addMessage(mbox, "test");
    TestUtil.waitForMessage(TestUtil.getZMailbox(MY_USER), "test");
    List<AdminRight> relatedRights = new ArrayList<AdminRight>();
    List<String> notes = new ArrayList<String>();
    AdminDocumentHandler handler = new LockoutMailbox();
    handler.docRights(relatedRights, notes);
    createDelegatedAdmin(relatedRights);
    LockoutMailboxRequest req = LockoutMailboxRequest.create(AccountNameSelector.fromName(MY_USER));
    req.setOperation(AdminConstants.A_START);
    try {
        LockoutMailboxResponse resp = delegatedSoapProv.invokeJaxb(req);
        assertNotNull("LockoutMailboxResponse should not be null", resp);
    } catch (SoapFaultException e) {
        fail("should not be getting an exception");
    }
    req = LockoutMailboxRequest.create(AccountNameSelector.fromName(MY_NON_EXISTING_USER));
    req.setOperation(AdminConstants.A_START);
    try {
        delegatedSoapProv.invokeJaxb(req);
        fail("should have caught an exception");
    } catch (SoapFaultException e) {
        assertEquals("should be getting 'no such account' response", AccountServiceException.NO_SUCH_ACCOUNT, e.getCode());
    }
}
Also used : LockoutMailboxResponse(com.zimbra.soap.admin.message.LockoutMailboxResponse) LockoutMailbox(com.zimbra.cs.service.admin.LockoutMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) ArrayList(java.util.ArrayList) AdminDocumentHandler(com.zimbra.cs.service.admin.AdminDocumentHandler) LockoutMailbox(com.zimbra.cs.service.admin.LockoutMailbox) SoapFaultException(com.zimbra.common.soap.SoapFaultException) LockoutMailboxRequest(com.zimbra.soap.admin.message.LockoutMailboxRequest) Test(org.junit.Test)

Example 5 with SoapFaultException

use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.

the class TestLockoutMailbox method testLockAccountEnumeration.

@Test
public void testLockAccountEnumeration() throws Exception {
    Mailbox mbox = TestUtil.getMailbox(MY_USER);
    TestUtil.addMessage(mbox, "test");
    TestUtil.waitForMessage(TestUtil.getZMailbox(MY_USER), "test");
    List<AdminRight> relatedRights = new ArrayList<AdminRight>();
    List<String> notes = new ArrayList<String>();
    AdminDocumentHandler handler = new LockoutMailbox();
    handler.docRights(relatedRights, notes);
    createDelegatedAdmin(relatedRights);
    LockoutMailboxRequest req = LockoutMailboxRequest.create(AccountNameSelector.fromName(OFFLIMITS_NON_EXISTING_USER));
    req.setOperation(AdminConstants.A_START);
    try {
        delegatedSoapProv.invokeJaxb(req);
        fail("should have caught an exception");
    } catch (SoapFaultException e) {
        assertEquals("should be getting 'Permission Denied' response", ServiceException.PERM_DENIED, e.getCode());
    }
}
Also used : LockoutMailbox(com.zimbra.cs.service.admin.LockoutMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) AdminRight(com.zimbra.cs.account.accesscontrol.AdminRight) ArrayList(java.util.ArrayList) AdminDocumentHandler(com.zimbra.cs.service.admin.AdminDocumentHandler) LockoutMailbox(com.zimbra.cs.service.admin.LockoutMailbox) SoapFaultException(com.zimbra.common.soap.SoapFaultException) LockoutMailboxRequest(com.zimbra.soap.admin.message.LockoutMailboxRequest) Test(org.junit.Test)

Aggregations

SoapFaultException (com.zimbra.common.soap.SoapFaultException)81 Test (org.junit.Test)62 Element (com.zimbra.common.soap.Element)32 Account (com.zimbra.cs.account.Account)23 ServiceException (com.zimbra.common.service.ServiceException)15 SoapTransport (com.zimbra.common.soap.SoapTransport)15 Attr (com.zimbra.soap.admin.type.Attr)15 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)14 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)14 ZMailbox (com.zimbra.client.ZMailbox)12 SoapProtocol (com.zimbra.common.soap.SoapProtocol)11 ArrayList (java.util.ArrayList)11 DeployZimletRequest (com.zimbra.soap.admin.message.DeployZimletRequest)10 CreateSignatureRequest (com.zimbra.soap.account.message.CreateSignatureRequest)9 Signature (com.zimbra.soap.account.type.Signature)9 AttachmentIdAttrib (com.zimbra.soap.admin.type.AttachmentIdAttrib)9 AdminDocumentHandler (com.zimbra.cs.service.admin.AdminDocumentHandler)8 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 Provisioning (com.zimbra.cs.account.Provisioning)5 AdminRight (com.zimbra.cs.account.accesscontrol.AdminRight)5