Search in sources :

Example 1 with SOAPHeaderBlock

use of org.apache.axiom.soap.SOAPHeaderBlock 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 SOAPHeaderBlock

use of org.apache.axiom.soap.SOAPHeaderBlock 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)

Example 3 with SOAPHeaderBlock

use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.

the class TestExamineMustUnderstandHeaderBlocksWithParser method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    String roleNextURI = spec.getNextRoleURI();
    Iterator<SOAPHeaderBlock> it = envelope.getHeader().examineMustUnderstandHeaderBlocks(roleNextURI);
    assertThat(it.hasNext()).isTrue();
    SOAPHeaderBlock headerBlock = it.next();
    assertThat(headerBlock.getQName()).isEqualTo(new QName("http://example.org/RoleTest", "h7"));
    assertThat(headerBlock.getRole()).isEqualTo(roleNextURI);
    assertThat(it.hasNext()).isFalse();
}
Also used : QName(javax.xml.namespace.QName) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Example 4 with SOAPHeaderBlock

use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.

the class TestGetHeaderBlocksWithName method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    Iterator<SOAPHeaderBlock> it = envelope.getHeader().getHeaderBlocksWithName(new QName("http://example.org/RoleTest", "h2"));
    assertThat(it.hasNext()).isTrue();
    SOAPHeaderBlock headerBlock = it.next();
    assertThat(headerBlock.getLocalName()).isEqualTo("h2");
    assertThat(headerBlock.getText().trim()).isEqualTo("I'm so next.");
}
Also used : QName(javax.xml.namespace.QName) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Example 5 with SOAPHeaderBlock

use of org.apache.axiom.soap.SOAPHeaderBlock in project webservices-axiom by apache.

the class TestGetHeaderBlocksWithNSURIWithParser method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    ArrayList<SOAPHeaderBlock> headerBlocks = envelope.getHeader().getHeaderBlocksWithNSURI("urn:ns2");
    assertThat(headerBlocks).hasSize(2);
    assertThat(headerBlocks.get(0).getQName()).isEqualTo(new QName("urn:ns2", "h4"));
    assertThat(headerBlocks.get(1).getQName()).isEqualTo(new QName("urn:ns2", "h6"));
}
Also used : QName(javax.xml.namespace.QName) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Aggregations

SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)40 SOAPHeader (org.apache.axiom.soap.SOAPHeader)22 QName (javax.xml.namespace.QName)15 OMNamespace (org.apache.axiom.om.OMNamespace)13 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 OMElement (org.apache.axiom.om.OMElement)8 OMAttribute (org.apache.axiom.om.OMAttribute)4 OMNode (org.apache.axiom.om.OMNode)4 SOAPBody (org.apache.axiom.soap.SOAPBody)4 SOAPProcessingException (org.apache.axiom.soap.SOAPProcessingException)4 BooleanAttributeAccessor (org.apache.axiom.ts.soap.BooleanAttributeAccessor)4 SOAPFault (org.apache.axiom.soap.SOAPFault)3 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)3 StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)2 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)2 SOAPCloneOptions (org.apache.axiom.soap.SOAPCloneOptions)2 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)2