use of org.apache.axiom.om.OMFactory 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.OMFactory 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();
}
use of org.apache.axiom.om.OMFactory 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);
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class ElementSerializerTest method testDualNamespaces1.
public void testDualNamespaces1() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns1 = factory.createOMNamespace("bar", "x");
OMNamespace ns2 = factory.createOMNamespace("bar", "y");
OMElement root = factory.createOMElement("root", ns1);
OMElement elt11 = factory.createOMElement("foo1", ns1);
OMElement elt12 = factory.createOMElement("foo2", ns1);
OMElement elt21 = factory.createOMElement("yuck", ns2);
OMElement elt22 = factory.createOMElement("yuck", ns2);
elt11.addChild(elt21);
elt12.addChild(elt22);
root.addChild(elt11);
root.addChild(elt12);
root.serialize(writer);
}
use of org.apache.axiom.om.OMFactory in project webservices-axiom by apache.
the class ElementSerializerTest method testDualNamespaces2.
public void testDualNamespaces2() throws Exception {
OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace ns1 = factory.createOMNamespace("bar", "x");
OMElement root = factory.createOMElement("root", ns1);
OMNamespace ns2 = root.declareNamespace("bar", "y");
OMElement elt1 = factory.createOMElement("foo", ns1);
OMElement elt2 = factory.createOMElement("yuck", ns2);
OMText txt1 = factory.createOMText(elt2, "blah");
elt2.addChild(txt1);
elt1.addChild(elt2);
root.addChild(elt1);
root.serialize(writer);
}
Aggregations