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 12-19-2006, 12:00 PM
Intermediate Member
 
Posts: 19
Cool API and JSON responses, How to read it in Java not JavaScript

I make it quick:

Zimbra API always responses in JSON. I need to process the response in my Java app (not JavaScript).

Do you know any Java class that can parse JSON?
-or-
Can Zimbra response in any other format?

Last edited by seeker; 12-19-2006 at 12:04 PM..
Reply With Quote
  #2 (permalink)  
Old 12-19-2006, 12:06 PM
Intermediate Member
 
Posts: 19
Default I love Google !

Yes , you can process JSON in JAVA:

http://www.json.org/javadoc/org/json/JSONObject.html
Reply With Quote
  #3 (permalink)  
Old 12-19-2006, 02:47 PM
Zimbra Employee
 
Posts: 1,434
Default Not JSON by default

Quote:
Originally Posted by seeker View Post
Zimbra API always responses in JSON. I need to process the response in my Java app (not JavaScript).
Zimbra by default responds with the same format your request is in. So if your resuest is SOAP 1.2, Zimbra responds in SOAP 1.2. If your request is JSON, Zimbra sends back JSON.

You can override this (and the Web client does) by adding a <format> element to the <context> element in the SOAP header. But if you send XML and leave off the special <format> tag, you'll get XML back.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #4 (permalink)  
Old 12-21-2006, 11:25 AM
Intermediate Member
 
Posts: 19
Default Are you sure?

Here is my request:

Code:
POST /service/admin/soap/ HTTP/1.1 
Content-Type: application/soap+xml; charset=utf-8 
User-Agent: Test application 
Host: 192.168.0.180:7071 
Content-Length: 342 
Connection: Keep-Alive 
Cache-Control: no-cache 
Pragma: no-cache 

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
	<soap:Header>
		<context xmlns="urn:zimbra">
			<nosession/>
			<format type="js"/>
		</context>
	</soap:Header>
	<soap:Body>
		<AuthRequest xmlns="urn:zimbraAccount">
			<account by="name">amir.far@MYDOMAIN.com</account>
			<password>1234</password>
		</AuthRequest>
	</soap:Body>
</soap:Envelope>
And here Zimbra's response:

Code:
HTTP/1.1 200 OK 
Server: Apache-Coyote/1.1 
Content-Type: text/javascript;charset=utf-8 
Content-Length: 275 
Date: Tue, 19 Dec 2006 18:38:36 GMT 

{Body:{AuthResponse:{lifetime:172800000,authToken:"0_9175f262ba2f814f542486fc4d39f4c2e771fb89_69643d33363a64386463643230662d613239622d346131352d613662622d6232626437363230376237343b6578703d31333a313136363732363331363734343b",_jsns:"urn:zimbraAccount"}},_jsns:"urn:zimbraSoap"}
As you see my request is in XML but the response from is JSON !
Im going to try <format>
Reply With Quote
  #5 (permalink)  
Old 12-21-2006, 12:11 PM
Zimbra Employee
 
Posts: 1,434
Default You're asking for JSON!

Do you see that <format type="js"/> line in your request? That explicitly requests a JSON response. Take it out and you'll get XML back.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!
Reply With Quote
  #6 (permalink)  
Old 12-21-2006, 01:26 PM
Intermediate Member
 
Posts: 19
Default Im sorry!

Im sorry, you are right, I should have copy and pasted the request from the webmail client's debug window.

I can not find documentation for the <format> tag in SOAP.txt
http://zimbra.svn.sourceforge.net/vi...88&view=markup

What are my options other than "js"?
If I remove <format type="js"/> then Zimbra does not response! (connection time out). type="xml" has the same effect.

Last edited by seeker; 12-21-2006 at 01:28 PM..
Reply With Quote
  #7 (permalink)  
Old 12-21-2006, 02:00 PM
sam sam is offline
Zimbra Employee
 
Posts: 821
Default

sound like a content-length bug. are you reducing the amount of data you are sending, but not decreasing the content-length you are sending?

If so, the server waits until you send it the number of bytes indicated in the content-length header. If your content-length is greater than the amount of data you actually send, the symptom is a timeout.
__________________
Sam Khavari

:: :: [ Zimbra ] :: :: [ Bugzilla ] :: :: [ Product Portal ] :: :: [ Wiki ] :: :: [ Downloads ] :: :: [ . ] ::
Reply With Quote
  #8 (permalink)  
Old 12-21-2006, 02:03 PM
Zimbra Employee
 
Posts: 1,434
Default Sorry for the missing documentation

Leaving the <format> element out should not cause the Zimbra server to hang. In fact, much our internal SOAP testing is done without setting <format>.

Can you post the request that's hanging on the server? Because that's really, really weird.


Or, what Sam said. I'd go with that option first.
__________________
Bugzilla - Wiki - Downloads - Before posting... Search!

Last edited by dkarp; 12-21-2006 at 02:04 PM.. Reason: Sam's probably right!
Reply With Quote
  #9 (permalink)  
Old 12-21-2006, 02:40 PM
Intermediate Member
 
Posts: 19
Default

I am sending the exact same request without <format type="js">. which is 19 characters.

My code calculates the length of the soap body right before posting it and puts it in the header. It calculates the lenght starting from begining of "<soap:Envelope"...to the end of..."</soap:Envelope>"

Here is my request with <format type="js"/> which works.
Code:
POST /service/admin/soap/ HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
User-Agent: Test application
Host: 192.168.0.180:7071
Content-Length: 332
Connection: Keep-Alive
Cache-Control: no-cache
Pragma: no-cache

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><context xmlns="urn:zimbra"><nosession/><format type="js"/></context></soap:Header><soap:Body><AuthRequest xmlns="urn:zimbraAccount"><account by="name">amir.far@xxxxxxxxx.com</account><password>1234</password></AuthRequest></soap:Body></soap:Envelope>
And here is the request without format tag, which does not work, (time out):
Code:
POST /service/admin/soap/ HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
User-Agent: Test application
Host: 192.168.0.180:7071
Content-Length: 313
Connection: Keep-Alive
Cache-Control: no-cache
Pragma: no-cache

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><context xmlns="urn:zimbra"><nosession/></context></soap:Header><soap:Body><AuthRequest xmlns="urn:zimbraAccount"><account by="name">amir.far@xxxxxxxxx.com</account><password>1234</password></AuthRequest></soap:Body></soap:Envelope>
Note that the content length is 19 characters shorter.

By the way, I have replaced my 9 characters long domain name with 9 "x"s.
Reply With Quote
  #10 (permalink)  
Old 12-21-2006, 02:44 PM
sam sam is offline
Zimbra Employee
 
Posts: 821
Default

7071 is the admin port. Are you trying to do an admin auth? What happens when you send the request to port 7070?
__________________
Sam Khavari

:: :: [ Zimbra ] :: :: [ Bugzilla ] :: :: [ Product Portal ] :: :: [ Wiki ] :: :: [ Downloads ] :: :: [ . ] ::
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


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.