Search in sources :

Example 1 with AnnotationFieldKeySorter

use of org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter in project camel by apache.

the class DefaultCompositeApiClient method configureXStream.

static XStream configureXStream() {
    final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider(new FieldDictionary(new AnnotationFieldKeySorter()));
    final XppDriver hierarchicalStreamDriver = new XppDriver(new NoNameCoder()) {

        @Override
        public HierarchicalStreamWriter createWriter(final Writer out) {
            return new CompactWriter(out, getNameCoder());
        }
    };
    final XStream xStream = new XStream(reflectionProvider, hierarchicalStreamDriver);
    xStream.aliasSystemAttribute(null, "class");
    xStream.ignoreUnknownElements();
    XStreamUtils.addDefaultPermissions(xStream);
    xStream.registerConverter(new DateTimeConverter());
    xStream.setMarshallingStrategy(new TreeMarshallingStrategy());
    xStream.processAnnotations(ADDITIONAL_TYPES);
    return xStream;
}
Also used : AnnotationFieldKeySorter(org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter) TreeMarshallingStrategy(com.thoughtworks.xstream.core.TreeMarshallingStrategy) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) XppDriver(com.thoughtworks.xstream.io.xml.XppDriver) XStream(com.thoughtworks.xstream.XStream) FieldDictionary(com.thoughtworks.xstream.converters.reflection.FieldDictionary) DateTimeConverter(org.apache.camel.component.salesforce.api.utils.DateTimeConverter) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Writer(java.io.Writer) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)

Example 2 with AnnotationFieldKeySorter

use of org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter in project camel by apache.

the class SObjectBatchTest method shouldSerializeToXml.

@Test
public void shouldSerializeToXml() {
    final String xml = //
    "<batch>\n" + //
    "  <batchRequests>\n" + //
    "    <batchRequest>\n" + //
    "      <method>POST</method>\n" + //
    "      <url>v37.0/sobjects/Account/</url>\n" + //
    "      <richInput>\n" + //
    "        <Account>\n" + //
    "          <Name>NewAccountName</Name>\n" + //
    "          <Industry>Environmental</Industry>\n" + //
    "        </Account>\n" + //
    "      </richInput>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>DELETE</method>\n" + //
    "      <url>v37.0/sobjects/Account/001D000000K0fXOIAZ</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/sobjects/Account/001D000000K0fXOIAZ?fields=Name,BillingPostalCode</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/sobjects/Account/EPK/12345</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/sobjects/Account/001D000000K0fXOIAZ/CreatedBy?fields=Name</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/limits/</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>PATCH</method>\n" + //
    "      <url>v37.0/sobjects/Account/001D000000K0fXOIAZ</url>\n" + //
    "      <richInput>\n" + //
    "        <Account>\n" + //
    "          <Name>NewName</Name>\n" + //
    "          <AccountNumber>AC12345</AccountNumber>\n" + //
    "        </Account>\n" + //
    "      </richInput>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>PATCH</method>\n" + //
    "      <url>v37.0/sobjects/Account/EPK/12345</url>\n" + //
    "      <richInput>\n" + //
    "        <Account>\n" + //
    "          <Name>NewName</Name>\n" + //
    "        </Account>\n" + //
    "      </richInput>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>PATCH</method>\n" + //
    "      <url>v37.0/sobjects/Account/EPK/12345</url>\n" + //
    "      <richInput>\n" + //
    "        <Account>\n" + //
    "          <Name>NewName</Name>\n" + //
    "        </Account>\n" + //
    "      </richInput>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>PATCH</method>\n" + //
    "      <url>v37.0/some/url</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/query/?q=SELECT Name FROM Account</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/queryAll/?q=SELECT Name FROM Account</url>\n" + //
    "    </batchRequest>\n" + //
    "    <batchRequest>\n" + //
    "      <method>GET</method>\n" + //
    "      <url>v37.0/search/?q=FIND {joe}</url>\n" + //
    "    </batchRequest>\n" + //
    "  </batchRequests>\n" + "</batch>";
    final PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider(new FieldDictionary(new AnnotationFieldKeySorter()));
    final XStream xStream = new XStream(reflectionProvider);
    xStream.aliasSystemAttribute(null, "class");
    xStream.processAnnotations(SObjectBatch.class);
    xStream.processAnnotations(batch.objectTypes());
    final String serialized = xStream.toXML(batch);
    assertEquals("Should serialize as expected by Salesforce", xml, serialized);
}
Also used : AnnotationFieldKeySorter(org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter) XStream(com.thoughtworks.xstream.XStream) FieldDictionary(com.thoughtworks.xstream.converters.reflection.FieldDictionary) PureJavaReflectionProvider(com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider) Test(org.junit.Test)

Aggregations

XStream (com.thoughtworks.xstream.XStream)2 FieldDictionary (com.thoughtworks.xstream.converters.reflection.FieldDictionary)2 PureJavaReflectionProvider (com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider)2 AnnotationFieldKeySorter (org.apache.camel.component.salesforce.api.dto.AnnotationFieldKeySorter)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 TreeMarshallingStrategy (com.thoughtworks.xstream.core.TreeMarshallingStrategy)1 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)1 NoNameCoder (com.thoughtworks.xstream.io.naming.NoNameCoder)1 CompactWriter (com.thoughtworks.xstream.io.xml.CompactWriter)1 XppDriver (com.thoughtworks.xstream.io.xml.XppDriver)1 Writer (java.io.Writer)1 DateTimeConverter (org.apache.camel.component.salesforce.api.utils.DateTimeConverter)1 Test (org.junit.Test)1