use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.
the class ImapServerListener method initWaitSet.
private synchronized void initWaitSet(String accountId, boolean alreadyListening) throws ServiceException {
if (wsID == null && this.sessionMap.containsKey(accountId)) {
AdminCreateWaitSetRequest req = new AdminCreateWaitSetRequest("all", false);
checkAuth();
AdminCreateWaitSetResponse resp;
resp = soapProv.invokeJaxbAsAdminWithRetry(req, server);
if (resp == null) {
throw ServiceException.FAILURE("Received null response from AdminCreateWaitSetRequest", null);
}
wsID = resp.getWaitSetId();
setWaitSetIdOnMailboxes();
lastSequence.set(resp.getSequence());
} else {
cancelPendingRequest();
}
ZimbraLog.imap.debug("Current waitset ID is %s", wsID);
// send non-blocking synchronous WaitSetRequest. This way the caller has certainty that listener was added on remote server
AdminWaitSetRequest waitSetReq = new AdminWaitSetRequest(wsID, lastSequence.toString());
waitSetReq.setBlock(false);
waitSetReq.setExpand(true);
if (!this.sessionMap.containsKey(accountId) || this.sessionMap.get(accountId).isEmpty()) {
ZimbraLog.imap.debug("Removing accout %s from waitset %s", accountId, wsID);
waitSetReq.addRemoveAccount(new Id(accountId));
} else {
WaitSetAddSpec updateOrAdd = new WaitSetAddSpec();
updateOrAdd.setId(accountId);
Enumeration<Integer> folderIDs = this.sessionMap.get(accountId).keys();
while (folderIDs.hasMoreElements()) {
updateOrAdd.addFolderInterest(folderIDs.nextElement());
}
if (alreadyListening) {
ZimbraLog.imap.debug("Updating folder interests for account %s in waitset %s", accountId, wsID);
waitSetReq.addUpdateAccount(updateOrAdd);
} else {
ZimbraLog.imap.debug("Adding account %s to waitset %s", accountId, wsID);
waitSetReq.addAddAccount(updateOrAdd);
}
}
try {
ZimbraLog.imap.debug("Sending initial AdminWaitSetRequest. WaitSet ID: %s", wsID);
AdminWaitSetResponse wsResp = soapProv.invokeJaxbAsAdminWithRetry(waitSetReq, server);
processAdminWaitSetResponse(wsResp);
} catch (SoapFaultException e) {
if (AdminServiceException.NO_SUCH_WAITSET.equalsIgnoreCase(e.getCode())) {
// waitset is gone. Create a new one
ZimbraLog.imap.warn("AdminWaitSet %s does not exist anymore", wsID);
wsID = null;
unsetWaitSetIdOnMailboxes();
lastSequence.set(0);
restoreWaitSet();
} else {
throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
}
} catch (Exception e) {
throw ServiceException.FAILURE("Failed to process initial AdminWaitSetResponse", e);
}
}
use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.
the class ZMailbox method populateTagCache.
private void populateTagCache() throws ServiceException {
if (mNameToTag != null) {
return;
}
if (mNotifyPreference == null || mNotifyPreference == SessionPreference.full) {
noOp();
if (mNameToTag != null) {
return;
}
}
List<ZTag> tagList = new ArrayList<ZTag>();
if (!mNoTagCache) {
try {
Element response = invoke(newRequestElement(MailConstants.GET_TAG_REQUEST));
for (Element t : response.listElements(MailConstants.E_TAG)) {
tagList.add(new ZTag(t, this));
}
} catch (SoapFaultException sfe) {
if (!sfe.getCode().equals(ServiceException.PERM_DENIED)) {
throw sfe;
}
}
}
ZRefreshEvent event = new ZRefreshEvent(mSize, null, tagList);
for (ZEventHandler handler : mHandlers) {
handler.handleRefresh(event, this);
}
}
use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.
the class Tester method main.
public static void main(String[] argv) {
CliUtil.toolSetup();
if (argv.length != 3) {
System.out.println("Usage: Tester <serverURL> <username> <password>");
System.out.println("where:");
System.out.println("<serverURL> is the full URL to the SOAP service");
System.out.println("<username> is the name of the user to log in as");
System.out.println("<password> is that user's password");
System.out.println("NOTE: THIS COMMAND WILL DELETE E-MAIL!!!");
}
String serverURL = argv[0];
System.out.println("connecting to " + serverURL + " as " + argv[1] + " with password " + argv[2]);
try {
/* do a ping */
LmcPingRequest pr = new LmcPingRequest();
LmcPingResponse pResp = (LmcPingResponse) pr.invoke(serverURL);
/* auth first */
System.out.println("========= AUTHENTICATE ===========");
LmcAuthRequest auth = new LmcAuthRequest();
auth.setUsername(argv[1]);
auth.setPassword(argv[2]);
LmcAuthResponse authResp = (LmcAuthResponse) auth.invoke(serverURL);
LmcSession session = authResp.getSession();
/* get some prefs -- this is not part of the login sequence now */
doGetDumpPrefs(session, serverURL);
/* get the tags */
System.out.println("======== GET TAGS =======");
LmcGetTagRequest gtReq = new LmcGetTagRequest();
gtReq.setSession(session);
LmcGetTagResponse gtResp = (LmcGetTagResponse) gtReq.invoke(serverURL);
/* dump the tags */
System.out.println("==== DUMP TAGS ======");
LmcTag[] tags = gtResp.getTags();
for (int t = 0; tags != null && t < tags.length; t++) System.out.println(tags[t]);
/* get the folders */
System.out.println("==== GET FOLDERS ======");
LmcGetFolderRequest gfReq = new LmcGetFolderRequest();
gfReq.setSession(session);
LmcGetFolderResponse gfResp = (LmcGetFolderResponse) gfReq.invoke(serverURL);
/* dump the folders */
System.out.println("====== DUMP FOLDERS ======");
LmcFolder folder = gfResp.getRootFolder();
recursiveDumpFolder(folder, 0);
/* inbox listing */
System.out.println("==== SEARCH in:inbox ======");
LmcSearchRequest sReq = new LmcSearchRequest();
sReq.setOffset("0");
sReq.setLimit("30");
sReq.setQuery("in:inbox");
sReq.setSession(session);
sReq.setTypes(MailItem.Type.CONVERSATION.toString());
LmcSearchResponse sResp = (LmcSearchResponse) sReq.invoke(serverURL);
/* dump the search */
System.out.println("====== DUMP SEARCH ======");
System.out.println("offset=\"" + sResp.getOffset() + "\" more=\"" + sResp.getMore() + "\"");
LmcConversation conv = null;
LmcConversation firstConv = null;
List cList = sResp.getResults();
for (Iterator cit = cList.iterator(); cit.hasNext(); ) {
conv = (LmcConversation) cit.next();
if (firstConv == null)
firstConv = conv;
System.out.println(conv);
}
/**
*** at this point the emulation of a login is complete ****
*/
/**
*** the following code emulates the first conv retrieval ****
*/
getAndDumpContacts(session, serverURL);
/* get the first conversation from the search */
System.out.println("===== GET CONVERSATION =====");
LmcGetConvRequest gconvReq = new LmcGetConvRequest();
gconvReq.setConvToGet(firstConv.getID());
gconvReq.setSession(session);
/*
* the client gets message detail in the getConvRequest and then
* fetches the msg with GetMsgReq anyway. so that's repeated here.
*/
String[] msgDetail = new String[] { firstConv.getMessages()[0].getID() };
gconvReq.setMsgsToGet(msgDetail);
LmcGetConvResponse gconvResp = (LmcGetConvResponse) gconvReq.invoke(serverURL);
/* dump the conversation response */
System.out.println("===== DUMP CONVERSATION ===== ");
System.out.println(gconvResp.getConv());
/* get the message in that conversation */
System.out.println("===== GET MESSAGE ===== ");
LmcGetMsgRequest gmReq = new LmcGetMsgRequest();
gmReq.setRead("1");
gmReq.setMsgToGet(msgDetail[0]);
gmReq.setSession(session);
LmcGetMsgResponse gmResp = (LmcGetMsgResponse) gmReq.invoke(serverURL);
/* dump the message in that conversation */
System.out.println("===== DUMP MESSAGE ===== ");
System.out.println(gmResp.getMsg());
/**
** that completes emulation of viewing a conv and its first message ***
*/
/* send a new message */
System.out.println("===== SEND MESSAGE ===== ");
LmcMessage lMsg = new LmcMessage();
lMsg.setEmailAddresses(new LmcEmailAddress[] { gEa });
lMsg.setSubject("msg from the test program");
LmcMimePart smrMp = new LmcMimePart();
smrMp.setContentType("text/plain");
smrMp.setContent("there is some fresh coffee somewhere");
lMsg.addMimePart(smrMp);
LmcSendMsgRequest smr = new LmcSendMsgRequest();
smr.setMsg(lMsg);
smr.setSession(session);
// add an attachment. XXX hardcoded stuff...
String aid = smr.postAttachment("http://dogfood.example.zimbra.com/service/upload", session, new File("c:/temp/ops.txt"), ".example.zimbra.com", 5000);
System.out.println("got back attachment id " + aid);
lMsg.setAttachmentIDs(new String[] { aid });
LmcSendMsgResponse smrResp = (LmcSendMsgResponse) smr.invoke(serverURL);
/* print result of sending new message */
System.out.println("==== DUMP SEND MSG RESPONSE ====");
System.out.println("Send successful, resulting ID " + smrResp.getID());
doSearchReadDelete(session, serverURL);
doSearchAndConvAction(session, serverURL);
doCreateDeleteFolder(session, serverURL);
// will also dump contacts
doCreateDeleteContact(session, serverURL);
doCreateDeleteTag(session, serverURL);
doModifyDumpPrefs(session, serverURL);
doCreateGetDeleteNote(session, serverURL);
doChangePassword(session, argv[1], argv[2], serverURL);
doGetInfo(session, serverURL);
// will not match
doSearchGal(session, serverURL, "Kevin");
// will match
doSearchGal(session, serverURL, "Satish");
doSearchConv(session, serverURL);
doBrowse(session, serverURL);
doAddMsg(session, serverURL);
} catch (SoapFaultException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LmcSoapClientException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.
the class TestDeployZimlet method testZipWithInvalidCharacter.
@Test
public void testZipWithInvalidCharacter() throws Exception {
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
authReq.setCsrfSupported(false);
Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
String authToken = authResp.getAuthToken();
String aid = adminUpload(authToken, "jelmer.zip", "/opt/zimbra/unittest/zimlets/jelmer.zip");
assertNotNull("Attachment ID should not be null", aid);
AttachmentIdAttrib att = new AttachmentIdAttrib(aid);
transport.setAdmin(true);
transport.setAuthToken(authToken);
DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, att);
Element req = JaxbUtil.jaxbToElement(deployReq);
try {
Element res = transport.invoke(req);
JaxbUtil.elementToJaxb(res);
fail("Should throw SoapFaultException");
} catch (SoapFaultException e) {
// expected
}
}
use of com.zimbra.common.soap.SoapFaultException in project zm-mailbox by Zimbra.
the class TestDeployZimlet method testBadAid.
@Test
public void testBadAid() throws Exception {
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
authReq.setCsrfSupported(false);
Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
String authToken = authResp.getAuthToken();
AttachmentIdAttrib att = new AttachmentIdAttrib("invalidaid");
transport.setAdmin(true);
transport.setAuthToken(authToken);
DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, att);
Element req = JaxbUtil.jaxbToElement(deployReq);
try {
Element res = transport.invoke(req);
JaxbUtil.elementToJaxb(res);
fail("Should throw SoapFaultException");
} catch (SoapFaultException e) {
// expected
}
}
Aggregations