Search in sources :

Example 1 with OMNamespace

use of org.apache.axiom.om.OMNamespace 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 2 with OMNamespace

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

the class SetNamespaceTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element;
    OMNamedInformationItem node;
    if (context()) {
        // To avoid collisions if prefixInScope is the empty string
        OMNamespace dummyNS = factory.createOMNamespace("__dummy__", "__dummy__");
        OMElement parent = factory.createOMElement("parent", dummyNS);
        element = factory.createOMElement("test", dummyNS, parent);
        if (prefixInScope != null) {
            if (prefixInScope.length() == 0) {
                parent.declareDefaultNamespace(namespaceURI);
            } else {
                parent.declareNamespace(namespaceURI, prefixInScope);
            }
        }
    } else {
        element = null;
    }
    node = node(factory, element);
    OMNamespace ns = namespaceURI == null ? null : factory.createOMNamespace(namespaceURI, prefix);
    try {
        setNamespace(node, ns);
        if (invalid) {
            fail("Expected IllegalArgumentException");
        }
    } catch (IllegalArgumentException ex) {
        if (invalid) {
            return;
        } else {
            throw ex;
        }
    }
    String expectedPrefix;
    if (this.expectedPrefix == null) {
        expectedPrefix = node.getPrefix();
        assertNotNull(expectedPrefix);
        assertFalse(expectedPrefix.length() == 0);
    } else {
        expectedPrefix = this.expectedPrefix;
        if (expectedPrefix.length() == 0) {
            assertNull(node.getPrefix());
        } else {
            assertEquals(expectedPrefix, node.getPrefix());
        }
    }
    if (namespaceURI == null || namespaceURI.length() == 0) {
        assertNull(node.getNamespace());
    } else {
        OMNamespace actualNS = node.getNamespace();
        assertEquals(expectedPrefix, actualNS.getPrefix());
        assertEquals(namespaceURI, actualNS.getNamespaceURI());
    }
    if (namespaceURI == null || namespaceURI.length() == 0) {
        assertNull(node.getNamespaceURI());
    } else {
        assertEquals(namespaceURI, node.getNamespaceURI());
    }
    QName qname = node.getQName();
    assertEquals(expectedPrefix, qname.getPrefix());
    assertEquals(namespaceURI == null ? "" : namespaceURI, qname.getNamespaceURI());
    if (element != null) {
        Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
        if (expectNSDecl) {
            assertTrue(it.hasNext());
            OMNamespace decl = it.next();
            assertEquals(expectedPrefix, decl.getPrefix());
            assertEquals(namespaceURI == null ? "" : namespaceURI, decl.getNamespaceURI());
        }
        assertFalse(it.hasNext());
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamedInformationItem(org.apache.axiom.om.OMNamedInformationItem) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 3 with OMNamespace

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

the class TestGetAttributeTypeDefault method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://www.me.com", "axiom");
    OMAttribute at = factory.createOMAttribute("id", ns, "value");
    assertEquals("CDATA", at.getAttributeType());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 4 with OMNamespace

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

the class OMElementTest method testChildDetachment.

public void testChildDetachment() {
    OMNamespace testNamespace2 = factory.createOMNamespace("ftp://anotherTest.ws.org", "ws");
    secondElement.detach();
    assertTrue("OMElement children detachment has not worked properly", !secondElement.equals(firstElement.getFirstElement()));
    assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstElement());
    assertNull("First Element should not contain elements after detaching. ", firstElement.getFirstOMChild());
    assertNull(secondElement.findNamespace(testNamespace2.getNamespaceURI(), testNamespace2.getPrefix()));
    firstElement.addChild(secondElement);
    factory.createOMText(firstElement, "Some Sample Text");
    assertTrue("First added child must be the first child", secondElement.equals(firstElement.getFirstOMChild()));
    Iterator children = firstElement.getChildren();
    int childCount = 0;
    while (children.hasNext()) {
        children.next();
        childCount++;
    }
    assertEquals("Children count should be two", childCount, 2);
    secondElement.detach();
    assertTrue("First child should be the text child", firstElement.getFirstOMChild() instanceof OMText);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) Iterator(java.util.Iterator) OMText(org.apache.axiom.om.OMText)

Example 5 with OMNamespace

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

the class TestExtractAllHeaderBlocks method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
    SOAPHeader header = soapFactory.createSOAPHeader(envelope);
    OMNamespace ns = soapFactory.createOMNamespace("urn:ns", "p");
    SOAPHeaderBlock h1 = header.addHeaderBlock("header1", ns);
    SOAPHeaderBlock h2 = header.addHeaderBlock("header2", ns);
    Iterator<SOAPHeaderBlock> it = header.extractAllHeaderBlocks();
    assertTrue(it.hasNext());
    assertSame(h1, it.next());
    assertTrue(it.hasNext());
    assertSame(h2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)235 OMElement (org.apache.axiom.om.OMElement)158 OMFactory (org.apache.axiom.om.OMFactory)125 QName (javax.xml.namespace.QName)48 OMAttribute (org.apache.axiom.om.OMAttribute)28 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)24 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)21 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)16 StringWriter (java.io.StringWriter)15 SOAPHeader (org.apache.axiom.soap.SOAPHeader)15 Iterator (java.util.Iterator)14 OMText (org.apache.axiom.om.OMText)10 SOAPBody (org.apache.axiom.soap.SOAPBody)10 OMNode (org.apache.axiom.om.OMNode)9 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)9 SOAPFactory (org.apache.axiom.soap.SOAPFactory)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 MessageContext (org.apache.axis2.context.MessageContext)6 StringReader (java.io.StringReader)5 OMContainer (org.apache.axiom.om.OMContainer)5