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;
}
}
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());
}
}
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());
}
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);
}
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());
}
Aggregations