Search in sources :

Example 81 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class Geo method toXml.

public Element toXml(Element parent) {
    Element geo = parent.addElement(MailConstants.E_CAL_GEO);
    geo.addAttribute(MailConstants.A_CAL_GEO_LATITUDE, mLatitude);
    geo.addAttribute(MailConstants.A_CAL_GEO_LONGITUDE, mLongitude);
    return geo;
}
Also used : Element(com.zimbra.common.soap.Element)

Example 82 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method kvpForCreateDLResp_bug74371.

/*
# zmsoap -z -t account -m user1 GetDistributionListRequest/dl=grendl@coco.local @by=name
<GetDistributionListResponse xmlns="urn:zimbraAccount">
  <dl id="7a3e8ec5-4892-4b17-9225-cf17e8b3acc9" dynamic="1" name="grendl@coco.local" isOwner="1" isMember="1">
    <a n="mail">grendl@coco.local</a>
    <a n="zimbraMailStatus">enabled</a>
    <a n="zimbraMailAlias">grendl@coco.local</a>
    <a n="description">Wonder at that</a>
    <a n="displayName">Gren DLfun</a>
    <a n="zimbraDistributionListSubscriptionPolicy">ACCEPT</a>
    <a n="zimbraDistributionListUnsubscriptionPolicy">ACCEPT</a>
  </dl>
</GetDistributionListResponse>
# zmsoap --json -z -t account -m user1 GetDistributionListRequest/dl=grendl@coco.local @by=name
{
  "dl": [{
      "name": "grendl@coco.local",
      "id": "7a3e8ec5-4892-4b17-9225-cf17e8b3acc9",
      "dynamic": true,
      "isMember": true,
      "isOwner": true,
      "_attrs": {
        "mail": "grendl@coco.local",
        "zimbraMailStatus": "enabled",
        "zimbraMailAlias": "grendl@coco.local",
        "description": "Wonder at that",
        "displayName": "Gren DLfun",
        "zimbraDistributionListSubscriptionPolicy": "ACCEPT",
        "zimbraDistributionListUnsubscriptionPolicy": "ACCEPT"
      }
    }],
  "_jsns": "urn:zimbraAccount"
}

Extract from mailbox.log for creation of this DL by ZWC - demonstrating the different handling of attrs - See Bug 74371

      "CreateDistributionListResponse": [{
          "dl": [{
              "name": "grendl@coco.local",
              "id": "7a3e8ec5-4892-4b17-9225-cf17e8b3acc9",
              "dynamic": true,
              "a": [
                {
                  "n": "memberURL",
                  "_content": "ldap:///??sub?(|(zimbraMemberOf=7a3e8ec5-4892-4b17-9225-cf17e8b3acc9)(zimbraId=de47828e-94dd-45c3-9770-4dbd255564ca))"
                },
                {
                  "n": "mail",
                  "_content": "grendl@coco.local"
                },
                ...
     */
/**
     * Desired JSON
     */
// Re-enable when Bug 74371 is fixed? @Test
public void kvpForCreateDLResp_bug74371() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get(AccountConstants.E_CREATE_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateCreateDlResp(jsonElem);
    Element xmlElem = XMLElement.mFactory.createElement(QName.get(AccountConstants.E_CREATE_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateCreateDlResp(xmlElem);
    logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("key1", "value1"));
    attrs.add(new KeyValuePair("key2", "value2"));
    DLInfo dl = new DLInfo("myId", "myRef", "my name", null, null, null, null, null);
    CreateDistributionListResponse jaxb = new CreateDistributionListResponse(dl);
    Element xmlJaxbElem = JaxbUtil.jaxbToElement(jaxb, XMLElement.mFactory);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    DLInfo roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, DLInfo.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    logDebug("XMLElement from JAXB ---> prettyPrint\n%1$s", xmlJaxbElem.prettyPrint());
    Element eDL = jsonJaxbElem.getElement(AdminConstants.E_DL);
    List<? extends KeyValuePair> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = eDL.getElement("a").listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 2, elemKVPs.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) CreateDistributionListResponse(com.zimbra.soap.account.message.CreateDistributionListResponse) DLInfo(com.zimbra.soap.account.type.DLInfo)

Example 83 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method kvpForGetDLResp.

/**
     * Desired JSON
     * {
     *   "dl": [{
     *       "name": "my name",
     *       "id": "myId",
     *       "dynamic": true,
     *       "_attrs": {
     *         "mail": "fun@example.test",
     *         "zimbraMailStatus": "enabled"
     *       }
     *     }],
     *   "_jsns": "urn:zimbraAccount"
     * }
     */
@Test
public void kvpForGetDLResp() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get(AccountConstants.E_GET_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateGetDlResp(jsonElem);
    Element xmlElem = XMLElement.mFactory.createElement(QName.get(AccountConstants.E_GET_DISTRIBUTION_LIST_RESPONSE, AccountConstants.NAMESPACE_STR));
    populateGetDlResp(xmlElem);
    logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    // ObjectInfo declares this field:
    //     @ZimbraKeyValuePairs
    //     @XmlElement(name=AccountConstants.E_A /* a */, required=false)
    //     private final List<KeyValuePair> attrList;
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("mail", "fun@example.test"));
    attrs.add(new KeyValuePair("zimbraMailStatus", "enabled"));
    DistributionListInfo dl = new DistributionListInfo("myId", "my name", null, attrs);
    dl.setDynamic(true);
    GetDistributionListResponse jaxb = new GetDistributionListResponse(dl);
    Element xmlJaxbElem = JaxbUtil.jaxbToElement(jaxb, XMLElement.mFactory);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    GetDistributionListResponse roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, GetDistributionListResponse.class);
    GetDistributionListResponse roundtrippedX = JaxbUtil.elementToJaxb(xmlJaxbElem, GetDistributionListResponse.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    logDebug("XMLElement from JAXB ---> prettyPrint\n%1$s", xmlJaxbElem.prettyPrint());
    List<? extends KeyValuePair> kvps = roundtripped.getDl().getAttrList();
    Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
    // ensure that the JAXB handles empty owners OK (not using empty list in JAXB field initializer)
    Assert.assertNull("roundtripped owner", roundtripped.getDl().getOwners());
    Assert.assertNull("roundtrippedX owner", roundtrippedX.getDl().getOwners());
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 84 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method zimbraKeyValuePairsAnnotation.

/**
     * Check that JSON can be deserialised into a JAXB object when some of the JSON represents Zimbra KeyValuePairs
     * (i.e. An "_attrs" array).
     * In this case, the target objects for each keyvalue pair use the defaults of "a" for the element name and
     * "n" for the attribute name in the XML form.
     * Desired XML :<br />
     * &lt;key-value-pairs-tester xmlns="urn:zimbraTest">
     *   &lt;a n="key1">value1&lt;/a>
     *   &lt;a n="key2">value2-a&lt;/a>
     *   &lt;a n="key2">value2-b&lt;/a>
     * &lt;/key-value-pairs-tester>
     *<br />
     * Desired JSON :<br />
     * {
     *   "_attrs": {
     *     "key1": "value1",
     *     "key2": [
     *       "value2-a",
     *       "value2-b"]
     *   },
     *   "_jsns": "urn:zimbraTest"
     * }
     */
@Test
public void zimbraKeyValuePairsAnnotation() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("key-value-pairs", "urn:zimbraTest"));
    jsonElem.addKeyValuePair("key1", "value1");
    jsonElem.addKeyValuePair("key2", "value2-a");
    jsonElem.addKeyValuePair("key2", "value2-b");
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("key1", "value1"));
    attrs.add(new KeyValuePair("key2", "value2-a"));
    attrs.add(new KeyValuePair("key2", "value2-b"));
    KeyValuePairsTester jaxb = new KeyValuePairsTester(attrs);
    logDebug("XMLElement (from JAXB) ---> prettyPrint\n%1$s", JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false).prettyPrint());
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    KeyValuePairsTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, KeyValuePairsTester.class);
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = jsonJaxbElem.listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 3, elemKVPs.size());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
    List<KeyValuePair> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 3, kvps.size());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) WrappedKeyValuePairsTester(com.zimbra.soap.jaxb.WrappedKeyValuePairsTester) KeyValuePairsTester(com.zimbra.soap.jaxb.KeyValuePairsTester) OddKeyValuePairsTester(com.zimbra.soap.jaxb.OddKeyValuePairsTester) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 85 with Element

use of com.zimbra.common.soap.Element in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method encodeAttr.

// Cut down version of com.zimbra.cs.service.admin.ToXML.encodeAttr
private void encodeAttr(Element parent, String key, String value, String eltname, String attrname) {
    Element e = parent.addElement(eltname);
    e.addAttribute(attrname, key);
    e.setText(value);
}
Also used : XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement)

Aggregations

Element (com.zimbra.common.soap.Element)980 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)315 XMLElement (com.zimbra.common.soap.Element.XMLElement)269 Account (com.zimbra.cs.account.Account)220 Test (org.junit.Test)175 JSONElement (com.zimbra.common.soap.Element.JSONElement)167 Provisioning (com.zimbra.cs.account.Provisioning)147 Mailbox (com.zimbra.cs.mailbox.Mailbox)138 ServiceException (com.zimbra.common.service.ServiceException)103 ItemId (com.zimbra.cs.service.util.ItemId)81 ArrayList (java.util.ArrayList)81 OperationContext (com.zimbra.cs.mailbox.OperationContext)80 HashMap (java.util.HashMap)77 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)56 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)54 Server (com.zimbra.cs.account.Server)49 FilterTest (com.zimbra.soap.mail.type.FilterTest)46 IOException (java.io.IOException)45 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)44 XmlElement (javax.xml.bind.annotation.XmlElement)44