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 03-21-2011, 01:44 PM
Intermediate Member
 
Posts: 17
Default Zimbra Calendar Client using SOAP or zclient

This is generic request, how to get Zimbra client started in Java v1.6.

We are running Zimbra 6.0, and need to write code to check/modify users' calendars to find for free time and setup meetings.

Looking to avoid writing SOAP, I am checking zclient. I can login as admin, but am overloaded with # of methods available in SoapProvisioning, Account, etc.

Is zclient a good tool for doing this, or should I write SOAP?

If zclient is good, please let me know how to get person's calendar free times, and any notes on how to create/delete meetings as well.


Thank you for your attention,
Ray
Reply With Quote
  #2 (permalink)  
Old 03-23-2011, 06:32 PM
Intermediate Member
 
Posts: 17
Default

I have seen examples for using ZMailbox and other items, confusing me further. It looks like I am on a wild goose chase.

We need to write Java client to support an application used by our University so students can sign up to meet their advisers.

Any response on directions to consider would be greatly appreciated, so I can stop chasing the goose.

Please help in any way you can.
Reply With Quote
  #3 (permalink)  
Old 03-20-2012, 01:22 PM
Junior Member
 
Posts: 7
Default

One year later , I have the same dilemma... ZMailbox or SOAP?
Which path did you finally choose?
Reply With Quote
  #4 (permalink)  
Old 03-20-2012, 01:48 PM
Intermediate Member
 
Posts: 17
Default

SOAP -> it works fine, once you get used to the structure (like envelope specifying xmlns for "urn:zimbra", "urn:zimbraAccount", etc.)
Reply With Quote
  #5 (permalink)  
Old 03-20-2012, 02:00 PM
Junior Member
 
Posts: 7
Default

Would it be possible for you to post a sample java code calling one of these SOAP web services?
Thanks.
Reply With Quote
  #6 (permalink)  
Old 03-21-2012, 11:35 AM
Intermediate Member
 
Posts: 17
Default Sample code

I do not know if I can give you a copy of our code.

Here is example code using sockets; we wrote our own wrappers for this, instead of using a framework.

REQUEST: replace [hostName], [port], and [soapRequest], and this should be able to run a request.

Code:
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

Socket socket = null;
if (ssl) {
	// Using SSL
	SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
	socket = (SSLSocket)
		factory.createSocket(InetAddress.getByName([hostName]), [port]);
} else {
	// Simple Socket
	socket = new Socket(InetAddress.getByName([hostName]), [port]);
}
socket.setKeepAlive(true);
Writer writer = new BufferedWriter(
		new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
writer.write([soapRequest]);
writer.flush();
RESPONSE: use the reader to get the header and contents.
Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;

BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream());
Read entire header, finding line "Content-Length: #[#[#]]"

Get that length, as that is critical to knowing when to stop reading the response

Once you got the entire header, you need to read the contents for that exact # of characters. Note that I found there may be a couple of empty lines before the contents, and those do not counted for, so you may end up missing the last couple characters in the response.

If you need example SOAP, check out the following. Note that also includes Java code, may be helpful, but we chose to not use that.

[SOLVED] Java SOAP Request receiving service.UNKNOWN_DOCUMENT

Good Luck.
Reply With Quote
  #7 (permalink)  
Old 03-21-2012, 09:10 PM
Junior Member
 
Posts: 7
Default

Your help is very much appreciated. Thank you.

I've made some progress... I'm now able to authenticate using the admin account.

Code:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:zaccount="urn:zimbraAccount"
    xmlns:zimbra="urn:zimbra"
    xmlns:zmail="urn:zimbraMail">
<soap:Header>
  <soap:context xmlns="urn:zimbra" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <nonotify xmlns=""/>
    <noqualify xmlns=""/>
  </soap:context>
</soap:Header>
<soap:Body>
  <zaccount:AuthRequest xmlns="urn:zimbraAccount">
    <account by="name" xmlns="">user</account>
    <password xmlns="">password</password>
  </zaccount:AuthRequest>
</soap:Body>
</soap:Envelope>
And I'm getting an authToken in the response:

Code:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
  <context xmlns="urn:zimbra">
    <change token="660"/>
  </context>
</soap:Header>
<soap:Body>
<AuthResponse xmlns="urn:zimbraAccount">
  <authToken>
    mytoken
  </authToken>
  <lifetime>172800000</lifetime>
  <skin>carbon</skin>
</AuthResponse>
</soap:Body>
</soap:Envelope>
But then I try to use this authToken to call another service :

Code:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:zaccount="urn:zimbraAccount"
    xmlns:zimbra="urn:zimbra"
    xmlns:zmail="urn:zimbraMail">
<soap:Header>
  <soap:context xmlns="urn:zimbra" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <account by="name" xmlns="">user@domain.com</account>
    <authToken xmlns="">myToken</authToken>
    <nonotify xmlns=""/>
    <noqualify xmlns=""/>
  </soap:context>
</soap:Header>
<soap:Body>
  <zmail:GetFolderRequest>
    <folder/>
  </zmail:GetFolderRequest>
</soap:Body>
</soap:Envelope>
And I get this response :

Code:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
  <context xmlns="urn:zimbra"/>
</soap:Header>
<soap:Body>
  <soap:Fault>
    <soap:faultcode>soap:Client</soap:faultcode>
    <soap:faultstring>no valid authtoken present</soap:faultstring>
    <soap:detail>
      <Error xmlns="urn:zimbra">
        <Code>service.AUTH_REQUIRED</Code>
        <Trace>...</Trace>
      </Error>      
    </soap:detail>
  </soap:Fault>
</soap:Body>
</soap:Envelope>
Do you have an idea of what could be wrong?
I'm using javax.xml.soap classes to build SOAP messages. The 2 calls are made using the same SOAPConnection.

Thanks.
Reply With Quote
  #8 (permalink)  
Old 03-22-2012, 05:24 AM
Intermediate Member
 
Posts: 17
Default

Same connection should not matter. It looks like your request is fine, but admin may not have permissions for that.

Maybe try the same request as the calendar's owner, and see if that works.

We share each user's calendar with admin to give admin access. No access to get folders seems like a different issue.

IMHO, writing SOAP requests is easier done using templates than using javax.xml.soap. We write each request in .txt file, with template keys, read the template by getting URL from classloader, then push in the data with String.replaceAll(). Of course, this means we have to make sure the data is XML compatible, and javax.xml.soap must take care of that.
Reply With Quote
  #9 (permalink)  
Old 03-22-2012, 10:55 PM
Starter Member
 
Posts: 1
Default

Is there any documentation about the Zimbra Java Client library ..... and where can I find it?
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.