Results 1 to 9 of 9

Thread: Zimbra SOAP Access from Java

  1. #1
    Join Date
    Oct 2006
    Posts
    100
    Rep Power
    9

    Question Zimbra SOAP Access from Java

    Hey everyone,

    I am writing a CRM like application in Java. Looking around I got started using com.zimbra.common.util.CliUtil . I can now get contacts for a single user and things of that nature; however, I want to be able to login as user with administrator permissions and be able to view and modify everyone contacts, appointments etc. Right now I have to log in as each user. Am I using the wrong classes? What should I be using?

    Here is a little bit of code to give you an idea of what I am doing:

    Code:
        public ZimbraInterface(String accessName, String accessPassword, String accessURL)
        {
            this.accessName = accessName;
            this.accessPass = accessPassword;
            this.accessURL = accessURL;
            CliUtil.toolSetup();
        }
    
        private LmcSession getSession() throws Exception
        {
            if(System.currentTimeMillis() - sessionLastAccessed > SESSION_TIMEOUT || session == null)
            {    
                LmcAuthRequest authRequest = new LmcAuthRequest();
                authRequest.setUsername(accessName);
                authRequest.setPassword(accessPass);
                LmcAuthResponse authResponse;
                authResponse = (LmcAuthResponse)authRequest.invoke(accessURL);
                session = authResponse.getSession();
                sessionLastAccessed = System.currentTimeMillis();
            }
            return session;
        }
        private ZmContact[] getContacts() throws Exception
        {        
            LmcGetContactsRequest contactsRequest = new LmcGetContactsRequest();
            contactsRequest.setSession(getSession());
            LmcGetContactsResponse contactsResponse = (LmcGetContactsResponse)contactsRequest.invoke(accessURL);
            LmcContact zmContacts[] = contactsResponse.getContacts();
            ZmContact[] result = new ZmContact[zmContacts.length];
            for(int i = 0; i < zmContacts.length; i++)
                result[i] = new ZmContact( zmContacts[i].getAttrs(), zmContacts[i].getID());            
            return result;
        }
    etc etc

  2. #2
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    Authenticate as the admin. You'll also probably want to use ZMailbox.java instead...
    Bugzilla - Wiki - Downloads - Before posting... Search!

  3. #3
    Join Date
    Oct 2006
    Posts
    100
    Rep Power
    9

    Cool Thanks for the advice

    Thanks for the advice- do you know of any good examples of ZMailbox being used? I primarily need to be able to add, remove and update contacts and appointments. I'm going to keep looking but I am not finding much for documentation. Thanks

  4. #4
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    Well, the HTML ("lite") client is done using a taglib, and that taglib uses ZMailbox extensively, I believe. It's under ZimbraTagLib/src/java/com/zimbra/cs/taglib.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  5. #5
    Join Date
    Oct 2006
    Posts
    100
    Rep Power
    9

    Default Getting closer

    Thanks for the tip. I started looking at ZMailbox and related classes and I found this: ZClient - Zimbra :: Wiki
    It looked promising, but the code doesn't appear to work anymore. Is that right, perhaps that wiki has not been updated to 5.0? AccountService doesn't seem to have the required constants anymore.

  6. #6
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    Actually, that explains the "hard way" to do it -- without zclient (aka ZMailbox.java).

    ZMailboxUtil.java is the source for the zmailbox command. It also uses ZMailbox.java extensively.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  7. #7
    Join Date
    Jul 2008
    Posts
    91
    Rep Power
    7

    Default

    I already installed zcs-5.0.7_GA_2450.UBUNTU8.FRANKLIN.
    Now I can happily try the ZClient

    I a bit confuse is this tutorial still works/valid?

    ZClient - Zimbra :: Wiki

    I using the ZimbraStore.jar file as inside the zcs-5.0.7_GA_2450.UBUNTU8.FRANKLIN.

    I use NetBean to run... Before I want to run the code, Some warning line came out... Which some static variable not declare in the AccountService class such as AccountService.E_ACCOUNT, ...

    Code:
    import java.io.IOException;
    import com.zimbra.common.service.ServiceException;
    import com.zimbra.common.soap.Element;
    import com.zimbra.common.soap.SoapHttpTransport;
    import com.zimbra.cs.service.mail.MailService;
    import com.zimbra.cs.service.account.AccountService;
    import com.zimbra.cs.servlet.ZimbraServlet;
    import com.zimbra.cs.util.Zimbra;
    import com.zimbra.soap.ZimbraSoapContext;
    
    public class TestZClient {
        public static void main(String [] args)
        {
            SoapHttpTransport trans = null;
            try {
                String URI = "https://3.244.4.16/zimbraAdmin/server/soap/iirc";
                trans = new SoapHttpTransport( URI);
            
                Element request = Element.XMLElement.mFactory.createElement(AccountService.AUTH_REQUEST);
                
                request.addAttribute(AccountService.E_ACCOUNT, "userdoesntexist@technicaldetails.org", Element.DISP_CONTENT);
                request.addAttribute(AccountService.E_PASSWORD, "notapassword", Element.DISP_CONTENT);
                Element response = trans.invoke(request);
                
                  // get the auth token out, no default, must be present or a service exception is thrown
                String authToken = response.getAttribute(AccountService.E_AUTH_TOKEN);
                // get the session id, if not present, default to null
                String sessionId = response.getAttribute(ZimbraSoapContext.E_SESSION_ID, null);
                
                 // set the auth token and session id in the transport for future requests to use
                trans.setAuthToken(authToken);
               if (sessionId != null)
                    trans.setSessionId(sessionId);
    
                Element tagsRequest = Element.XMLElement.mFactory.createElement(MailService.GET_TAG_REQUEST);
                Element tagsResponse = trans.invoke(tagsRequest);
                System.out.println(tagsResponse.prettyPrint());
             }
             catch (Exception e){
                e.printStackTrace();
            } 
        }
    }
    May I know the tutorial still valid or not?
    If not valid anymore can you direct me to the valid Zimbra SOAP tutorial....?

    Thank you

    -fsloke

  8. #8
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    Default

    Use SoapProvisioning and ZMailbox instead of crafting the requests/responses yourself and using SoapHttpTransport.
    Bugzilla - Wiki - Downloads - Before posting... Search!

  9. #9
    Join Date
    Jul 2008
    Posts
    91
    Rep Power
    7

    Default

    Please refer here
    http://www.zimbra.com/forums/develop...nt-coding.html

    I got use the SoapProvisioning and Zmailbox....

    but also didn't run it well....

    Thank

Similar Threads

  1. Big Fubar on 5 FOSS GA Upgrade
    By uxbod in forum Administrators
    Replies: 24
    Last Post: 01-21-2008, 03:37 AM
  2. Replies: 8
    Last Post: 02-27-2007, 04:10 AM
  3. Replies: 16
    Last Post: 09-07-2006, 07:39 AM
  4. Unable to start tomcat
    By chanck in forum Administrators
    Replies: 11
    Last Post: 06-11-2006, 01:58 AM
  5. Mail logs
    By Rick Baker in forum Installation
    Replies: 8
    Last Post: 01-17-2006, 04:33 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
  •