Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
  #1 (permalink)  
Old 05-01-2008, 12:20 PM
tsx tsx is offline
Member
 
Join Date: Apr 2008
Posts: 11
tsx is on a distinguished road
Default [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
Reply With Quote
  #2 (permalink)  
Old 05-02-2008, 07:39 AM
tsx tsx is offline
Member
 
Join Date: Apr 2008
Posts: 11
tsx is on a distinguished road
Default

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
Reply With Quote
  #3 (permalink)  
Old 05-03-2008, 10:44 PM
raj's Avatar
raj raj is offline
Special Member
 
Join Date: Oct 2005
Location: US, Canada and India
ZCS Version: zcs-5.0.1_GA_1902.RHEL5.20080109200629.tgz , CentOS 5.1
Posts: 158
raj is on a distinguished road
Default

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
__________________
i2k2 Networks
Dedicated & Shared Zimbra Hosting Experts
Reply With Quote
  #4 (permalink)  
Old 05-05-2008, 08:12 AM
tsx tsx is offline
Member
 
Join Date: Apr 2008
Posts: 11
tsx is on a distinguished road
Default

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

Last edited by tsx : 05-05-2008 at 12:27 PM.
Reply With Quote
  #5 (permalink)  
Old 05-05-2008, 08:30 PM
raj's Avatar
raj raj is offline
Special Member
 
Join Date: Oct 2005
Location: US, Canada and India
ZCS Version: zcs-5.0.1_GA_1902.RHEL5.20080109200629.tgz , CentOS 5.1
Posts: 158
raj is on a distinguished road
Default

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
__________________
i2k2 Networks
Dedicated & Shared Zimbra Hosting Experts
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Get EMAIL details with SOAP in JAVA rkmorgan Developers 5 10-11-2007 09:05 AM
[SOLVED] SOAP API from Java liriarte Developers 8 09-14-2007 04:24 PM
How to consume zimbra SOAP API in my java application Hemant Shrivastava Developers 34 12-24-2006 12:24 AM
Java 1.5 crashing on PPC Mac 10.4.8 bradn Installation 1 12-08-2006 05:27 PM
like to consume zimbra SOAP API in my java application ( 1 2 3) xyqqq Developers 0 12-04-2006 08:48 PM


freshmeat.net sourceforge.net The best Java IDE



 

Search Engine Optimization by vBSEO 3.0.0