Results 1 to 10 of 25

Thread: API and JSON responses, How to read it in Java not JavaScript

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    19
    Rep Power
    9

    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.

  2. #2
    Join Date
    Nov 2006
    Posts
    19
    Rep Power
    9

    Default I love Google !

    Yes , you can process JSON in JAVA:

    http://www.json.org/javadoc/org/json/JSONObject.html

  3. #3
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    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!

  4. #4
    Join Date
    Nov 2006
    Posts
    19
    Rep Power
    9

    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>

  5. #5
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    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!

  6. #6
    Join Date
    Nov 2006
    Posts
    19
    Rep Power
    9

    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.

  7. #7
    Join Date
    Aug 2005
    Posts
    821
    Rep Power
    11

    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 ] :: :: [ . ] ::

  8. #8
    Join Date
    Aug 2005
    Posts
    1,433
    Rep Power
    12

    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.
    Last edited by dkarp; 12-21-2006 at 02:04 PM. Reason: Sam's probably right!
    Bugzilla - Wiki - Downloads - Before posting... Search!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •