Results 1 to 5 of 5

Thread: [SOLVED] Java with SOAP

  1. #1
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    7

    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

  2. #2
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    7

    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

  3. #3
    Join Date
    Oct 2005
    Location
    USA, Canada and India
    Posts
    777
    Rep Power
    11

    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 Provider

  4. #4
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    7

    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 01:27 PM.

  5. #5
    Join Date
    Oct 2005
    Location
    USA, Canada and India
    Posts
    777
    Rep Power
    11

    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 Provider

Similar Threads

  1. [SOLVED] Get EMAIL details with SOAP in JAVA
    By rkmorgan in forum Developers
    Replies: 5
    Last Post: 10-11-2007, 10:05 AM
  2. [SOLVED] SOAP API from Java
    By liriarte in forum Developers
    Replies: 8
    Last Post: 09-14-2007, 05:24 PM
  3. How to consume zimbra SOAP API in my java application
    By Hemant Shrivastava in forum Developers
    Replies: 34
    Last Post: 12-24-2006, 01:24 AM
  4. Java 1.5 crashing on PPC Mac 10.4.8
    By bradn in forum Installation
    Replies: 1
    Last Post: 12-08-2006, 06:27 PM
  5. Replies: 0
    Last Post: 12-04-2006, 09:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •