Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Zimbra Calendar integration in third party application

  1. #1
    marinew is offline Senior Member
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    7

    Default Zimbra Calendar integration in third party application

    Hello,

    I have to develop a J2EE software that will use Zimbra as Calendar.
    At this time, I am studying Web Services possibilities.

    Is there a Web Services API or documentation ? I found very useful documentations about Zimlets, but I didn't find anything describing available Web Services.

    I found some interesting classes on SNV repository (SourceForge.net Repository - [zimbra] Index of /trunk/ZimbraServer/src/java/com/zimbra/cs/client/soap)
    and succeeded calling a WebService to get contacts list from Zimbra, but I don't see any WebServices related to calendar, such as find events, create, modify and delete events.

    Thanks for help.

  2. #2
    marinew is offline Senior Member
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    7

    Default Web Services documentation

    I finally found Web Services documentation and Java code sample with Calendar related Web services that I was looking for, in this post :
    - Documentation : ZimbraServer sources > docs/soap*.txt
    - Sample code : ZimbraServer sources > src/java/com.zimbra.cs.zclient.ZMailboxUtil.java
    Last edited by marinew; 08-29-2007 at 03:32 AM.

  3. #3
    marinew is offline Senior Member
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    7

    Default Java SOAP Access : client / zclient / manual method ?

    Hello,


    I know this subject has already been discussed many times, but it is not clear for me after reading many posts.
    I have to search, create, modify appointment from a Java application, through Zimbra SOAP interface.

    Which "clean" method should I use ?

    - Call com.zimbra.zc.client.* classes methods ?
    => In that case, I don't see any class to manage appointments. Are there some ? It seems all objects may be managed through this package, except appointments !

    - Call com.zimbra.zc.zclient.* classes methods ?
    => What is the difference between these 2 packages "client" and "zclient" ?

    - Are these packages usable in the state ? Or should I write my own classes by manually constructing XML messages and decrypting XML responses ?

    Thanks for any help
    (Precision : I have only few aknowledgment with Zimbra and SOAP).


    [edit]
    Another question : Can I use latest Java client classes downloaded from Subversion, in order to manage appointments from a 4.5.6 Zimbra server ? Will it be compatible ?
    [/edit]
    Last edited by marinew; 10-10-2007 at 12:09 PM.

  4. #4
    nbobfin is offline New Member
    Join Date
    Jun 2008
    Location
    Paris
    Posts
    4
    Rep Power
    7

    Default

    Hi

    I also have to develop a J2EE software that will use Zimbra as Calendar and I come to the same questions.

    Have you succeeded to interact with zimbra's calendar ?
    Or can somebody answer to marinew's questions ?

    Thanks

  5. #5
    marinew is offline Senior Member
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    7

    Default

    Hi nbobfin,

    Yes, I succeeded calling Zimbra webServices. I d'ont know whether it's the best way or not, but here is an example :

    Code:
            String serverUrl = "http://zimbraServer" + ZimbraServlet.USER_SERVICE_URI;
            LmcSession session;
            
            LmcAuthRequest auth = new LmcAuthRequest();
            auth.setUsername(username);
            auth.setPassword(password);
            
            LmcAuthResponse authResp = null;
            
            try {
                authResp = (LmcAuthResponse) auth.invoke(serverURL);
            } catch (Exception e) {
                (...)
            }
            
            session = authResp.getSession();
    
            LmcFolderActionRequest req = new LmcFolderActionRequest();
            req.setSession(session);
            req.setFolderList(listeIdFolders);
            req.setOp(MailConstants.E_GRANT);
            req.setGrant(droits, typeAccedant, nomAccedant);
            
            try {
                
                req.invoke(serverUrl);
                
            } catch (Exception e) {
                (...)
            }
    You have to include zimbracommon.jar and zimbrastore.jar

    Look into these libraries, you will find LmcFolderActionRequest class, and other classes you can use.
    If there is no LmcXxxxRequest class for the service you want to invoke (LmcApptSummariesRequest, for example), you will have to write it on your own.
    For this, you will have to look at the soap*.txt doc (found in Zimbra sources).

    Here is an example of ApptSummariesRequest I wrote :
    Code:
    public class ApptSummariesRequest extends LmcSoapRequest {
    
    	private final static Log log = LogFactory.getLog(ApptSummariesRequest.class);
    
    	String idFolder;
    	Date debutRecherche;
    	Date finRecherche;
    
    	protected Element getRequestXML() {
    		
    		Element request = DocumentHelper.createElement(MailConstants.GET_APPT_SUMMARIES_REQUEST);
    		
    		// add all the attributes of the SearchRequest element
    		addAttrNotNull(request, com.zimbra.common.soap.MailConstants.A_CAL_START_TIME, ZimbraUtils.getFormatDateTimeMSec(debutRecherche));
    		addAttrNotNull(request, com.zimbra.common.soap.MailConstants.A_CAL_END_TIME, ZimbraUtils.getFormatDateTimeMSec(finRecherche));
    		addAttrNotNull(request, com.zimbra.common.soap.MailConstants.A_FOLDER, idFolder);
    
    		log.debug("Recherche planning entre " + debutRecherche + " et " + finRecherche + " pour idFolder=" + idFolder);
    		log.debug("Requete :" + DomUtil.toString(request, false));
    		
    		return request;
    	}
    
    	protected void parseResponse(ApptSummariesResponse response, Element responseXML)
    			throws ServiceException, LmcSoapClientException {
    
    		log.debug("Reponse :" + DomUtil.toString(responseXML, false));
    
    		// On boucle sur les elements trouves
    		Collection<Appointment> apptsTrouves = new ArrayList<Appointment>();
    		for (Iterator<Element> it = responseXML.elementIterator(); it.hasNext();) {
    			Element e = (Element) it.next();
    
    			Appointment app = ResponseParser.parseAppointment(e);
    			apptsTrouves.add(app);
    		}
    
    		response.setApptTrouves(apptsTrouves);
    	}
    
    	protected LmcSoapResponse parseResponseXML(Element responseXML)
    			throws ServiceException, LmcSoapClientException {
    		ApptSummariesResponse response = new ApptSummariesResponse();
    		parseResponse(response, responseXML);
    		return response;
    	}
    
    	public String getIdFolder() {
    		return idFolder;
    	}
    
    	public void setIdFolder(String idFolder) {
    		this.idFolder = idFolder;
    	}
    
    	public Date getDebutRecherche() {
    		return debutRecherche;
    	}
    
    	public void setDebutRecherche(Date debutRecherche) {
    		this.debutRecherche = debutRecherche;
    	}
    
    	public Date getFinRecherche() {
    		return finRecherche;
    	}
    
    	public void setFinRecherche(Date finRecherche) {
    		this.finRecherche = finRecherche;
    	}
    
    }
    And ApptSummariesResponse :
    Code:
    public class ApptSummariesResponse extends LmcSoapResponse {
    
    	Collection<Appointment> apptTrouves;
    
    	public Collection<Appointment> getApptTrouves() {
    		return apptTrouves;
    	}
    
    	public void setApptTrouves(Collection<Appointment> apptTrouves) {
    		this.apptTrouves = apptTrouves;
    	}
    	
    }
    Marine

  6. #6
    nbobfin is offline New Member
    Join Date
    Jun 2008
    Location
    Paris
    Posts
    4
    Rep Power
    7

    Default

    Thank you very much for your answer

    But I have found another way to do that. I tried to use the zclient api and it seems to be simpler.
    Here is how I log in :
    Code:
    SoapHttpTransport soapHttpTransport = new SoapHttpTransport(SERVICE_URL);
    Element request = Element.XMLElement.mFactory.createElement(AccountConstants.AUTH_REQUEST);
    request.addAttribute(AccountConstants.E_ACCOUNT, account, Element.Disposition.CONTENT);
    request.addAttribute(AccountConstants.E_PASSWORD, password, Element.Disposition.CONTENT);
    Element response = soapHttpTransport.invoke(request);
    String authToken = response.getAttribute(AccountConstants.E_AUTH_TOKEN);
    
    Options options = new Options(authToken, SERVICE_URL);
    ZMailbox zimbraMailbox = new ZMailbox(options);
    Then I use the ZMailBox object I just create to execute my queries.
    For instance here is the method to get the appointments :
    Code:
    zimbraMailbox.getApptSummaries(null, start.getTimeInMillis(), end.getTimeInMillis(),
          folderIds, TimeZone.getDefault(), null);
    where start and end are Calendar objects corresponding to the date between which I want to search, and foldersIds a String array containing the ids of the calendars.

    And if somebody is interested, here is the code to create an appointment :
    Code:
    ZMailbox.ZOutgoingMessage message = new ZOutgoingMessage();
    message.setSubject("subject");
    message.setMessagePart(new MessagePart("text/plain", "message body ..."));
    ZInvite invite = new ZInvite();
    ZComponent comp = new ZComponent();
    comp.setStart(new ZDateTime(startDateInMillis, false, TimeZone.getTimeZone("Europe/Brussels")));
    comp.setEnd(new ZDateTime(endDateInMillis, false, TimeZone.getTimeZone("Europe/Brussels")));
    comp.setOrganizer(new ZOrganizer(zimbraMailbox.getName()));
    comp.setName("name");
    invite.getComponents().add(comp);
    zimbraMailbox.createAppointment(folderId, null, message, invite, null);

  7. #7
    marinew is offline Senior Member
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    7

    Default

    Thanks Nbobfin !

    Interesting example, as that API you are using seems to be more complete that the one I use...
    It would be nice if Zimbra team could give some examples like this one, in soap.txt doc, for example, or in Wiki, so that developers don't take the wrong way.

  8. #8
    nbobfin is offline New Member
    Join Date
    Jun 2008
    Location
    Paris
    Posts
    4
    Rep Power
    7

    Default

    In fact, a more developed documentation would be very useful.

    But I have another problem.
    I want to create and modify appointments in the calendars of several users without knowing their password.
    Is there a way to do that with one of the zimbra APIs with an admin access ?

    Thanks

  9. #9
    marinew is offline Senior Member
    Join Date
    Aug 2007
    Location
    France - Bretagne
    Posts
    55
    Rep Power
    7

    Default

    You can access to admin commands using URL :
    "https://Zimbraserver:7071" + ZimbraServlet.ADMIN_SERVICE_URI
    instead of :
    "http://Zimbraserver" + ZimbraServlet.USER_SERVICE_URI

    Maybe you could try this ?

  10. #10
    nbobfin is offline New Member
    Join Date
    Jun 2008
    Location
    Paris
    Posts
    4
    Rep Power
    7

    Default

    OK that's it
    Thank you very much

    Here is the code to log in zimbra as a user :
    Code:
    SoapProvisioning sp = new SoapProvisioning();
    sp.soapSetURI("https://Zimbraserver:7071" + ZimbraServlet.ADMIN_SERVICE_URI);
    sp.soapAdminAuthenticate(adminLogin, adminPassword);
    ZAuthToken authToken = sp.delegateAuth(AccountBy.name, userLogin, durationInSecond).getAuthToken();
    Options options = new Options(authToken.getValue(), "http://Zimbraserver" + ZimbraServlet.USER_SERVICE_URI);
    ZMailbox zimbraMailbox = new ZMailbox(options);
    And then you have access to all methods described in previous posts.

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Spam Being Sent Thru Server - Help Needed!
    By msf004 in forum Administrators
    Replies: 22
    Last Post: 03-14-2008, 11:11 PM
  2. Can't start Zimbra!
    By zibra in forum Administrators
    Replies: 5
    Last Post: 03-22-2007, 11:34 AM
  3. Replies: 7
    Last Post: 01-24-2007, 11:03 PM
  4. Unable to start tomcat
    By chanck in forum Administrators
    Replies: 11
    Last Post: 06-11-2006, 12:58 AM
  5. Zimbra server crashed
    By goetzi in forum Administrators
    Replies: 6
    Last Post: 03-25-2006, 01:00 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
  •