Results 1 to 10 of 16

Thread: SOAP response structure for GetContactsRequest

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Location
    India
    Posts
    28
    Rep Power
    2

    Default SOAP response structure for GetContactsRequest

    Hi,

    when GetContactsRequest's response in SOAP format is received the structure of that xml response is something like this.

    <GetContactsResponse xmlns="urn:zimbraMail">
    <cn id="680" fileAsStr="group1" d="1308612784000" rev="900" l="7">
    <a n="nickname">group one</a>
    <a n="type">group</a>
    <a n="fileAs">8:group1</a>
    <m value="user@zimbra.com" type="I"/>
    <m value="282" type="C">
    <cn id="282" fileAsStr="Smith, John" d="1308547353000" rev="27" l="7">
    <a n="lastName">Smith</a>
    <a n="email">jsmith@example.zimbra.com</a>
    <a n="workURL">http://www.example.zimbra.com</a>
    <a n="company">Zimbra</a>
    <a n="workCountry">US</a>
    <a n="workState">CA</a>
    <a n="workPhone">(408) 123-4567</a>
    <a n="firstName">Mark</a>
    </cn>
    </m>
    <m value="uid=user1,ou=people,dc=phoebe,dc=mbp" type="G">
    <cn id="2a692f57-1a5b-4542-9f8e-28dfdd0e3f43:260" fileAsStr="Demo User One" d="1308626790000" rev="22" l="257">
    <a n="createTimeStamp">20110620052132Z</a>
    <a n="lastName">user1</a>
    <a n="email">user1@phoebe.mbp</a>
    <a n="zimbraId">b4bf7953-c10f-449e-b7fe-3df48eea36f8</a>
    <a n="objectClass">inetOrgPerson</a>
    <a n="objectClass">zimbraAccount</a>
    <a n="objectClass">amavisAccount</a>
    <a n="fullName">Demo User One</a>
    <a n="dn">uid=user1,ou=people,dc=phoebe,dc=mbp</a>
    <a n="workPhone">+1 650 555 1111</a>
    <a n="modifyTimeStamp">20110620052229Z</a>
    <a n="fileAs">8emo User One</a>
    </cn>
    </m>
    </cn>
    </GetContactsResponse>


    in above xml structure, fullname,firstname,birthdates have been used as attribute's value rather than saperate xml element. due to this parsing entire data with multiple fields is very difficult.cant we have structure something like this,


    <cn id=""...>
    <firstname>blah</firstname>
    <lastname>blah</lastname>

    </cn>

    Address fields like city,street are included as part of attribute's value of <a n=".."> element.so it could have been structurized differently somthing like this
    <address type="home">
    <city>blah</city>
    <street></street>
    </address>


    due to lack of proper structure of response format,parsing have to be done manually using if and else conditions. any suggestion on how to parse this specific response in JAVA? i currently use JAXB for parsing. but after getting list of element <a n="..."> i have to set details manually.

  2. #2
    Join Date
    Oct 2009
    Location
    Dublin, IRELAND
    Posts
    712
    Rep Power
    7

    Default

    I haven't parsed any of the output with JAVA - but in PHP I found it easier to request JSON output from the server, and then to use an out of the box json_decode function. I assume JAVA must have one as well.

    When you are formatting your soap request you need to specify a format tag in the header context element. type="js" requests json output.

    $header = '<context xmlns="urn:zimbra">
    <session />
    <notify seq="0" />
    <format type="js" />
    </context>';

    One caveat is that error conditions will sometimes return plain HTML or XML.

    If you can read php - take a look at the function SoapRequest in zimbra.php (part of z-push zimbra backend) from Z-Push Zimbra Backend | Free software downloads at SourceForge.net
    It has handling for all the odd conditions I have found over time.

  3. #3
    Join Date
    Feb 2013
    Location
    India
    Posts
    28
    Rep Power
    2

    Default

    @liverpoolfcfan

    yes. we can have soap request/response in JSON format. but even if you receive response in json format,you will have same problem of manipulating list of <a> elements. because we have no clue where firstname is stored. so we must use ifs and else.so my question is something like this if you understand. i have one POJO class which contains simple fields related to contact like firstname and last name. so for setting that fields we must travers list of <a> element and must check each value of that element in order to set first name from response. it would be helpful if you can post some glimpse of parsing.

  4. #4
    Join Date
    Oct 2009
    Location
    Dublin, IRELAND
    Posts
    712
    Rep Power
    7

    Default

    It is all contained within the zimbra.php file.

    We use a defined an associative array of the attributes we are interested in $_contactMapping (definition is at the top of the file.) this contains all the fields that ActiveSync can handle. Each key for that array is a property within our output contact object. Each value is the matching attribute name on zimbra.

    Then we loop through that list of attribute keys, looking to see if that matching attribute is set on the zimbra side, and if it is, then grab the value. We ignore all the other zimbra attributes that do not exist in the mapping array, as we cannot send them to the phone anyway. See loop at approx line 4600.

    If you are populating some kind of contact object, then you could have a similar mapping defined for your object.

    In our case, we grab one contact at a time - so 'cn' is always 0 - $item = $array['Body']['GetContactsResponse']['cn'][0];

    But you could easily loop through a number of contacts by getting
    count ( $array['Body']['GetContactsResponse']['cn'] )
    and then looping through the
    $array['Body']['GetContactsResponse']['cn'][0]
    $array['Body']['GetContactsResponse']['cn'][1]
    ...
    $array['Body']['GetContactsResponse']['cn'][n]

    Be careful not to select too many contacts at a time.

  5. #5
    Join Date
    Feb 2013
    Location
    India
    Posts
    28
    Rep Power
    2

    Default

    thanx @liverpoolfcfan. i got it after seeing zimbra.php. but that is where the limitation comes into picutre. you have populated a fixed array of attributes. so you wont be able to populate object's value out of that array. i mean imagine if user enters 5 email addressess or 5 url in url list. so the resulting structure would be like email,email1,email2,email3,.... emailN. so my problem is how to set N number of same type of element. right now zimbra web client supports and they can manange multiple type of elements. i am searching the source for that solution but still unable to find how they manage to handle N number of element.it would be great if they provide structure like,

    <emails>
    <email type="">blah</email>
    <email type="">blah</email>
    <email type="">blah</email>
    </emails>

    instead of,
    <a n="email">blah</a>
    <a n="email1">blah</a>
    <a n="email2">blah</a>

    so do you have any solution for that?

  6. #6
    Join Date
    Aug 2010
    Location
    England
    Posts
    39
    Rep Power
    5

    Default

    Hi Parin,

    I appreciate that such a format would make parsing easier for you.
    We wouldn't be able to make that change generally, because we need to support backwards compatibility. You could submit an enhancement request at Zimbra Bugzilla (http://bugzilla.zimbra.com) to add a new variant of GetContactsRequest or even a new SOAP request to do what you desire. I'll be honest and say that I personally wouldn't be a fan though. It would make our WSDL significantly larger (although perhaps slightly easier to consume) and add an extra step to enhance the WSDL each time we add a new attribute (unless we invest a fair amount of effort in creating a new mechanism for keeping the attributes and WSDL in step automatically) The fact that we haven't chosen to create such a format for our internal use suggests that we are happy enough with the current format from a parsing perspective.

    Another approach you could consider is to use the REST interface to get the contact information either in csv format or vcard format. There are libraries for many programming languages which help with processing both those formats.
    Another possibility, if you're using JAXB objects, you could add methods that process the "a" list to produce the information in a form you are happier consuming.

    All the best,
    Gren
    Gren Elliot
    Lead Engineer - Server
    Zimbra | Community & Collaboration

Similar Threads

  1. Refresh tab with soap response
    By bud in forum Developers
    Replies: 0
    Last Post: 09-04-2012, 04:14 AM
  2. How to read attribute value in soap response
    By hugo@dlshk in forum Zimlets
    Replies: 1
    Last Post: 04-12-2012, 08:59 PM
  3. Zimbra 6 SOAP response changes ?
    By Aderium in forum Developers
    Replies: 0
    Last Post: 09-22-2009, 03:36 PM
  4. How to handle SOAP body response in PHP
    By ferdinant in forum Developers
    Replies: 1
    Last Post: 07-03-2007, 02:21 PM
  5. Whitespaces in SOAP response
    By smies in forum Developers
    Replies: 2
    Last Post: 11-05-2005, 03:33 PM

Posting Permissions

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