Search in sources :

Example 1 with OMElement

use of org.apache.axiom.om.OMElement in project tdi-studio-se by Talend.

the class SforceManagementImpl method upsert.

/**
     * upsert, one record, one time.
     */
@Override
public UpsertResult[] upsert(String tablename, String upsertkey, OMElement[] updatefields, String[] fieldsToNull) throws Exception {
    // create the account object to hold our changes
    SObject item = new SObject();
    item.setType(tablename);
    // set a new value for the name property
    item.setExtraElement(updatefields);
    // set a null field for the name property
    item.setFieldsToNull(fieldsToNull);
    upsertItems.add(item);
    upsertKeyColumn = upsertkey;
    // call the update passing an array of object
    if (upsertItems.size() >= commitLevel) {
        SObject[] upds = upsertItems.toArray(new SObject[upsertItems.size()]);
        String[] changedItemKeys = new String[upds.length];
        for (int ix = 0; ix < upds.length; ++ix) {
            changedItemKeys[ix] = "No value for " + upsertKeyColumn + " ";
            OMElement[] oms = upds[ix].getExtraElement();
            for (OMElement om : oms) {
                if (upsertKeyColumn != null && om != null && upsertKeyColumn.equals(om.getLocalName())) {
                    changedItemKeys[ix] = om.getText();
                    break;
                }
            }
        }
        Upsert upsert = new Upsert();
        upsert.setSObjects(upds);
        upsert.setExternalIDFieldName(upsertKeyColumn);
        UpsertResult[] upsertResults = sforceConn.upsert(upsert).getResult();
        upsertItems.clear();
        upds = null;
        if (upsertResults != null && upsertResults.length != 0) {
            int batch_idx = -1;
            for (UpsertResult result : upsertResults) {
                ++batch_idx;
                StringBuilder errors = new StringBuilder("");
                if (result.getSuccess()) {
                // TODO: send back the ID
                } else {
                    errors = addLog(result.getErrors(), batch_idx < changedItemKeys.length ? changedItemKeys[batch_idx] : "Batch index out of bounds");
                }
                if (exceptionForErrors && errors.toString().length() > 0) {
                    if (logWriter != null) {
                        logWriter.close();
                    }
                    throw new Exception(errors.toString());
                }
            }
        }
        return upsertResults;
    }
    return null;
}
Also used : Upsert(com.salesforce.soap.partner.Upsert) DescribeSObject(com.salesforce.soap.partner.DescribeSObject) SObject(com.salesforce.soap.partner.sobject.SObject) OMElement(org.apache.axiom.om.OMElement) UpsertResult(com.salesforce.soap.partner.UpsertResult)

Example 2 with OMElement

use of org.apache.axiom.om.OMElement in project tdi-studio-se by Talend.

the class MSCRMClient method createCRMSecurityHeaderBlock.

private static SOAPHeaderBlock createCRMSecurityHeaderBlock(SecurityData securityData) throws XMLStreamException {
    RequestDateTimeData dateTimeData = WsdlTokenManager.getRequestDateTime();
    String currentDateTime = dateTimeData.getCreatedDateTime();
    String expireDateTime = dateTimeData.getExpiresDateTime();
    String securityHeaderTemplate = "<EncryptedData " + "    xmlns=\"http://www.w3.org/2001/04/xmlenc#\"" + "     Id=\"Assertion0\" " + "    Type=\"http://www.w3.org/2001/04/xmlenc#Element\">" + "    <EncryptionMethod " + "        Algorithm=\"http://www.w3.org/2001/04/xmlenc#tripledes-cbc\"/>" + "    <ds:KeyInfo " + "        xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">" + "        <EncryptedKey>" + "            <EncryptionMethod " + "                Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\"/>" + "            <ds:KeyInfo Id=\"keyinfo\">" + "                <wsse:SecurityTokenReference " + "                    xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" + "                    <wsse:KeyIdentifier " + "                        EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" " + "                        ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier\">%s</wsse:KeyIdentifier>" + "                </wsse:SecurityTokenReference>" + "            </ds:KeyInfo>" + "            <CipherData>" + "                <CipherValue>%s</CipherValue>" + "            </CipherData>" + "        </EncryptedKey>" + "    </ds:KeyInfo>" + "    <CipherData>" + "        <CipherValue>%s</CipherValue>" + "    </CipherData>" + "</EncryptedData>";
    String securityHeader = String.format(securityHeaderTemplate, securityData.getKeyIdentifier(), securityData.getSecurityToken0(), securityData.getSecurityToken1());
    try {
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace securityNS = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "o");
        OMNamespace utitlityNS = factory.createOMNamespace("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "u");
        OMElement timeStamp = factory.createOMElement("Timestamp", utitlityNS);
        timeStamp.addAttribute("Id", "_0", utitlityNS);
        OMElement created = factory.createOMElement("Created", utitlityNS);
        OMText createdTime = factory.createOMText(currentDateTime + "Z");
        created.addChild(createdTime);
        OMElement expires = factory.createOMElement("Expires", utitlityNS);
        OMText expiresTime = factory.createOMText(expireDateTime + "Z");
        expires.addChild(expiresTime);
        timeStamp.addChild(created);
        timeStamp.addChild(expires);
        SOAPHeaderBlock wsseHeader = OMAbstractFactory.getSOAP12Factory().createSOAPHeaderBlock("Security", securityNS);
        wsseHeader.setMustUnderstand(true);
        wsseHeader.addChild(timeStamp);
        wsseHeader.addChild(AXIOMUtil.stringToOM(factory, securityHeader));
        return wsseHeader;
    } catch (XMLStreamException e) {
        logger.error(e.getMessage());
        throw e;
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) RequestDateTimeData(org.talend.ms.crm.sdk.RequestDateTimeData) XMLStreamException(javax.xml.stream.XMLStreamException) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Example 3 with OMElement

use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.

the class OMAttributeTest method addAttributeMethod2.

private String addAttributeMethod2(String xmlString) throws Exception {
    OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createOMBuilder(new StringReader(xmlString));
    OMElement doc = builder2.getDocumentElement();
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
    //code line to be tested
    doc.addAttribute("id", "value", ns);
    return doc.toString();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 4 with OMElement

use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.

the class OMOutputTest method setUp.

/*
     * @see TestCase#setUp()
     */
protected void setUp() throws Exception {
    super.setUp();
    DataHandler dataHandler;
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace soap = fac.createOMNamespace("http://schemas.xmlsoap.org/soap/envelope/", "soap");
    envelope = fac.createOMElement("Envelope", soap);
    OMElement body = fac.createOMElement("Body", soap);
    OMNamespace dataName = fac.createOMNamespace("http://www.example.org/stuff", "m");
    OMElement data = fac.createOMElement("data", dataName);
    OMNamespace mime = fac.createOMNamespace("http://www.w3.org/2003/06/xmlmime", "mime");
    OMElement text = fac.createOMElement("name", dataName);
    OMAttribute cType1 = fac.createOMAttribute("contentType", mime, "text/plain");
    text.addAttribute(cType1);
    byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1, 98 };
    dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
    OMText textData = fac.createOMText(dataHandler, false);
    envelope.addChild(body);
    body.addChild(data);
    data.addChild(text);
    text.addChild(textData);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) OMAttribute(org.apache.axiom.om.OMAttribute) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource)

Example 5 with OMElement

use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.

the class MTOMStAXSOAPModelBuilderTest method testCreateCloneAndSerializeOptimized.

/**
     * Test reading a message containing XOP.
     * Then make a copy of the message.
     * Then ensure that the XOP is preserved when it is serialized.
     * @throws Exception
     */
public void testCreateCloneAndSerializeOptimized() throws Exception {
    OMElement root = createTestMTOMMessage();
    // Create a clone of root
    OMElement root2 = root.cloneOMElement();
    // Write out the source
    checkSerialization(root, true);
    // Write out the clone
    checkSerialization(root2, true);
}
Also used : OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMElement (org.apache.axiom.om.OMElement)379 OMFactory (org.apache.axiom.om.OMFactory)189 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)90 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)42 OMText (org.apache.axiom.om.OMText)40 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)28 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)23 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 DataHandler (javax.activation.DataHandler)17 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 InputStream (java.io.InputStream)15 OMException (org.apache.axiom.om.OMException)13 SOAPBody (org.apache.axiom.soap.SOAPBody)13