Example usage for javax.xml.soap SOAPElement getNamespacePrefixes

List of usage examples for javax.xml.soap SOAPElement getNamespacePrefixes

Introduction

In this page you can find the example usage for javax.xml.soap SOAPElement getNamespacePrefixes.

Prototype

public Iterator<String> getNamespacePrefixes();

Source Link

Document

Returns an Iterator over the namespace prefix String s declared by this element.

Usage

From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java

/**
 * Namespace context resolver//w  w w  .  jav  a2s. com
 * 
 * @param context namespace context
 * @param element SOAP message element
 */
public static final void addNamespaces(final SimpleNamespaceContext context, final SOAPElement element) {
    final Iterator<?> namespaces = element.getNamespacePrefixes();
    while (namespaces.hasNext()) {
        final String prefix = (String) namespaces.next();
        final String uri = element.getNamespaceURI(prefix);
        context.addNamespace(prefix, uri);
    }
}

From source file:ee.ria.xroad.common.message.SoapUtils.java

/**
 * Returns all namespace prefixes of a given SOAP element.
 * @param element the SOAP element from which to retrieve namespace prefixes
 * @return a List of namespace prefix Strings
 *//*  w w  w .java 2 s  .c  om*/
public static List<String> getNamespacePrefixes(SOAPElement element) {
    List<String> nsPrefixes = new ArrayList<>();

    Iterator<?> it = element.getNamespacePrefixes();
    while (it.hasNext()) {
        nsPrefixes.add(it.next().toString());
    }

    return nsPrefixes;
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static void copyNamespaces(Element target, SOAPElement source) {
    copyNamespaces(target, source, source.getNamespacePrefixes());
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static void removeNamespaces(SOAPElement elem) {
    Iterator prefixIt = elem.getNamespacePrefixes();
    while (prefixIt.hasNext()) {
        String prefix = (String) prefixIt.next();
        elem.removeNamespaceDeclaration(prefix);
    }/*from  w  w w. j av a  2 s  .c  o m*/
}

From source file:org.jbpm.bpel.integration.soap.SoapUtilTest.java

public void testRemoveNamespaces_soap() throws Exception {
    String xml = "<soap:Envelope xmlns:soap='" + SOAPConstants.URI_NS_SOAP_ENVELOPE + "'>"
            + " <soap:Body xmlns:fish='urn:example:fish'>"
            + "  <lunch time='1200' produce:lettuce='0.1lb' fish:fillet='0.25lb' "
            + "   xmlns:produce='urn:example:produce' />" + " </soap:Body>" + "</soap:Envelope>";
    ByteArrayInputStream sourceStream = new ByteArrayInputStream(xml.getBytes());
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, sourceStream);
    SOAPElement element = SoapUtil.getElement(soapMessage.getSOAPBody(), "lunch");
    // remove namespaces
    SoapUtil.removeNamespaces(element);/*  w w  w  .  ja  va2 s  . c  o m*/
    // verify remotion
    assertFalse(element.getNamespacePrefixes().hasNext());
    // attributes should still be there
    // qualified attributes
    assertEquals("0.1lb", element.getAttributeNS("urn:example:produce", "lettuce"));
    assertEquals("0.25lb", element.getAttributeNS("urn:example:fish", "fillet"));
    // local attribute
    assertEquals("1200", element.getAttribute("time"));
}

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.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//from w ww.j a  va 2s.  c o m
 * @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());
    }
}