Example usage for javax.xml.soap SOAPElement getNamespaceURI

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

Introduction

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

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:be.fedict.eid.idp.protocol.ws_federation.sts.WSSecuritySoapHandler.java

private void handleInboundMessage(SOAPMessageContext context) throws SOAPException {
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (null == soapHeader) {
        return;//from   ww w .j av a 2 s  .co  m
    }
    Iterator<SOAPHeaderElement> headerIterator = soapHeader.examineAllHeaderElements();
    while (headerIterator.hasNext()) {
        SOAPHeaderElement soapHeaderElement = headerIterator.next();
        if (false == WSTrustConstants.WS_SECURITY_NAMESPACE.equals(soapHeaderElement.getNamespaceURI())) {
            continue;
        }
        if (false == "Security".equals(soapHeaderElement.getLocalName())) {
            continue;
        }
        Iterator<SOAPElement> securityElementIterator = soapHeaderElement.getChildElements();
        while (securityElementIterator.hasNext()) {
            SOAPElement securityElement = securityElementIterator.next();
            if (false == WSTrustConstants.SAML2_NAMESPACE.equals(securityElement.getNamespaceURI())) {
                continue;
            }
            if (false == "Assertion".equals(securityElement.getLocalName())) {
                continue;
            }
            LOG.debug("putting SAML token on JAX-WS context");
            context.put(SAML_TOKEN_CONTEXT_ATTRIBUTE, securityElement);
            context.setScope(SAML_TOKEN_CONTEXT_ATTRIBUTE, Scope.APPLICATION);
        }
    }
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test/*from  w w  w  .  j a va2s . co m*/
public void testAddChildElementFromLocalNameAndPrefix() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addNamespaceDeclaration("p", "urn:test");
    SOAPElement child = element.addChildElement("child", "p");
    assertEquals("urn:test", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("child", child.getLocalName());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test//from w  w  w  . j  av  a 2s.  c om
public void testAddChildElementWithDeclaredNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns");
    SOAPElement child = element.addChildElement("test", "p", "urn:ns");
    assertEquals("urn:ns", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("test", child.getLocalName());
    assertEquals(0, child.getAttributes().getLength());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test//from   ww w  .  j  av a2 s  . c om
public void testAddChildElementWithUndeclaredNamespace() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement child = element.addChildElement("test", "p", "urn:ns");
    assertEquals("urn:ns", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("test", child.getLocalName());
    Attr nsDecl = child.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p");
    assertNotNull(nsDecl);
    assertEquals("urn:ns", nsDecl.getValue());
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private void addAttributes(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context,
        NamedNodeMap attributes, SOAPElement soapElement) throws SOAPException {
    SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild();
    String targetNamespace = soapMethodResponseElement.getNamespaceURI();
    String prefix = soapMethodResponseElement.getPrefix();

    int len = attributes.getLength();
    Attr attribute;/*w w  w .ja  v  a  2 s .c om*/
    for (int i = 0; i < len; i++) {
        attribute = (Attr) attributes.item(i);
        String attributeName = attribute.getName();
        String attributeValue = attribute.getNodeValue();
        String attributeNsUri = attribute.getNamespaceURI();
        String attributePrefix = getPrefix(context.projectName, attributeNsUri);

        XmlSchemaAttribute xmlSchemaAttribute = getXmlSchemaAttributeByName(context.projectName, attributeName);
        boolean isGlobal = xmlSchemaAttribute != null;
        if (isGlobal) {
            attributeNsUri = xmlSchemaAttribute.getQName().getNamespaceURI();
            attributePrefix = getPrefix(context.projectName, attributeNsUri);
        }

        if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) {
            if (attributePrefix == null) {
                soapElement.addAttribute(soapEnvelope.createName(attributeName, prefix, targetNamespace),
                        attributeValue);
            } else {
                soapElement.addAttribute(
                        soapEnvelope.createName(attributeName, attributePrefix, attributeNsUri),
                        attributeValue);
            }
        } else {
            soapElement.addAttribute(soapEnvelope.createName(attributeName), attributeValue);
        }
    }
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private void addElement(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context,
        Element elementToAdd, SOAPElement soapElement) throws SOAPException {
    SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild();
    String targetNamespace = soapMethodResponseElement.getNamespaceURI();
    String prefix = soapMethodResponseElement.getPrefix();

    String nodeType = elementToAdd.getAttribute("type");
    SOAPElement childSoapElement = soapElement;

    boolean elementAdded = true;
    boolean bTable = false;

    if (nodeType.equals("table")) {
        bTable = true;/*w  ww.  j  a  va 2 s  .  c  o m*/
        /*childSoapElement = soapElement.addChildElement("ArrayOf" + context.transactionName + "_" + tableName + "_Row", "");
                
           if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) {
              childSoapElement.addAttribute(soapEnvelope.createName("xsi:type"), "soapenc:Array");
           }*/
        childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName());
    } else if (nodeType.equals("row")) {
        /*String elementType = context.transactionName + "_" + tableName + "_Row";
        childSoapElement = soapElement.addChildElement(elementType, "");*/
        childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName());
    } else if (nodeType.equals("attachment")) {
        childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName());

        if (context.requestedObject instanceof AbstractHttpTransaction) {
            AttachmentDetails attachment = AttachmentManager.getAttachment(elementToAdd);
            if (attachment != null) {
                byte[] raw = attachment.getData();
                if (raw != null)
                    childSoapElement.addTextNode(Base64.encodeBase64String(raw));
            }

            /* DON'T WORK YET *\
            AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), elementToAdd.getAttribute("content-type"));
            ap.setContentId(key);
            ap.setContentLocation(elementToAdd.getAttribute("url"));
            responseMessage.addAttachmentPart(ap);
            \* DON'T WORK YET */
        }
    } else {
        String elementNodeName = elementToAdd.getNodeName();
        String elementNodeNsUri = elementToAdd.getNamespaceURI();
        String elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri);

        XmlSchemaElement xmlSchemaElement = getXmlSchemaElementByName(context.projectName, elementNodeName);
        boolean isGlobal = xmlSchemaElement != null;
        if (isGlobal) {
            elementNodeNsUri = xmlSchemaElement.getQName().getNamespaceURI();
            elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri);
        }

        // ignore original SOAP message response elements
        //         if ((elementNodeName.toUpperCase().indexOf("SOAP-ENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAP-ENV:") != -1)) ||
        //            (elementNodeName.toUpperCase().indexOf("SOAPENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAPENV:") != -1)) ||
        //            (elementNodeName.toUpperCase().indexOf("NS0:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1))) {
        //            elementAdded = false;
        //         }
        if ("http://schemas.xmlsoap.org/soap/envelope/".equals(elementToAdd.getNamespaceURI())
                || "http://schemas.xmlsoap.org/soap/envelope/"
                        .equals(elementToAdd.getParentNode().getNamespaceURI())
                || elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1
                || elementNodeName.toUpperCase().indexOf("NS0:") != -1) {
            elementAdded = false;
        } else {
            if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) {
                if (elementNodePrefix == null) {
                    childSoapElement = soapElement
                            .addChildElement(soapEnvelope.createName(elementNodeName, prefix, targetNamespace));
                } else {
                    childSoapElement = soapElement.addChildElement(
                            soapEnvelope.createName(elementNodeName, elementNodePrefix, elementNodeNsUri));
                }
            } else {
                childSoapElement = soapElement.addChildElement(elementNodeName);
            }
        }
    }

    if (elementAdded && elementToAdd.hasAttributes()) {
        addAttributes(responseMessage, soapEnvelope, context, elementToAdd.getAttributes(), childSoapElement);
    }

    if (elementToAdd.hasChildNodes()) {
        NodeList childNodes = elementToAdd.getChildNodes();
        int len = childNodes.getLength();

        if (bTable) {
            /*if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) {
               childSoapElement.addAttribute(soapEnvelope.createName("soapenc:arrayType"), context.projectName+"_ns:" + context.transactionName + "_" + tableName + "_Row[" + (len - 1) + "]");
            }*/
        }

        org.w3c.dom.Node node;
        Element childElement;
        for (int i = 0; i < len; i++) {
            node = childNodes.item(i);
            switch (node.getNodeType()) {
            case org.w3c.dom.Node.ELEMENT_NODE:
                childElement = (Element) node;
                addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement);
                break;
            case org.w3c.dom.Node.CDATA_SECTION_NODE:
            case org.w3c.dom.Node.TEXT_NODE:
                String text = node.getNodeValue();
                text = (text == null) ? "" : text;
                childSoapElement.addTextNode(text);
                break;
            default:
                break;
            }
        }

        /*org.w3c.dom.Node node;
        Element childElement;
        for (int i = 0 ; i < len ; i++) {
           node = childNodes.item(i);
           if (node instanceof Element) {
              childElement = (Element) node;
              addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement);
           }
           else if (node instanceof CDATASection) {
              Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.CDATA_SECTION_NODE);
              String text = textNode.getNodeValue();
              if (text == null) {
          text = "";
              }
              childSoapElement.addTextNode(text);
           }
           else {
              Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.TEXT_NODE);
              if (textNode != null) {
          String text = textNode.getNodeValue();
          if (text == null) {
             text = "";
          }
          childSoapElement.addTextNode(text);
              }
           }
        }*/
    }
}

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

/**
 * Create child SOAPElement/*from w ww .  j av a 2 s  .  c  om*/
 *
 * @param parent SOAPElement
 * @param name   Name
 * @return
 */
protected SOAPElement createElement(SOAPElement parent, QName qName) throws SOAPException {
    SOAPElement child;
    if (parent instanceof SOAPEnvelope) {
        if (qName.getNamespaceURI().equals(parent.getNamespaceURI())) {
            if (qName.getLocalPart().equals("Body")) {
                child = ((SOAPEnvelope) parent).addBody();
            } else {
                child = ((SOAPEnvelope) parent).addHeader();
            }
        } else {
            child = parent.addChildElement(qName);
        }
    } else if (parent instanceof SOAPBody) {
        if (qName.getNamespaceURI().equals(parent.getNamespaceURI()) && qName.getLocalPart().equals("Fault")) {
            child = ((SOAPBody) parent).addFault();
        } else {
            child = ((SOAPBody) parent).addBodyElement(qName);
        }
    } else if (parent instanceof SOAPHeader) {
        child = ((SOAPHeader) parent).addHeaderElement(qName);
    } else if (parent instanceof SOAPFault) {
        // This call assumes that the addChildElement implementation
        // is smart enough to add "Detail" or "SOAPFaultElement" objects.
        child = parent.addChildElement(qName);
    } else if (parent instanceof Detail) {
        child = ((Detail) parent).addDetailEntry(qName);
    } else {
        child = parent.addChildElement(qName);
    }

    return child;
}

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

private void _fixFaultElements(SOAPEnvelope env) {
    try {//  w  w  w .jav  a  2s  .  co m
        // If we have a SOAP 1.2 envelope, then there's nothing to do.
        if (env.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            return;
        }

        SOAPBody body = env.getBody();
        if (body != null && !body.hasFault()) {
            if (log.isDebugEnabled()) {
                log.debug("No fault found.  No conversion necessary.");
            }
            return;
        } else if (body != null && body.hasFault()) {
            if (log.isDebugEnabled()) {
                log.debug("A fault was found.  Converting the fault child elements to SOAP 1.1 format");
            }

            SOAPFault fault = body.getFault();

            Iterator itr = fault.getChildElements();
            while (itr.hasNext()) {
                SOAPElement se = (SOAPElement) itr.next();
                if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: faultcode");
                    }
                    // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue object, so we have to 
                    // get that and add it as a text node under the original element.
                    Node value = se.getFirstChild();
                    if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
                        org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
                        ElementImpl e = valueElement.getElement();
                        String content = e.getText();

                        SOAPElement child = fault.addChildElement(
                                new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME));
                        child.addTextNode(content);

                        se.detachNode();
                    }
                } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: detail");
                    }
                    se.setElementQName(
                            new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
                } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: faultstring");
                    }
                    se.setElementQName(
                            new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                    // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue object, so we have to 
                    // get that and add it as a text node under the original element.
                    Node value = se.getFirstChild();
                    if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
                        org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
                        ElementImpl e = valueElement.getElement();
                        String content = e.getText();

                        SOAPElement child = fault.addChildElement(
                                new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                        child.addTextNode(content);

                        se.detachNode();
                    }
                }
            }
        }
    } catch (SOAPException e) {
        if (log.isDebugEnabled()) {
            log.debug("An error occured while converting fault elements: " + e.getMessage());
        }
        throw ExceptionFactory.makeWebServiceException(e);
    }
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test//from  w w  w.  j av  a2 s.  c  o m
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/* www  . jav  a  2s  .  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();
    }
}