| Welcome to the Zimbra - Forums! | |
Welcome, if you would like to post a comment in the forums, please register and review our posting policy & tips.
We also encourage you to explore all things Zimbra with our team and members of the community.
|  | | 
08-28-2007, 01:01 AM
| | | 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. | 
08-29-2007, 03:29 AM
| | | 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.
| 
10-10-2007, 11:34 AM
| | | 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.
| 
06-19-2008, 07:12 AM
| | | 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 | 
06-23-2008, 12:48 AM
| | | 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 respon***ML)
throws ServiceException, LmcSoapClientException {
log.debug("Reponse :" + DomUtil.toString(respon***ML, false));
// On boucle sur les elements trouves
Collection<Appointment> apptsTrouves = new ArrayList<Appointment>();
for (Iterator<Element> it = respon***ML.elementIterator(); it.hasNext();) {
Element e = (Element) it.next();
Appointment app = ResponseParser.parseAppointment(e);
apptsTrouves.add(app);
}
response.setApptTrouves(apptsTrouves);
}
protected LmcSoapResponse parseRespon***ML(Element respon***ML)
throws ServiceException, LmcSoapClientException {
ApptSummariesResponse response = new ApptSummariesResponse();
parseResponse(response, respon***ML);
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 | 
06-26-2008, 01:21 AM
| | | 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); | 
06-26-2008, 11:23 PM
| | | 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. | 
06-27-2008, 09:39 AM
| | | 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 | 
06-27-2008, 10:17 AM
| | | 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 ? | 
06-30-2008, 02:44 AM
| | | 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. | | Thread Tools | | | | Display Modes | Linear Mode | | Why Join? Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.  |