use of com.zimbra.soap.mail.message.WaitSetResponse in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testWaitSetRequest.
@Test
public void testWaitSetRequest() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String authToken = mbox.getAuthToken().getValue();
CreateWaitSetRequest req = new CreateWaitSetRequest("all");
WaitSetAddSpec add = new WaitSetAddSpec();
add.setId(mbox.getAccountInfo(false).getId());
req.addAccount(add);
DocumentResult dr = new DocumentResult();
marshaller.marshal(req, dr);
Document doc = dr.getDocument();
ZimbraLog.test.info(doc.getRootElement().asXML());
CreateWaitSetResponse createResp = (CreateWaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "CreateWaitSetRequest");
String waitSetId = createResp.getWaitSetId();
Assert.assertNotNull(waitSetId);
WaitSetRequest waitSet = new com.zimbra.soap.mail.message.WaitSetRequest(waitSetId, "0");
dr = new DocumentResult();
marshaller.marshal(waitSet, dr);
doc = dr.getDocument();
WaitSetResponse wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
Assert.assertEquals("0", wsResp.getSeqNo());
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessageLmtp(subject, USER_NAME, "user999@example.com");
try {
Thread.sleep(500);
} catch (Exception e) {
}
wsResp = (WaitSetResponse) sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
Assert.assertFalse(wsResp.getSeqNo().equals("0"));
}
use of com.zimbra.soap.mail.message.WaitSetResponse in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testSyncWaitSetRequest.
@Test
public void testSyncWaitSetRequest() throws Exception {
String user1Name = "testSyncWaitSetRequest_user1";
acc1 = TestUtil.createAccount(user1Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
String authToken = mbox.getAuthToken().getValue();
CreateWaitSetResponse resp = createWaitSet(mbox.getAccountInfo(false).getId(), authToken);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
int seq = resp.getSequence();
WaitSetRequest waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
WaitSetResponse wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertEquals("0", wsResp.getSeqNo());
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
// try { Thread.sleep(500); } catch (Exception e) {}
TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertFalse(wsResp.getSeqNo().equals("0"));
List<AccountWithModifications> accounts = wsResp.getSignalledAccounts();
assertEquals("should have signaled 1 account", 1, accounts.size());
assertEquals(String.format("Shold have signaled account %s", acc1.getId()), acc1.getId(), accounts.get(0).getId());
assertNull("Should not return folder notifications unless 'expand' is set to 'true'", accounts.get(0).getPendingFolderModifications());
}
use of com.zimbra.soap.mail.message.WaitSetResponse in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testFolderInterestSyncWaitSetRequest.
@Test
public void testFolderInterestSyncWaitSetRequest() throws Exception {
String user1Name = "testFISyncWaitSetRequest_user1";
acc1 = TestUtil.createAccount(user1Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
String acctId = mbox.getAccountId();
String authToken = mbox.getAuthToken().getValue();
ZimbraLog.test.info("GREN 1");
String adminAuthToken = TestUtil.getAdminSoapTransport().getAuthToken().getValue();
ZimbraLog.test.info("GREN 2");
ZFolder myFolder = TestUtil.createFolder(mbox, "funFolder");
Set<Integer> folderInterest = Sets.newHashSet();
folderInterest.add(myFolder.getFolderIdInOwnerMailbox());
/* initially only interested in funFolder */
CreateWaitSetResponse resp = createWaitSet(acctId, authToken, folderInterest);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
int seq = resp.getSequence();
WaitSetRequest waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
WaitSetResponse wsResp = (WaitSetResponse) sendReq(waitSet, authToken, TestUtil.getSoapUrl());
assertEquals("0", wsResp.getSeqNo());
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertTrue(wsResp.getSeqNo().equals("0"));
assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
QueryWaitSetResponse qwsResp;
QueryWaitSetRequest qwsReq = new QueryWaitSetRequest(waitSetId);
qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
/* interested in funFolder AND inbox */
folderInterest.add(Integer.valueOf(Mailbox.ID_FOLDER_INBOX));
waitSet.addUpdateAccount(createWaitSetAddSpec(acctId, folderInterest));
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertTrue(wsResp.getSeqNo().equals("0"));
assertEquals("Number of signalled accounts", 0, wsResp.getSignalledAccounts().size());
qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
subject = NAME_PREFIX + " test wait set request 2";
TestUtil.addMessageLmtp(subject, user1Name, "user999@example.com");
TestUtil.waitForMessages(mbox, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
qwsResp = (QueryWaitSetResponse) sendReq(qwsReq, adminAuthToken, TestUtil.getAdminSoapUrl());
validateQueryWaitSetResponse(qwsResp, acctId, folderInterest, null);
waitSet = new WaitSetRequest(waitSetId, Integer.toString(seq));
waitSet.setExpand(true);
wsResp = (WaitSetResponse) sendReq(envelope(authToken, jaxbToString(waitSet), "urn:zimbra"), TestUtil.getSoapUrl() + "WaitSetRequest");
assertFalse(wsResp.getSeqNo().equals("0"));
assertEquals("Number of signalled accounts", 1, wsResp.getSignalledAccounts().size());
AccountWithModifications acctInfo = wsResp.getSignalledAccounts().get(0);
assertEquals("Signaled account id", mbox.getAccountId(), acctInfo.getId());
Collection<PendingFolderModifications> mods = acctInfo.getPendingFolderModifications();
assertNotNull("'mod' field should not be null", mods);
assertEquals("Should have 1 folder object with modifications", 1, mods.size());
Integer foldInt = mods.iterator().next().getFolderId();
assertEquals(String.format("Folder ID should be %d (Inbox). Getting %d instead", Mailbox.ID_FOLDER_INBOX, foldInt), foldInt.intValue(), Mailbox.ID_FOLDER_INBOX);
}
use of com.zimbra.soap.mail.message.WaitSetResponse in project zm-mailbox by Zimbra.
the class TestWaitSetRequest method testBlockingWaitSetRequest.
@Test
public void testBlockingWaitSetRequest() throws Exception {
ZimbraLog.test.info("Starting testBlockingWaitSetRequest");
String user1Name = "testBlockingWaitSetRequest_user1";
acc1 = TestUtil.createAccount(user1Name);
ZMailbox mbox = TestUtil.getZMailbox(user1Name);
String authToken = mbox.getAuthToken().getValue();
String accId = mbox.getAccountId();
CreateWaitSetResponse resp = createWaitSet(accId, authToken);
assertNotNull(resp);
waitSetId = resp.getWaitSetId();
int seq = resp.getSequence();
assertNotNull(waitSetId);
WaitSetRequest waitSetReq = new WaitSetRequest(waitSetId, Integer.toString(seq));
waitSetReq.setBlock(true);
final CountDownLatch doneSignal = new CountDownLatch(1);
mbox.getTransport().invokeAsync(JaxbUtil.jaxbToElement(waitSetReq), new FutureCallback<HttpResponse>() {
@Override
public void completed(final HttpResponse response) {
cbCalled.set(true);
int respCode = response.getStatusLine().getStatusCode();
success.set((respCode == 200));
if (!success.get()) {
failureMessage = "Response code " + respCode;
}
if (success.get()) {
Element envelope;
try {
envelope = W3cDomUtil.parseXML(response.getEntity().getContent());
SoapProtocol proto = SoapProtocol.determineProtocol(envelope);
Element doc = proto.getBodyElement(envelope);
ZimbraLog.test.info(new String(doc.toUTF8(), "UTF-8"));
WaitSetResponse wsResp = (WaitSetResponse) JaxbUtil.elementToJaxb(doc);
success.set((Integer.parseInt(wsResp.getSeqNo()) > 0));
if (!success.get()) {
failureMessage = "wrong squence number. Sequence #" + wsResp.getSeqNo();
}
if (success.get()) {
success.set((wsResp.getSignalledAccounts().size() == 1));
if (!success.get()) {
failureMessage = "wrong number of signaled accounts " + wsResp.getSignalledAccounts().size();
}
}
if (success.get()) {
success.set(wsResp.getSignalledAccounts().get(0).getId().equalsIgnoreCase(accId));
if (!success.get()) {
failureMessage = "signaled wrong account " + wsResp.getSignalledAccounts().get(0).getId();
}
}
} catch (UnsupportedOperationException | IOException | ServiceException e) {
fail(e.getMessage());
}
try {
Thread.sleep(100);
} catch (Exception e) {
}
}
doneSignal.countDown();
}
@Override
public void failed(final Exception ex) {
ZimbraLog.test.error("request :: failed ", ex);
success.set(false);
failureMessage = ex.getMessage();
doneSignal.countDown();
}
@Override
public void cancelled() {
ZimbraLog.test.info("request :: cancelled");
success.set(false);
failureMessage = "request :: cancelled";
doneSignal.countDown();
}
});
String subject = NAME_PREFIX + " test wait set request 1";
TestUtil.addMessage(mbox, subject);
try {
doneSignal.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted. ");
}
assertTrue("callback was not triggered.", cbCalled.get());
assertTrue(failureMessage, success.get());
}
use of com.zimbra.soap.mail.message.WaitSetResponse in project zm-mailbox by Zimbra.
the class WaitSetRequest method handle.
/*
<!--*************************************
WaitMultipleAccounts: optionally modifies the wait set and checks
for any notifications. If block=1 and there are no notificatins, then
this API will BLOCK until there is data.
Client should always set 'seq' to be the highest known value it has
received from the server. The server will use this information to
retransmit lost data.
If the client sends a last known sync token then the notification is
calculated by comparing the accounts current token with the client's
last known.
If the client does not send a last known sync token, then notification
is based on change since last Wait (or change since <add> if this
is the first time Wait has been called with the account)
************************************* -->
<WaitMultipleAccountsRequest waitSet="setId" seq="highestSeqKnown" [block="1"]>
[ <add>
[<a id="ACCTID" [token="lastKnownSyncToken"] [types="a,c..."]/>]+
</add> ]
[ <update>
[<a id="ACCTID" [token="lastKnownSyncToken"] [types=]/>]+
</update> ]
[ <remove>
[<a id="ACCTID"/>]+
</remove> ]
</WaitMultipleAccountsRequest>
<WaitMultipleAccountsResponse waitSet="setId" seq="seqNo" [canceled="1"]>
[ <n id="ACCTID"/>]*
[ <error ...something.../>]*
</WaitMultipleAccountsResponse>
*/
/* (non-Javadoc)
* @see com.zimbra.soap.DocumentHandler#handle(com.zimbra.common.soap.Element, java.util.Map)
*/
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
com.zimbra.soap.mail.message.WaitSetRequest req = zsc.elementToJaxb(request);
boolean adminAllowed = zsc.getAuthToken().isAdmin();
WaitSetResponse resp = new WaitSetResponse();
staticHandle(req, context, resp, adminAllowed);
return zsc.jaxbToElement(resp);
/* MUST use zsc variant NOT JaxbUtil */
}
Aggregations