Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-16-2008, 09:51 AM
Special Member
 
Posts: 100
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
Reply With Quote
  #2 (permalink)  
Old 01-29-2008, 10:47 AM
Zimbra Employee
 
Posts: 1,434
Default

Authenticate as the admin. You'll also probably want to use ZMailbox.java instead...
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #3 (permalink)  
Old 01-29-2008, 01:09 PM
Special Member
 
Posts: 100
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
Reply With Quote
  #4 (permalink)  
Old 01-29-2008, 01:43 PM
Zimbra Employee
 
Posts: 1,434
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!
Reply With Quote
  #5 (permalink)  
Old 01-29-2008, 02:46 PM
Special Member
 
Posts: 100
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.
Reply With Quote
  #6 (permalink)  
Old 01-29-2008, 03:18 PM
Zimbra Employee
 
Posts: 1,434
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!
Reply With Quote
  #7 (permalink)  
Old 09-02-2008, 12:14 AM
Loyal Member
 
Posts: 91
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
Reply With Quote
  #8 (permalink)  
Old 09-02-2008, 09:56 AM
Zimbra Employee
 
Posts: 1,434
Default

Use SoapProvisioning and ZMailbox instead of crafting the requests/responses yourself and using SoapHttpTransport.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #9 (permalink)  
Old 09-03-2008, 07:24 AM
Loyal Member
 
Posts: 91
Default

Please refer here
Test Delete Zimbra account coding

I got use the SoapProvisioning and Zmailbox....

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

Thank
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.