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());
}
}
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());
}
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());
}
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());
}
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);
}
Aggregations