Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: SOAP response structure for GetContactsRequest

  1. #1
    parin is offline Active Member
    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
    liverpoolfcfan's Avatar
    liverpoolfcfan is online now Outstanding Member
    Join Date
    Oct 2009
    Location
    Dublin, IRELAND
    Posts
    710
    Rep Power
    6

    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
    parin is offline Active Member
    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
    liverpoolfcfan's Avatar
    liverpoolfcfan is online now Outstanding Member
    Join Date
    Oct 2009
    Location
    Dublin, IRELAND
    Posts
    710
    Rep Power
    6

    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
    parin is offline Active Member
    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
    gren is offline Zimbra Employee
    Join Date
    Aug 2010
    Location
    England
    Posts
    33
    Rep Power
    4

    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

  7. #7
    parin is offline Active Member
    Join Date
    Feb 2013
    Location
    India
    Posts
    28
    Rep Power
    2

    Default

    Thank you gren for replying. actually my problem is something like this. i am using Hibernate ORM to map database objects to classes. so i have one class called Contact which represents basic details like firstName,lastName etc.. now for any multiple valued attribute, i have created saperate class means a saperate table by giving O2M relationship.. for example ContactEmail class/table represents multiple emails of that contact.in the same way ContactPhone represents multiple phone numbers of that contact. so these class/tables will be having M20 reletionship with the Contact base class. so my problem arises when i try to set values for these pojo class. because once the multimap or map has been prepared, i must travers for looking details.. so my question is how Zimbra handles these details inside database?? and how it displays back to web client in form of phone1, phone2 etc or multiple address with type definde.

    Thnx.

  8. #8
    liverpoolfcfan's Avatar
    liverpoolfcfan is online now Outstanding Member
    Join Date
    Oct 2009
    Location
    Dublin, IRELAND
    Posts
    710
    Rep Power
    6

    Default

    Zimbra simply stores an ordered sequence of attributes. email, email2, email3 ... The easiest was to understand what it does is to use the Developer Tools in a Chrome browser.

    Open Menu->Tools->Developer Tools.

    Within Developer tools, select the Network tab.

    Create a test contact with 4 email addresses. Then modify something about the contact, and save it. You will see a Request ModifyContactRequest in the left hand navigation window. Click on it and look at the JSON response. You will see that there are 4 email addresses in there email, email2, email3, email4

    Now, open the Contact again. Delete the 2nd email address. Save the contact, and look for the new ModifyContactRequest entry in the navigation window. Click on it and look at the JSON response. You will see that there are just 3 email addresses in there - and they are labelled email, email2, and email3 - NOT email, email3, and email4

    Zimbra does not care that you thought you were deleting email2 - it just stores them as a list of email addresses, and returns them and labels them in sequence whenever they are requested.

    Now, open the contact again. Click the + beside the first email address. Add in a new email address. So you now have 4 email addresses again. Save the contact and look for the new ModifyContactRequest entry in the navigation window. Click on it and look at the JSON response. You will see that there are now 4 email addresses in there - and they are labelled email, email2, email3, and email4 - but this time the address that was previously in email3 is now in email4, and the old email2 is now in email3, and the newly added address is now in email2

  9. #9
    parin is offline Active Member
    Join Date
    Feb 2013
    Location
    India
    Posts
    28
    Rep Power
    2

    Default

    @liverpoolfcfan

    exactly correct.. we see a response part only. but my question is how it is going to store in underlying database. take an example of emails just as above and we have table relationship like Contact Table for contact details and Email table for contactEmail details. now Contact and ContactEmail have O2M relationship.means one contact can have 0 or more emails. so now the problem arises. json response will simply return _attr element with list of contact attribute. so my question is how we will find multiple emails from that Map. also the problem becomes more complecated when user enters multiple addresses. and in that case it becomes more worsen when users like me adds single value like city in one address,street in second address and state in another address for testing.so now finding out how many addresses user have entered is very tough. can you help me in this case. ???

  10. #10
    liverpoolfcfan's Avatar
    liverpoolfcfan is online now Outstanding Member
    Join Date
    Oct 2009
    Location
    Dublin, IRELAND
    Posts
    710
    Rep Power
    6

    Default

    If it were me, using PHP I would use the json_decode function to parse the JSON response into an array.

    28/11/2013 13:36:21 [16031] [DEBUG] [vincents] [sec1f4a1a73470de] Zimbra->GetMessage(): CONTACT:Array
    (
    [id] => 36017
    [l] => 7
    [f] =>
    [t] =>
    [md] => 1385645781
    [ms] => 521933
    [d] => 1385645781000
    [rev] => 521933
    [meta] => Array
    (
    [0] => Array
    (
    )

    )

    [fileAsStr] => NoFriends, Mary
    [_attrs] => Array
    (
    [email4] => mary4@123.com
    [lastName] => NoFriends
    [mobilePhone] => +353 2345678
    [email] => mary@123.com
    [workPhone] => +353 12345678
    [firstName] => Mary
    [email2] => mary5@123.com
    [email3] => mary3@123.com
    [jobTitle] => New title
    )

    )

    And then look for the key ['_attrs']['email'] first. If it is not found you are done. Otherwise, look for email2, email3, etc. until you run out of them.

    $emails = array();

    if (isset($contact['_attrs']['email'])) {
    $emails[0] = $contact['_attrs']['email'];

    $counter = 1;
    while true {
    $lookForEmail = 'email' . strval($counter + 1);
    if ( isset($contact['_attrs'][$lookForEmail])) {
    $emails[$counter] = $contact['_attrs'][$lookForEmail];
    } else {
    break;
    }
    $counter += 1;
    }
    }

    $numberOfEmails = count($emails);

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Refresh tab with soap response
    By bud in forum Developers
    Replies: 0
    Last Post: 09-04-2012, 03:14 AM
  2. How to read attribute value in soap response
    By hugo@dlshk in forum Zimlets
    Replies: 1
    Last Post: 04-12-2012, 07:59 PM
  3. Zimbra 6 SOAP response changes ?
    By Aderium in forum Developers
    Replies: 0
    Last Post: 09-22-2009, 02:36 PM
  4. How to handle SOAP body response in PHP
    By ferdinant in forum Developers
    Replies: 1
    Last Post: 07-03-2007, 01: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
  •