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 Display Modes
  #21 (permalink)  
Old 10-08-2008, 06:53 AM
Active Member
 
Posts: 25
Default

Ok, but i dont understand which properties you set in parseAppointment() method.

For example, for contacts is this:

protected LmcContact parseContact(Element cn)
throws ServiceException
{
LmcContact result = new LmcContact();

// get the element's attributes
result.setID(DomUtil.getAttr(cn, MailConstants.A_ID));
result.setTags(cn.attributeValue(MailConstants.A_T AGS));
result.setFlags(cn.attributeValue(MailConstants.A_ FLAGS));
result.setFolder(cn.attributeValue(MailConstants.A _FOLDER));
result.setMDate(cn.attributeValue(MailConstants.A_ DATE));
result.setModDate(cn.attributeValue(MailConstants. A_MODIFIED_DATE));

// get the contact attributes (<a> elements)
ArrayList cnAttrs = new ArrayList();
for (Iterator ait = cn.elementIterator(MailConstants.E_ATTRIBUTE); ait.hasNext(); ) {
Element cnAttrElem = (Element) ait.next();
cnAttrs.add(parseContactAttr(cnAttrElem));
}
if (!cnAttrs.isEmpty()) {
LmcContactAttr cnAttrArray[] = new LmcContactAttr[cnAttrs.size()];
result.setAttrs((LmcContactAttr []) cnAttrs.toArray(cnAttrArray));
}

// XXX: not clear from spec if the <mp> element is used -- assume not
return result;
}
Reply With Quote
  #22 (permalink)  
Old 10-08-2008, 07:29 AM
Senior Member
 
Posts: 51
Default

Here is my ResponseParser.parseAppointment() method.

But you may also look at nbobfin post that seems to be a better method (I didn't try it).

Code:
public class ResponseParser {

	private final static Log log = LogFactory.getLog(ResponseParser.class);

	/**
	 * Construction d'un objet Appointment à partir d'un arbre XML.
	 * @param app
	 * @return
	 * @throws ServiceException
	 * @throws LmcSoapClientException
	 */
	public static Appointment parseAppointment(Element app)
			throws ServiceException, LmcSoapClientException {
		Appointment result = new Appointment();

		log.debug("Parse appointment : " + DomUtil.toString(app, false));

		result.setId(DomUtil.getAttr(app, MailConstants.A_ID));
		result.setLibelle(DomUtil.getAttr(app, MailConstants.A_NAME));
		result.setInviteId(DomUtil.getAttr(app, MailConstants.A_CAL_INV_ID));

		// On récupère l'attribut des tags, s'il existe
		try {
			String[] tags = DomUtil.getAttr(app, MailConstants.A_TAGS).split(
					",");
			result.setTagsId(Arrays.asList(tags));
		} catch (ServiceException e) {
			result.setTagsId(new ArrayList<String>());
		}
		Element inst = DomUtil.get(app, MailConstants.E_INSTANCE);
		long debut = DomUtil.getAttrLong(inst, MailConstants.A_CAL_START_TIME);
		long tzo = DomUtil.getAttrLong(inst, MailConstants.A_CAL_TZ_OFFSET, 3600000);
		debut += tzo - TimeZone.getDefault().getOffset(debut);
		result.setDateHeureDebut(new Date(debut));

		long fin = DomUtil.getAttrLong(inst, MailConstants.A_CAL_END_TIME, 0);
		if (fin != 0) {
			fin += tzo - TimeZone.getDefault().getOffset(fin);
			result.setDateHeureFin(new Date(fin));
		} else {
			long duree = DomUtil.getAttrLong(app, MailConstants.A_CAL_DURATION, 0);
			result.setDateHeureFin(new Date(debut + duree - 1));
		}

		result.setFreeBusy(DomUtil.getAttr(app, MailConstants.A_APPT_FREEBUSY_ACTUAL));
		if ("1".equals(DomUtil.getAttr(app, MailConstants.A_CAL_ALLDAY, "0"))) {
			result.setJourneeEntiere(true);
		} else {
			result.setJourneeEntiere(false);
		}
		
		result.setLieu(DomUtil.getAttr(app, MailConstants.A_CAL_LOCATION));

		// result.setFlags(app.attributeValue(MailService.A_FLAGS));
		// result.setFolder(app.attributeValue(MailService.A_FOLDER));
		log.debug("Appointment : " + result.toString());

		return result;
	}
}
Reply With Quote
  #23 (permalink)  
Old 10-08-2008, 08:33 AM
Active Member
 
Posts: 25
Default

When i try to post an http soap request i get an error.
It says to me :"invalid request: missing required element: inst"
Reply With Quote
  #24 (permalink)  
Old 10-09-2008, 01:18 AM
Junior Member
 
Posts: 8
Unhappy errors from chekout svn for building an env dev!!!

Quote:
Originally Posted by Klug View Post
Funny, we have two french developers chatting on an english forum 8)

In order to get the last and updated documentations about SOAP and APIs, you have to do a code checkout (against P4).
The up-to-date files are here (and here only, yet).
What is P4 ? I checkout the codes from svn :
https://zimbra.svn.sourceforge.net/svnroot/zimbra

I do the steps to build an eclipse env with the file :
http://zimbra.svn.sourceforge.net/vi...-SVN-WIN32.txt
and there are some mistakes that stop the ant generation processes :
1. for tomcat 5.5 part, it can't start due to a missing file : conf/keystore
2. 100 errors in eclipse java dev with 4 java errors form the chekout.

What does it happen ? What ais the right solution ?
Reply With Quote
  #25 (permalink)  
Old 10-09-2008, 06:10 AM
Active Member
 
Posts: 25
Default

This is my LmcApptSummariesRequest source code:

package com.zimbra.cs.client.soap;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.zimbra.common.service.ServiceException;
import com.zimbra.common.soap.MailConstants;
import com.zimbra.common.soap.SoapParseException;
import com.zimbra.common.soap.DomUtil;
import com.zimbra.common.util.Log;
import com.zimbra.common.util.LogFactory;
import com.zimbra.cs.client.*;

public class LmcApptSummariesRequest extends LmcSoapRequest {

private final static Log log = LogFactory.getLog(LmcApptSummariesRequest.class);

String idFolder;
Date inizioRicerca;
Date fineRicerca;

protected Element getRequestXML() {

Element request = DocumentHelper.createElement(MailConstants.GET_APP T_SUMMARIES_REQUEST);
inizioRicerca=new Date();
fineRicerca=new Date();
long inizio=inizioRicerca.getTime();
long fine=fineRicerca.getTime()+8400000;
// add all the attributes of the SearchRequest element
addAttrNotNull(request, com.zimbra.common.soap.MailConstants.A_CAL_START_T IME, String.valueOf(inizio));
addAttrNotNull(request, com.zimbra.common.soap.MailConstants.A_CAL_END_TIM E, String.valueOf(fine));
addAttrNotNull(request, com.zimbra.common.soap.MailConstants.A_FOLDER, idFolder);

log.debug("Ricerca da " + inizioRicerca + " e " + fineRicerca + " per idFolder=" + idFolder);
log.debug("Richiesta :" + DomUtil.toString(request, false));

return request;
}

protected void parseResponse(LmcApptSummariesResponse response, Element responseXML)
throws ServiceException, LmcSoapClientException {

log.debug("Reponse :" + DomUtil.toString(responseXML, false));

// Ciclo sugli elementi trovati
Collection<Appointment> appuntamentiTrovati = new ArrayList<Appointment>();
for (Iterator<Element> it = responseXML.elementIterator(MailConstants.E_APPOIN TMENT); it.hasNext() {
Element e = (Element) it.next();
System.err.println("sono dentro");
Appointment app = ResponseParser.parseAppointment(e);
appuntamentiTrovati.add(app);
}

response.setAppuntamentiTrovati(appuntamentiTrovat i);
}

protected LmcSoapResponse parseResponseXML(Element responseXML)
throws ServiceException, LmcSoapClientException {
LmcApptSummariesResponse response = new LmcApptSummariesResponse();
parseResponse(response, responseXML);
return response;
}

public String getIdFolder() {
return idFolder;
}

public void setIdFolder(String idFolder) {
this.idFolder = idFolder;
}

public Date getInizioRicerca() {
return inizioRicerca;
}

public void setInizioRicerca(Date inizioRicerca) {
this.inizioRicerca = inizioRicerca;
}

public Date getFineRicerca() {
return fineRicerca;
}

public void setFineRicerca(Date fineRicerca) {
this.fineRicerca = fineRicerca;
}
}


This code works, but i dont't understand how startTime, endTime, and IdFolder works, because results are not in the time range i expected.
Are dates required in a different format?
Reply With Quote
  #26 (permalink)  
Old 10-14-2008, 09:23 AM
Junior Member
 
Posts: 8
Default

Quote:
Originally Posted by nbobfin View Post
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.
I am beginner wtih zimbra soap service uses.
Your solution seems to be the rignt way to write these services.
I read some codes from marinew. What is you opinion ?
Would you please publish your entire source code to test quicky my first service. Il is a main java class ?
I don't know which jars are necessary (zimbracommon.jar and zimbrastore.jar) . I just have finished to install a ZCS 5
Where do you find information about the zclient api ?
Best regards
Reply With Quote
  #27 (permalink)  
Old 10-14-2008, 09:40 AM
Junior Member
 
Posts: 8
Default

Quote:
Originally Posted by gambo View Post
I find this code very interesting. Can you tell me how did you implement Appointment class?
Where can i find in soap.txt Appointment properties?
hello Marinew,
Would you please publish you entire code from login to create request , answer to manage appointment.
I want to test my first service. I have just finished to install my ZCS 5 server.
Best regards
Reply With Quote
  #28 (permalink)  
Old 10-20-2008, 05:38 AM
Junior Member
 
Posts: 8
Default

Hello marinew, gambo, nbobfin
Would you please publish you entire java code from login to create request , answer to manage appointment.
AEnd the necessary jars file : zimbrastore and zimbracommon are no sufficient...
I am keen on to testing my first service. I have just finished to install my ZCS 5 server.
Best regards
Reply With Quote
Reply


Thread Tools
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.

Zimbrablog.com




 

Search Engine Optimization by vBSEO 3.1.0