List of usage examples for javax.xml.soap SOAPElement getNamespaceURI
public String getNamespaceURI(String prefix);
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)); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopyVisibleNamespaces_soapDom_targetMatch() 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"); String targetXml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>" + " <soap:Body>" + " <other:Operation xmlns:produce='urn:example:produce' xmlns:meal='urn:example:meal'" + " xmlns:other='urn:example:other'>" + " <lunch />" + " </other:Operation>" + " </soap:Body>" + "</soap:Envelope>"; SOAPMessage soapMessage = parseSoap(targetXml); SOAPElement operation = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:other", "Operation"); SOAPElement target = SoapUtil.getElement(operation, "lunch"); // in the WS4EE stack, target contains the *visible* namespace after parsing target.removeNamespaceDeclaration("produce"); target.removeNamespaceDeclaration("meal"); // perform the copy SoapUtil.copyVisibleNamespaces(target, source); List prefixes = IteratorUtils.toList(target.getNamespacePrefixes()); // prefixed declaration assertTrue(prefixes.contains("fish")); assertEquals("urn:example:fish", target.getNamespaceURI("fish")); // parent prefixed declaration assertFalse(prefixes.contains("produce")); assertEquals("urn:example:produce", target.getNamespaceURI("produce")); // default declaration (reassigned) assertFalse(prefixes.contains("meal")); assertEquals("urn:example:meal", target.getNamespaceURI("meal")); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopy_soapDom_qualifiedNoPrefix() throws Exception { String xml = "<ReverseAndConcatNames xmlns='http://my.namespace'>" + " <firstName>Martin</firstName>" + " <secondName>Steinle</secondName>" + "</ReverseAndConcatNames>"; Element source = XmlUtil.parseText(xml); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope(); SOAPElement target = envelope.getBody().addBodyElement(envelope.createName("detail")); // perform the copy SoapUtil.copy(target, source);// w w w . j ava 2 s . c om assertEquals("http://my.namespace", target.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); // qualified elements SOAPElement firstName = SoapUtil.getElement(target, "http://my.namespace", "firstName"); assertEquals("Martin", firstName.getValue()); SOAPElement secondName = SoapUtil.getElement(target, "http://my.namespace", "secondName"); assertEquals("Steinle", secondName.getValue()); }
From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java
public void testCopy_soapDom_noOverride() 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.parseText(xml); /*/*from w w w . ja v a 2 s. c o m*/ * here, notice the 'urn:example:meal' namespace (the default namespace in the source) is mapped * to prefix 'fish' which the source maps to namespace 'urn:example:fish' */ // <soap:Envelope xmlns:soap='${SOAPConstants.URI_NS_SOAP_ENVELOPE}'> // <soap:Body>" // <fish:Operation xmlns:fish='urn:example:meal'> // <part /> // </fish:Operation> // </soap:Body>" // </soap:Envelope> SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPElement operation = soapMessage.getSOAPBody().addChildElement("Operation", "fish", "urn:example:meal"); SOAPElement part = SoapUtil.addChildElement(operation, "part"); // perform the copy SoapUtil.copy(part, source); soapMessage = writeAndRead(soapMessage); // retrieve relevant elements operation = SoapUtil.getElement(soapMessage.getSOAPBody(), "urn:example:meal", "Operation"); part = SoapUtil.getElement(operation, "part"); SOAPElement lunch = SoapUtil.getElement(part, "urn:example:meal", "lunch"); // prefixed declaration assertEquals("urn:example:fish", lunch.getNamespaceURI("fish")); // parent prefixed declaration assertEquals("urn:example:produce", lunch.getNamespaceURI("produce")); // default declaration (reassigned) assertEquals("urn:example:meal", lunch.getNamespaceURI(SoapUtil.DEFAULT_NAMESPACE_PREFIX)); }
From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java
/** * Converts a {@link QName} to a {@link Name}. A {@link SOAPElement} is required to resolve namespaces. * * @param qName the <code>QName</code> to convert * @param resolveElement a <code>SOAPElement</code> used to resolve namespaces to prefixes * @return the converted SAAJ Name//ww w . j a v a 2s. c om * @throws SOAPException if conversion is unsuccessful * @throws IllegalArgumentException if <code>qName</code> is not fully qualified */ public static Name toName(QName qName, SOAPElement resolveElement) throws SOAPException { String qNamePrefix = QNameUtils.getPrefix(qName); SOAPEnvelope envelope = getEnvelope(resolveElement); if (StringUtils.hasLength(qName.getNamespaceURI()) && StringUtils.hasLength(qNamePrefix)) { return envelope.createName(qName.getLocalPart(), qNamePrefix, qName.getNamespaceURI()); } else if (StringUtils.hasLength(qName.getNamespaceURI())) { Iterator<?> prefixes; if (getSaajVersion(resolveElement) == SAAJ_11) { prefixes = resolveElement.getNamespacePrefixes(); } else { prefixes = resolveElement.getVisibleNamespacePrefixes(); } while (prefixes.hasNext()) { String prefix = (String) prefixes.next(); if (qName.getNamespaceURI().equals(resolveElement.getNamespaceURI(prefix))) { return envelope.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); } } return envelope.createName(qName.getLocalPart(), "", qName.getNamespaceURI()); } else { return envelope.createName(qName.getLocalPart()); } }