List of usage examples for javax.xml.soap SOAPFactory createElement
public abstract SOAPElement createElement(String localName) throws SOAPException;
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test/* w w w . j a v a2s.co m*/ public void testCreateElement() { try { //SOAPFactory sf = SOAPFactory.newInstance(); SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); if (sf == null) { fail("createElementTest4() could not create SOAPFactory object"); } //Create QName object with localName=MyName1,prefix=MyPrefix1, uri=MyUri1 QName name = new QName("MyUri1", "MyName1", "MyPrefix1"); SOAPElement se = sf.createElement(name); assertNotNull(se); name = se.getElementQName(); String localName = name.getLocalPart(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); if (localName == null) { fail("localName is null (expected MyName1)"); } else if (!localName.equals("MyName1")) { fail("localName is wrong (expected MyName1)"); } else if (prefix == null) { fail("prefix is null (expected MyPrefix1)"); } else if (!prefix.equals("MyPrefix1")) { fail("prefix is wrong (expected MyPrefix1)"); } else if (uri == null) { fail("uri is null (expected MyUri1)"); } else if (!uri.equals("MyUri1")) { fail("uri is wrong (expected MyUri1)"); } } catch (Exception e) { fail(); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test//w w w .java 2 s. com public void testCreateElement2() { try { SOAPFactory sf = SOAPFactory.newInstance(); //SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); if (sf == null) { fail("could not create SOAPFactory object"); } log.info("Create a DOMElement"); DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbfactory.newDocumentBuilder(); Document document = builder.newDocument(); Element de = document.createElementNS("http://MyNamespace.org/", "MyTag"); //Calling SOAPFactory.createElement(org.w3c.dom.Element) SOAPElement se = sf.createElement(de); if (!de.getNodeName().equals(se.getNodeName()) || !de.getNamespaceURI().equals(se.getNamespaceURI())) { //Node names are not equal fail("Got: <URI=" + se.getNamespaceURI() + ", PREFIX=" + se.getPrefix() + ", NAME=" + se.getNodeName() + ">" + "Expected: <URI=" + de.getNamespaceURI() + ", PREFIX=" + de.getPrefix() + ", NAME=" + de.getNodeName() + ">"); } } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test//from ww w.ja v a 2 s . c o m public void testCreateElement4() { try { SOAPFactory sf = SOAPFactory.newInstance(); if (sf == null) { fail("createElementTest6() could not create SOAPFactory object"); } QName qname = new QName("http://MyNamespace.org/", "MyTag"); SOAPElement se1 = sf.createElement(qname); //Create second SOAPElement from first SOAPElement SOAPElement se2 = sf.createElement(se1); //commented to support jdk 1.4 build // if(!se1.isEqualNode(se2) && !se1.isSameNode(se2)) { // fail("The SOAPElement's are not equal and not the same (unexpected)"); // } if (!se1.getNodeName().equals(se2.getNodeName()) || !se1.getNamespaceURI().equals(se2.getNamespaceURI())) { fail("Got: <URI=" + se1.getNamespaceURI() + ", PREFIX=" + se1.getPrefix() + ", NAME=" + se1.getNodeName() + ">" + "Expected: <URI=" + se2.getNamespaceURI() + ", PREFIX=" + se2.getPrefix() + ", NAME=" + se2.getNodeName() + ">"); } } catch (Exception e) { fail(); } }
From source file:org.codice.ddf.security.interceptor.AnonymousInterceptor.java
private void createSecurityToken(SoapVersion version, SOAPFactory soapFactory, SOAPElement securityHeader, String ipAddress) {//from w w w . j a va 2s . com Subject subject = getSubject(ipAddress); LOGGER.trace("Attempting to create Security token."); if (subject != null) { PrincipalCollection principals = subject.getPrincipals(); if (principals != null) { SecurityAssertion securityAssertion = principals.oneByType(SecurityAssertion.class); if (securityAssertion != null) { SecurityToken securityToken = securityAssertion.getSecurityToken(); Element samlElement = securityToken.getToken(); SOAPElement samlAssertion = null; try { samlAssertion = soapFactory.createElement(samlElement); securityHeader.addChildElement(samlAssertion); } catch (SOAPException e) { LOGGER.error("Unable to convert SecurityToken to SOAPElement.", e); } } else { LOGGER.warn("Subject did not contain a security assertion, could not assertion" + "to security header."); } } else { LOGGER.warn("Subject did not contain any principals, could not create element."); } } }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyAttributes_soapDom() throws Exception { String xml = "<lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:produce='urn:example:produce' xmlns:fish='urn:example:fish'/>"; Element source = XmlUtil.parseText(xml); SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement target = soapFactory.createElement("detail"); // perform the copy SoapUtil.copyAttributes(target, source); // qualified attributes assertEquals("0.1lb", target.getAttributeValue(soapFactory.createName("lettuce", null, "urn:example:produce"))); assertEquals("0.25lb", target.getAttributeValue(soapFactory.createName("fillet", null, "urn:example:fish"))); // local attribute assertEquals("1200", target.getAttributeValue(soapFactory.createName("time"))); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyNamespaces_soapDom() throws Exception { String xml = "<part xmlns:produce='urn:example:produce'>" + " <lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:fish='urn:example:fish' xmlns='urn:example:meal'/>" + "</part>"; Element source = XmlUtil.getElement(XmlUtil.parseText(xml), "urn:example:meal", "lunch"); SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement target = soapFactory.createElement("detail"); // perform the copy SoapUtil.copyNamespaces(target, source); // prefixed declaration assertEquals("urn:example:fish", target.getNamespaceURI("fish")); // parent prefixed declaration assertNull(target.getNamespaceURI("produce")); // default declaration (reassigned) assertEquals("urn:example:meal", target.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyVisibleNamespaces_soapDom() throws Exception { String xml = "<part xmlns:produce='urn:example:produce'>" + " <lunch produce:lettuce='0.1lb' fish:fillet='0.25lb' " + " xmlns:fish='urn:example:fish' xmlns='urn:example:meal'/>" + "</part>"; Element source = XmlUtil.getElement(XmlUtil.parseText(xml), "urn:example:meal", "lunch"); SOAPFactory soapFactory = SOAPFactory.newInstance(); SOAPElement target = soapFactory.createElement("lunch"); // perform the copy SoapUtil.copyVisibleNamespaces(target, source); // prefixed declaration assertEquals("urn:example:fish", target.getNamespaceURI("fish")); // parent prefixed declaration assertEquals("urn:example:produce", target.getNamespaceURI("produce")); // default declaration (reassigned) assertEquals("urn:example:meal", target.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); }