-
[SOLVED] Java with SOAP
Hello,
I'm trying to gain access to all the messages/conversations on a Zimbra server. I've got access to an admin account and I'm using a combination of SoapProvivisioning and SoapHttpTransport. Here is what I've got so far
Code:
public class ZimbraTest {
public static void main(String[] args) {
try {
SoapProvisioning sp = new SoapProvisioning();
sp.soapSetURI("https://192.168.0.165:7071"
+ ZimbraServlet.ADMIN_SERVICE_URI);
sp.soapAdminAuthenticate("admin", "baseball");
List<Domain> domains = sp.getAllDomains();
for (Domain domain : domains) {
System.out.println(domain.getName());
List<Account> accounts = sp.getAllAccounts(domain);
for (Account account : accounts) {
System.out.println("\t" + account.getName());
// This throws ZClientException
// MailboxInfo mailboxInfo = sp.getMailbox(account);
// System.out.println("\t\t" + mailboxInfo.getMailboxId());
//This works
SoapHttpTransport soapHttpTransport = new SoapHttpTransport(
sp.soapGetURI());
soapHttpTransport.setAuthToken(sp.getAuthToken());
XMLElement req = new XMLElement(
AdminService.GET_MAILBOX_REQUEST);
Element mBox = req.addElement(AdminService.E_MAILBOX);
mBox
.addAttribute(AdminService.A_ACCOUNTID, account
.getId());
System.out.println(req.prettyPrint());
Element tagsResponse = soapHttpTransport.invoke(req);
System.out.println(tagsResponse.prettyPrint());
}
}
} catch (SoapFaultException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
My questions.
1. Is it all right to use SoapProvisioning or should I be using SoapHttpTransport only?
2. What should I do after I have the account id? Is there a request to get all messages for an account?
Also, is there a way to turn off debug messages on SoapProvisioning?
Any help would be appreciated.
Thanks in advance,
-t
-
No reply :(
Here's how I'm approaching it.
1. Authenticate as admin account - Done
2. Get all domains - Done
3. Get all accounts in a domain - Done
4. Authenticate as one of the account - How?
5. Get all mails - Tested
Do you think this is the right approach? If it is, any suggestions on how to authenticate as another user. I'm looking at pre-auth to do that. Initially I was getting pre-auth disabled on server but after following steps on the wiki I'm now getting authentication failed.
It appears the authentication token generated by "computePreAuth" is not working (just looking at it, it seems too small compared to one generated when you click "View mail" from admin interface).
Any suggestions?
-t
-
for step 4) to get deligated auth to for a user you need to use
*************************
SOAP API - DelegateAuthRequest
ADMIN_TOKEN - you have
USER_ID - you have
*************************
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>
<context xmlns="urn:zimbra">
<authToken>ADMIN_TOKEN</authToken>
</context>
</soap:Header>
<soap:Body>
<DelegateAuthRequest xmlns="urn:zimbraAdmin" duration="600">
<account xmlns=" by="id">USER_ID</account>
</DelegateAuthRequest>
</soap:Body>
</soap:Envelope>
this will give you user "authToken" which you will use in user soap api's
Raj
-
Thanks Raj, I got it working using pre authentication. The pre auth token was erroneous because of time difference on my local machine and the server. Talk about things you overlook :)
Your solution is definitely the right way to go. It's much more simpler. It's working using DelegateAuthRequest.
I do have one more question, is SoapProvisioning the right approach?
-t
-
using SOAP API should be the only approach to integrate anything in ZIMBRA as it transparent to version changes and 99.99% your stuff will not break due to ZIMBRA upgrades. API's tend to be greatly backward compatible
Raj