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