Example usage for javax.xml.soap SOAPElement getPrefix

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

Introduction

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

Prototype

public String getPrefix();

Source Link

Document

The namespace prefix of this node, or null if it is unspecified.

Usage

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

public void testCopyChildNodes_soapDom() throws Exception {
    String xml = "<lunch xmlns:produce='urn:example:produce'" + " xmlns='urn:example:meal'>"
            + " <time>1200</time>" + " <produce:lettuce>0.1lb</produce:lettuce>"
            + " <fish:fillet xmlns:fish='urn:example:fish'>0.25lb</fish:fillet>" + " <padding xmlns=''/>"
            + "</lunch>";
    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.copyChildNodes(target, source);

    // qualified, prefixless element
    SOAPElement time = SoapUtil.getElement(target, "urn:example:meal", "time");
    assertEquals(SoapUtil.DEFAULT_NAMESPACE_PREFIX, time.getPrefix());
    // qualified, prefixed element
    SOAPElement lettuce = SoapUtil.getElement(target, "urn:example:produce", "lettuce");
    assertEquals("produce", lettuce.getPrefix());
    // parent qualified, prefixed element
    SOAPElement fillet = SoapUtil.getElement(target, "urn:example:fish", "fillet");
    assertEquals("fish", fillet.getPrefix());
    // local element
    SOAPElement padding = SoapUtil.getElement(target, "padding");
    assertNull(padding.getPrefix());//w  ww.jav  a  2 s  . c  om
    assertNull(padding.getNamespaceURI());
}

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

public void testCopyChildElement_soapDom() throws Exception {
    String xml = "<meal:lunch xmlns:meal='urn:example:meal'>" + " <padding />" + "</meal:lunch>";
    Element source = XmlUtil.parseText(xml);
    SOAPMessage message = MessageFactory.newInstance().createMessage();
    SOAPElement parent = message.getSOAPBody().addChildElement("lunch", "meal", "urn:example:meal");
    // perform the copy
    SoapUtil.copyChildElement(parent, XmlUtil.getElement(source, "padding"));
    SOAPElement padding = SoapUtil.getElement(parent, "padding");

    // unqualified element
    assertNull(padding.getPrefix());

    // reload/*from w  w  w.  j a  v a 2 s .  c  om*/
    message = writeAndRead(message);
    parent = SoapUtil.getElement(message.getSOAPBody(), "urn:example:meal", "lunch");
    padding = SoapUtil.getElement(parent, "padding");

    // unqualified element
    assertNull(padding.getPrefix());
}

From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java

/**
 * Checks whether we can find a SAAJ 1.2 implementation, being aware of the broken WebLogic 9 SAAJ implementation.
 * <p/>//from ww  w. j a v  a 2s . c  o m
 * WebLogic 9 does implement SAAJ 1.2, but throws UnsupportedOperationExceptions when a SAAJ 1.2 method is called.
 */
private static boolean isSaaj12(SOAPElement soapElement) {
    try {
        Method m = soapElement.getClass().getMethod("getPrefix", new Class[0]);
        // we might be using the SAAJ 1.2 API, while the impl is 1.1
        // let's see if the method is not abstract
        if (Modifier.isAbstract(m.getModifiers())) {
            logger.warn("Detected SAAJ API version 1.2, while implementation provides version 1.1. "
                    + "Please replace the SAAJ API jar with a version that corresponds to your runtime "
                    + "implementation (which might be provided by your app server).");
            return false;
        } else {
            soapElement.getPrefix();
            return true;
        }
    } catch (NoSuchMethodException e) {
        // getPrefix not found
        return false;
    } catch (UnsupportedOperationException ex) {
        // getPrefix results in UOE, let's see if we're dealing with WL 9
        if (WEBLOGIC_9_SAAJ_EXCEPTION_MESSAGE.equals(ex.getMessage())) {
            return false;
        } else {
            throw ex;
        }
    }
}