Search in sources :

Example 6 with SoapHttpTransport

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

the class TestSoap method testAccountGetInfoRequest.

/**
     * Tests the AccountService version of GetInfoRequest (see bug 30010).
     */
@Test
public void testAccountGetInfoRequest() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    Element request = Element.create(transport.getRequestProtocol(), AccountConstants.GET_VERSION_INFO_REQUEST);
    // Test with version exposed
    TestUtil.setServerAttr(Provisioning.A_zimbraSoapExposeVersion, LdapConstants.LDAP_TRUE);
    Element response = transport.invoke(request);
    validateSoapVersionResponse(response);
    // Test with version not exposed
    TestUtil.setServerAttr(Provisioning.A_zimbraSoapExposeVersion, LdapConstants.LDAP_FALSE);
    request = Element.create(transport.getRequestProtocol(), AccountConstants.GET_VERSION_INFO_REQUEST);
    try {
        response = transport.invoke(request);
        Assert.fail("GetInfoRequest should have failed");
    } catch (SoapFaultException e) {
        Assert.assertEquals(ServiceException.PERM_DENIED, e.getCode());
    }
}
Also used : Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test) SoapTest(com.zimbra.qa.unittest.prov.soap.SoapTest)

Example 7 with SoapHttpTransport

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

the class TestSendAndReceive method testSendNoDraft.

@Test
public void testSendNoDraft() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    MailSender.registerPreSendMailListener(listener);
    //register second time to test that it will be triggered once
    MailSender.registerPreSendMailListener(listener);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    String subj = "Dwalin";
    String body = "To dungeons deep, and caverns old";
    String customHeaderValue = "http://zss.server/file1";
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setAuthToken(zmbox.getAuthToken());
    //create a draft with a custom mime header
    Element request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
    Element el = request.addUniqueElement(MailConstants.E_MSG);
    el.addAttribute(MailConstants.E_SUBJECT, subj);
    el.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, body);
    el.addNonUniqueElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, TestUtil.addDomainIfNecessary(REMOTE_USER_NAME));
    el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, MailSender.PRE_SEND_HEADER).setText("custom");
    el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, PUBLIC_LIST_HEADER).setText(customHeaderValue);
    transport.invoke(request);
    Assert.assertTrue("Listener was not triggered", listener.isTriggered());
    Assert.assertEquals("listener should ahve been triggered only once", 1, listener.getTriggerCounter());
    String[] listenersData = listener.getData();
    Assert.assertNotNull("Listener did not get data from custom headers", listenersData);
    Assert.assertTrue("wrong number of elements in custom header data", listenersData.length == 1);
    Assert.assertTrue("wrong value in custom header", customHeaderValue.equalsIgnoreCase(listenersData[0].replace("\"", "")));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Example 8 with SoapHttpTransport

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

the class TestSendAndReceive method testMultipleHeaders.

@Test
public void testMultipleHeaders() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    MailSender.registerPreSendMailListener(listener);
    //register second time to test that it will be triggered once
    MailSender.registerPreSendMailListener(listener);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    String subj = "Dwalin";
    String body = "To dungeons deep, and caverns old";
    String customHeaderValue1 = "http://zss.server/file1";
    String customHeaderValue2 = "http://zss.server/file2";
    String customHeaderValue3 = "http://zss.server/file3";
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setAuthToken(zmbox.getAuthToken());
    //create a draft with a custom mime header
    Element request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
    Element el = request.addUniqueElement(MailConstants.E_MSG);
    el.addAttribute(MailConstants.E_SUBJECT, subj);
    el.addUniqueElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, body);
    el.addNonUniqueElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, TestUtil.addDomainIfNecessary(REMOTE_USER_NAME));
    el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, MailSender.PRE_SEND_HEADER).setText("custom");
    el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, PUBLIC_LIST_HEADER).setText(customHeaderValue1);
    el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, PUBLIC_LIST_HEADER).setText(customHeaderValue2);
    el.addNonUniqueElement(MailConstants.E_HEADER).addAttribute(MailConstants.A_NAME, PUBLIC_LIST_HEADER).setText(customHeaderValue3);
    transport.invoke(request);
    Assert.assertTrue("Listener was not triggered", listener.isTriggered());
    Assert.assertEquals("listener should ahve been triggered only once", 1, listener.getTriggerCounter());
    String[] listenersData = listener.getData();
    Assert.assertNotNull("Listener did not get data from custom headers", listenersData);
    Assert.assertEquals("wrong number of elements in custom header data", 3, listenersData.length);
    List<String> valueList = Arrays.asList(listenersData);
    Assert.assertTrue(customHeaderValue1 + " is missing", valueList.contains(String.format("\"%s\"", customHeaderValue1)));
    Assert.assertTrue(customHeaderValue2 + " is missing", valueList.contains(String.format("\"%s\"", customHeaderValue2)));
    Assert.assertTrue(customHeaderValue3 + " is missing", valueList.contains(String.format("\"%s\"", customHeaderValue3)));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Example 9 with SoapHttpTransport

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

the class SoapTest method authUser.

static SoapTransport authUser(String acctName, String password) throws Exception {
    com.zimbra.soap.type.AccountSelector acct = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acctName);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(soapDebugListener);
    AuthRequest req = new AuthRequest(acct, password);
    AuthResponse resp = invokeJaxb(transport, req);
    transport.setAuthToken(resp.getAuthToken());
    return transport;
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse)

Example 10 with SoapHttpTransport

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

the class FbCli method setServer.

public void setServer(String server) {
    String adminUrl = URLUtil.getAdminURL(server);
    mTransport = new SoapHttpTransport(adminUrl);
}
Also used : SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Aggregations

SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)69 Element (com.zimbra.common.soap.Element)54 Test (org.junit.Test)32 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 ServiceException (com.zimbra.common.service.ServiceException)13 Account (com.zimbra.cs.account.Account)13 DeployZimletRequest (com.zimbra.soap.admin.message.DeployZimletRequest)13 AuthRequest (com.zimbra.soap.account.message.AuthRequest)12 AttachmentIdAttrib (com.zimbra.soap.admin.type.AttachmentIdAttrib)12 XMLElement (com.zimbra.common.soap.Element.XMLElement)11 AuthToken (com.zimbra.cs.account.AuthToken)10 ZAuthToken (com.zimbra.common.auth.ZAuthToken)8 AuthResponse (com.zimbra.soap.account.message.AuthResponse)8 IOException (java.io.IOException)8 ZMailbox (com.zimbra.client.ZMailbox)7 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)6 AccountSelector (com.zimbra.soap.type.AccountSelector)6 HashMap (java.util.HashMap)5 Domain (com.zimbra.cs.account.Domain)4 Server (com.zimbra.cs.account.Server)4