Search in sources :

Example 41 with SoapHttpTransport

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

the class ZMailbox method setSoapURI.

/**
     * @param uri URI of server we want to talk to
     * @param timeout timeout for HTTP connection or 0 for no timeout
     * @param retryCount max number of times to retry the call on connection failure
     */
private void setSoapURI(Options options) {
    if (mTransport != null) {
        mTransport.shutdown();
    }
    mTransport = new SoapHttpTransport(options.getUri());
    if (options.getUserAgentName() == null) {
        mTransport.setUserAgent("zclient", SystemUtil.getProductVersion());
    } else {
        mTransport.setUserAgent(options.getUserAgentName(), options.getUserAgentVersion());
    }
    mTransport.setMaxNotifySeq(0);
    mTransport.setClientIp(mClientIp);
    if (options.getTimeout() > -1) {
        mTransport.setTimeout(options.getTimeout());
    }
    if (options.getRetryCount() != -1) {
        mTransport.setRetryCount(options.getRetryCount());
    }
    if (mAuthToken != null) {
        mTransport.setAuthToken(mAuthToken);
    }
    if (mCsrfToken != null) {
        mTransport.setCsrfToken(mCsrfToken);
    }
    for (Map.Entry<String, String> entry : options.getCustomHeaders().entrySet()) {
        mTransport.getCustomHeaders().put(entry.getKey(), entry.getValue());
    }
}
Also used : SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 42 with SoapHttpTransport

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

the class TestAuthentication method testSimpleAuth.

/**
     * test detault auth request with login/password
     * @throws Exception
     */
public void testSimpleAuth() throws Exception {
    //regular auth request
    Account a = TestUtil.getAccount(USER_NAME);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, a.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    String newAuthToken = authResp.getAuthToken();
    assertNotNull("should have received a new authtoken", newAuthToken);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    assertTrue("new auth token should be registered", at.isRegistered());
    assertFalse("new auth token should not be expired yet", at.isExpired());
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse)

Example 43 with SoapHttpTransport

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

the class TestAuthentication method testAdminAuthViaCookie.

/**
     * test admin auth request with authtoken cookie instead of login/password
     * @throws Exception
     */
public void testAdminAuthViaCookie() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    com.zimbra.soap.admin.message.AuthRequest req = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    String newAuthToken = authResp.getAuthToken();
    assertNotNull("should have received a new authtoken", newAuthToken);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    assertTrue("new auth token should be registered", at.isRegistered());
    assertFalse("new auth token should not be expired yet", at.isExpired());
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) Element(com.zimbra.common.soap.Element) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 44 with SoapHttpTransport

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

the class TestAuthentication method testAdminAuth.

/**
     * test detault admin auth request with login/password
     * @throws Exception
     */
public void testAdminAuth() throws Exception {
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
    com.zimbra.soap.admin.message.AuthRequest req = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    String newAuthToken = authResp.getAuthToken();
    assertNotNull("should have received a new authtoken", newAuthToken);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    assertTrue("new auth token should be registered", at.isRegistered());
    assertFalse("new auth token should not be expired yet", at.isExpired());
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) Element(com.zimbra.common.soap.Element) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 45 with SoapHttpTransport

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

the class TestSendAndReceive method testSendDraftWithCustomDataNoSave.

@Test
public void testSendDraftWithCustomDataNoSave() 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.SAVE_DRAFT_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);
    ZMessage draft = new ZMessage(transport.invoke(request).getElement(MailConstants.E_MSG), zmbox);
    //send the draft but don't save to Sent folder
    request = new Element.JSONElement(MailConstants.SEND_MSG_REQUEST);
    request.addUniqueElement(MailConstants.E_MSG).addAttribute(MailConstants.A_DRAFT_ID, Integer.parseInt(draft.getId())).addAttribute(MailConstants.A_SEND_FROM_DRAFT, true).addAttribute(MailConstants.A_NO_SAVE_TO_SENT, true);
    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(String.format("wrong value in custom header: %s", listenersData[0]), customHeaderValue.equalsIgnoreCase(listenersData[0].replace("\"", "")));
    Assert.assertNotNull("Listener did not get data from custom headers", listenersData);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

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