Search in sources :

Example 11 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class JaxbUtil method jaxbToNamedElement.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Element jaxbToNamedElement(String name, String namespace, Object o, Element.ElementFactory factory) throws ServiceException {
    if (Element.JSONElement.mFactory.equals(factory)) {
        return JacksonUtil.jaxbToJSONElement(o, org.dom4j.QName.get(name, namespace));
    }
    try {
        Marshaller marshaller = createMarshaller(o.getClass());
        // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        DocumentResult dr = new DocumentResult();
        marshaller.marshal(new JAXBElement(new QName(namespace, name), o.getClass(), o), dr);
        Document theDoc = dr.getDocument();
        org.dom4j.Element rootElem = theDoc.getRootElement();
        return Element.convertDOM(rootElem, factory);
    } catch (Exception e) {
        throw ServiceException.FAILURE("Unable to convert " + o.getClass().getName() + " to Element", e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) DocumentResult(org.dom4j.io.DocumentResult) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Document(org.dom4j.Document) ServiceException(com.zimbra.common.service.ServiceException) JAXBException(javax.xml.bind.JAXBException)

Example 12 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ExtShareInfoTest method testGenNotifyBody.

@Test
public void testGenNotifyBody() {
    Locale locale = new Locale("en", "US");
    String notes = "none";
    ShareInfoData sid = new ShareInfoData();
    sid.setGranteeDisplayName("Demo User Three");
    sid.setGranteeId(testAcct.getId());
    sid.setGranteeName(testAcct.getName());
    sid.setGranteeType(ACL.GRANTEE_GUEST);
    sid.setPath("/Inbox/Test");
    sid.setFolderDefaultView(MailItem.Type.MESSAGE);
    sid.setItemUuid("9badf685-3420-458b-9ce5-826b0bec638f");
    sid.setItemId(257);
    sid.setOwnerAcctId(ownerAcct.getId());
    sid.setOwnerAcctEmail(ownerAcct.getName());
    sid.setOwnerAcctDisplayName("Demo User Two");
    try {
        sid.setRights(ACL.stringToRights("rwidxap"));
        MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, null, null);
        Assert.assertNotNull(mmp);
        String body = (String) mmp.getBodyPart(0).getDataHandler().getContent();
        int index = body.indexOf("http");
        int endIndex = body.indexOf(".", index);
        String authUrl = body.substring(index, endIndex);
        index = authUrl.indexOf("p=");
        String authToken = authUrl.substring(index + 2);
        try {
            ZimbraAuthToken.getAuthToken(authToken);
            fail("Authtoken should fail");
        } catch (AuthTokenException e) {
            assertTrue(e.getMessage().contains("hmac failure"));
        }
    // Commenting for now, need to figure out why it fails on hudson
    //           try {
    //               ExternalUserProvServlet.validatePrelimToken(authToken);
    //           } catch (Exception e) {
    //               fail("Should not throw Exception" + e.getMessage());
    //           }
    } catch (ServiceException | MessagingException | IOException e) {
        fail("Exception should not be thrown: " + e.getMessage());
    }
}
Also used : Locale(java.util.Locale) ServiceException(com.zimbra.common.service.ServiceException) MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ShareInfoTest method testGenNotifyBody.

@Test
public void testGenNotifyBody() {
    Locale locale = new Locale("en", "US");
    String notes = "none";
    ShareInfoData sid = new ShareInfoData();
    sid.setGranteeDisplayName("Demo User Three");
    sid.setGranteeId("46031e4c-deb4-4724-b5bb-8f854d0c518a");
    sid.setGranteeName("Demo User Three");
    sid.setGranteeType(ACL.GRANTEE_USER);
    sid.setPath("/Calendar/Cal1");
    sid.setFolderDefaultView(MailItem.Type.APPOINTMENT);
    sid.setItemUuid("9badf685-3420-458b-9ce5-826b0bec638f");
    sid.setItemId(257);
    sid.setOwnerAcctId("bbf152ca-e7cd-477e-9f72-70fef715c5f9");
    sid.setOwnerAcctEmail("test@zimbra.com");
    sid.setOwnerAcctDisplayName("Demo User Two");
    try {
        sid.setRights(ACL.stringToRights("rwidxap"));
        MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, null, null);
        Assert.assertNotNull(mmp);
        String body = (String) mmp.getBodyPart(0).getDataHandler().getContent();
        assertTrue(body.indexOf("Role: Admin") != -1);
    } catch (ServiceException | MessagingException | IOException e) {
        fail("Exception should not be thrown: " + e.getMessage());
    }
}
Also used : Locale(java.util.Locale) ServiceException(com.zimbra.common.service.ServiceException) MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ZimbraQueryTest method checkSortCompatibility.

@Test
public void checkSortCompatibility() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    SearchParams params = new SearchParams();
    params.setQueryString("in:inbox content:test");
    params.setSortBy(SortBy.RCPT_ASC);
    try {
        new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
        Assert.fail();
    } catch (ServiceException e) {
        Assert.assertEquals(ServiceException.INVALID_REQUEST, e.getCode());
    }
    params.setSortBy(SortBy.ATTACHMENT_ASC);
    try {
        new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    } catch (ServiceException e) {
        Assert.fail("Sorting by whether has attachments should be supported");
    }
    params.setSortBy(SortBy.FLAG_ASC);
    try {
        new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    } catch (ServiceException e) {
        Assert.fail("Sorting by flagged should be supported");
    }
    params.setSortBy(SortBy.PRIORITY_ASC);
    try {
        new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    } catch (ServiceException e) {
        Assert.fail("Sorting by priority should be supported");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test)

Example 15 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class DocumentTest method checkName.

private static void checkName(Mailbox mbox, String name, boolean valid) throws Exception {
    Document doc = null;
    ParsedDocument pd = new ParsedDocument(new ByteArrayInputStream("test".getBytes()), name, "text/plain", System.currentTimeMillis(), null, null);
    try {
        doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
        if (!valid) {
            Assert.fail("should not have been allowed to create document: [" + name + "]");
        }
    } catch (ServiceException e) {
        Assert.assertEquals("unexpected error code", MailServiceException.INVALID_NAME, e.getCode());
        if (valid) {
            Assert.fail("should have been allowed to create document: [" + name + "]");
        }
    }
    // clean up after ourselves
    if (doc != null) {
        mbox.delete(null, doc.getId(), MailItem.Type.DOCUMENT);
    }
}
Also used : ParsedDocument(com.zimbra.cs.mime.ParsedDocument) ServiceException(com.zimbra.common.service.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) ParsedDocument(com.zimbra.cs.mime.ParsedDocument)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)772 AccountServiceException (com.zimbra.cs.account.AccountServiceException)220 Account (com.zimbra.cs.account.Account)193 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)149 IOException (java.io.IOException)127 Mailbox (com.zimbra.cs.mailbox.Mailbox)122 ArrayList (java.util.ArrayList)107 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)100 Element (com.zimbra.common.soap.Element)97 HashMap (java.util.HashMap)93 Test (org.junit.Test)89 Provisioning (com.zimbra.cs.account.Provisioning)86 Domain (com.zimbra.cs.account.Domain)60 Folder (com.zimbra.cs.mailbox.Folder)54 Server (com.zimbra.cs.account.Server)53 ItemId (com.zimbra.cs.service.util.ItemId)52 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)51 ZMailbox (com.zimbra.client.ZMailbox)50 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)46 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)44