javax.xml.soap.SOAPElement Java Examples

The following examples show how to use javax.xml.soap.SOAPElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SaajEmptyNamespaceTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
 
Example #2
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
 
Example #3
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
 
Example #4
Source File: SaajEmptyNamespaceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
 
Example #5
Source File: SaajEmptyNamespaceTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
 
Example #6
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
 
Example #7
Source File: ElementImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected String getSOAPNamespace() {
    String soapNamespace = null;

    SOAPElement antecedent = this;
    while (antecedent != null) {
        Name antecedentName = antecedent.getElementName();
        String antecedentNamespace = antecedentName.getURI();

        if (NameImpl.SOAP11_NAMESPACE.equals(antecedentNamespace)
            || NameImpl.SOAP12_NAMESPACE.equals(antecedentNamespace)) {

            soapNamespace = antecedentNamespace;
            break;
        }

        antecedent = antecedent.getParentElement();
    }

    return soapNamespace;
}
 
Example #8
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
 
Example #9
Source File: MustUnderstandHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean handleMessage(SOAPMessageContext cxt) {
	Boolean outbound = (Boolean) cxt.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

	if (outbound.booleanValue()) {
		SOAPMessage message = cxt.getMessage();
		
		try {
			SOAPHeader header = message.getSOAPHeader();
			if(header != null) {
				Iterator<SOAPElement> it = header.getChildElements(WSSE);
				while(it.hasNext()) {
					SOAPElement el = (SOAPElement)it.next();
					el.removeAttributeNS(message.getSOAPPart().getEnvelope().getNamespaceURI(), "mustUnderstand");
					LOG.debug("Recipe hook: The mustunderstand in security header has succesfully been removed");
				}
				
				message.saveChanges();
			}
		} catch (SOAPException e) {
			throw SecurableSoapMessage.newSOAPFaultException("Recipe hook problem: " + e.getMessage(), e);
		}

	}

	return true;
}
 
Example #10
Source File: Fault1_2Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Iterator<String> getFaultReasonTexts() throws SOAPException {
    // Fault Reason has similar semantics as faultstring
    if (this.faultStringElement == null)
        findReasonElement();
    Iterator eachTextElement =
        this.faultStringElement.getChildElements(textName);
    List<String> texts = new ArrayList<>();
    while (eachTextElement.hasNext()) {
        SOAPElement textElement = (SOAPElement) eachTextElement.next();
        Locale thisLocale = getLocale(textElement);
        if (thisLocale == null) {
            log.severe("SAAJ0431.ver1_2.xml.lang.missing");
            throw new SOAPExceptionImpl("\"xml:lang\" attribute is not present on the Text element");
        }
        texts.add(textElement.getValue());
    }
    if (texts.isEmpty()) {
        log.severe("SAAJ0434.ver1_2.text.element.not.present");
        throw new SOAPExceptionImpl("env:Text must be present inside env:Reason");
    }
    return texts.iterator();
}
 
Example #11
Source File: ElementImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected SOAPElement replaceElementWithSOAPElement(
    Element element,
    ElementImpl copy) {

    Iterator<Name> eachAttribute = getAllAttributesFrom(element);
    while (eachAttribute.hasNext()) {
        Name name = eachAttribute.next();
        copy.addAttributeBare(name, getAttributeValueFrom(element, name));
    }

    Iterator<Node> eachChild = getChildElementsFromDOM(element);
    while (eachChild.hasNext()) {
        Node nextChild = eachChild.next();
        copy.insertBefore(nextChild, null);
    }

    Node parent = soapDocument.find(element.getParentNode());
    if (parent != null) {
        parent.replaceChild(copy, element);
    } // XXX else throw an exception?

    return copy;
}
 
Example #12
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
 
Example #13
Source File: Adsv5XTeeServiceImpl.java    From j-road with Apache License 2.0 6 votes vote down vote up
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
  callback.doWithMessage(message);
  try {
    SaajSoapMessage saajMessage = (SaajSoapMessage) message;
    SOAPMessage soapmess = saajMessage.getSaajMessage();
    SOAPEnvelope env = soapmess.getSOAPPart().getEnvelope();
    env.addNamespaceDeclaration("xro", "http://x-road.ee/xsd/x-road.xsd");
    Iterator headers = env.getHeader().getChildElements();
    while (headers.hasNext()) {
      SOAPElement header = (SOAPElement) headers.next();
      if (header.getNamespaceURI().equalsIgnoreCase("http://x-rd.net/xsd/xroad.xsd")) {
        String localHeaderName = header.getLocalName();
        QName qName = new QName("http://x-road.ee/xsd/x-road.xsd", localHeaderName, "xro");
        header.setElementQName(qName);
      }
    }
  } catch (SOAPException e) {
    throw new RuntimeException(e);
  }

}
 
Example #14
Source File: FaultElement1_2Impl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public SOAPElement addAttribute(QName name, String value)
    throws SOAPException {
    if (name.getLocalPart().equals("encodingStyle")
        && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
        setEncodingStyle(value);
    }
    return super.addAttribute(name, value);
}
 
Example #15
Source File: FaultElement1_1Impl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPElement setElementQName(QName newName) throws SOAPException {
    if (!isStandardFaultElement()) {
        FaultElement1_1Impl copy =
            new FaultElement1_1Impl((SOAPDocumentImpl) getOwnerDocument(), newName);
        return replaceElementWithSOAPElement(this,copy);
    } else {
        return super.setElementQName(newName);
    }
}
 
Example #16
Source File: Fault1_2Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPElement addAttribute(QName name, String value)
    throws SOAPException {
    if (name.getLocalPart().equals("encodingStyle")
        && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
        setEncodingStyle(value);
    }
    return super.addAttribute(name, value);
}
 
Example #17
Source File: ConsumerGateway.java    From xroad-rest-gateway with European Union Public License 1.1 5 votes vote down vote up
@Override
protected void serializeRequest(ServiceRequest request, SOAPElement soapRequest, SOAPEnvelope envelope) throws SOAPException {
    handleBody(request, soapRequest);
    if (this.requestBody != null && !this.requestBody.isEmpty()) {
        handleAttachment(request, soapRequest, envelope, this.requestBody);
    }
}
 
Example #18
Source File: ConsumerGateway.java    From xroad-rest-gateway with European Union Public License 1.1 5 votes vote down vote up
protected void handleBody(ServiceRequest request, SOAPElement soapRequest) throws SOAPException {
    if (this.resourceId != null && !this.resourceId.isEmpty()) {
        logger.debug("Add resourceId : \"{}\".", this.resourceId);
        soapRequest.addChildElement("resourceId").addTextNode(this.resourceId);
    }
    Map<String, String[]> params = (Map<String, String[]>) request.getRequestData();
    for (Map.Entry<String, String[]> entry : params.entrySet()) {
        String key = entry.getKey();
        String[] arr = entry.getValue();
        for (String value : arr) {
            logger.debug("Add parameter : \"{}\" -> \"{}\".", key, value);
            soapRequest.addChildElement(key).addTextNode(value);
        }
    }
}
 
Example #19
Source File: SaajStaxWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Flushes state of this element to the {@code target} element.
 *
 * <p>
 * If this element is initialized then it is added with all the namespace declarations and attributes
 * to the {@code target} element as a child. The state of this element is reset to uninitialized.
 * The newly added element object is returned.
 * </p>
 * <p>
 * If this element is not initialized then the {@code target} is returned immediately, nothing else is done.
 * </p>
 *
 * @param target target element
 * @return {@code target} or new element
 * @throws XMLStreamException on error
 */
public SOAPElement flushTo(final SOAPElement target) throws XMLStreamException {
    try {
        if (this.localName != null) {
            // add the element appropriately (based on namespace declaration)
            final SOAPElement newElement;
            if (this.namespaceUri == null) {
                // add element with inherited scope
                newElement = target.addChildElement(this.localName);
            } else if (prefix == null) {
                newElement = target.addChildElement(new QName(this.namespaceUri, this.localName));
            } else {
                newElement = target.addChildElement(this.localName, this.prefix, this.namespaceUri);
            }
            // add namespace declarations
            for (NamespaceDeclaration namespace : this.namespaceDeclarations) {
                target.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri);
            }
            // add attribute declarations
            for (AttributeDeclaration attribute : this.attributeDeclarations) {
                addAttibuteToElement(newElement,
                        attribute.prefix, attribute.namespaceUri, attribute.localName, attribute.value);
            }
            // reset state
            this.reset();

            return newElement;
        } else {
            return target;
        }
        // else after reset state -> not initialized
    } catch (SOAPException e) {
        throw new XMLStreamException(e);
    }
}
 
Example #20
Source File: FaultElement1_2Impl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public SOAPElement addAttribute(Name name, String value)
    throws SOAPException {
    if (name.getLocalName().equals("encodingStyle")
        && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
        setEncodingStyle(value);
    }
    return super.addAttribute(name, value);
}
 
Example #21
Source File: JaxWsHandler.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * @see SoapClientHandler#setHeader(Object, String, String, Object)
 */
@Override
public void setHeader(BindingProvider soapClient, String namespace, String headerName,
    Object headerValue) {
  if (headerValue instanceof SOAPElement) {
    getContextHandlerFromClient(soapClient).addHeader(namespace, headerName,
        (SOAPElement) headerValue);
  } else {
    throw new ServiceException("Unexpected SOAP header given for JAX-WS binding. Given "
        + "object of class \"" + headerValue.getClass().toString() + "\" but expecting "
        + "object of class \"" + SOAPElement.class + "\".", null);
  }
}
 
Example #22
Source File: TextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setParentElement(SOAPElement parent) throws SOAPException {
    if (parent == null) {
        log.severe("SAAJ0126.impl.cannot.locate.ns");
        throw new SOAPException("Cannot pass NULL to setParentElement");
    }
    ((ElementImpl) parent).addNode(this);
}
 
Example #23
Source File: SOAPHandlerInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageContext createProtocolMessageContext(SoapMessage message) {
    SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);

    Exchange exch = message.getExchange();
    setupBindingOperationInfo(exch, sm);
    SOAPMessage msg = sm.getMessage();
    if (msg != null) {
        try {
            List<SOAPElement> params = new ArrayList<>();
            message.put(MessageContext.REFERENCE_PARAMETERS, params);
            SOAPHeader head = SAAJUtils.getHeader(msg);
            if (head != null) {
                Iterator<Node> it = CastUtils.cast(head.getChildElements());
                while (it != null && it.hasNext()) {
                    Node nd = it.next();
                    if (nd instanceof SOAPElement) {
                        SOAPElement el = (SOAPElement) nd;
                        if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")
                                && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME,
                                "IsReferenceParameter"))
                                || Boolean.parseBoolean(el.getAttributeNS(Names.WSA_NAMESPACE_NAME,
                                "IsReferenceParameter")))) {
                            params.add(el);
                        }
                    }
                }
            }
            if (isRequestor(message) && msg.getSOAPPart().getEnvelope().getBody() != null
                    && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
                return null;
            }
        } catch (SOAPException e) {
            throw new Fault(e);
        }
    }

    return sm;
}
 
Example #24
Source File: WsAddressingHandlerV200508.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
private void generateRelateToElement(SOAPHeader soapHeader, WsAddressingRelatesTo relateTo) throws SOAPException {
   SOAPElement relateToElement = soapHeader.addChildElement(RELATESTO);
   if (relateTo.getRelationshipType() != null && !relateTo.getRelationshipType().isEmpty()) {
      relateToElement.addAttribute(RELATIONSHIPTYPE, relateTo.getRelationshipType());
   }

   if (relateTo.getRelationshipType() != null) {
      relateToElement.setTextContent(relateTo.getReleatesTo().toString());
   }

}
 
Example #25
Source File: Fault1_1Impl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public SOAPElement addChildElement(SOAPElement element)
    throws SOAPException {
    String localName = element.getLocalName();
    if ("Detail".equalsIgnoreCase(localName)) {
        if (hasDetail()) {
            log.severe("SAAJ0305.ver1_2.detail.exists.error");
            throw new SOAPExceptionImpl("Cannot add Detail, Detail already exists");
        }
    }
    return super.addChildElement(element);
}
 
Example #26
Source File: TextImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setParentElement(SOAPElement parent) throws SOAPException {
    if (parent == null) {
        log.severe("SAAJ0126.impl.cannot.locate.ns");
        throw new SOAPException("Cannot pass NULL to setParentElement");
    }
    ((ElementImpl) parent).addNode(this);
}
 
Example #27
Source File: SaajEmptyNamespaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testAddElementToGlobalNsNoDeclarations() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
 
Example #28
Source File: AbstractTypeTestClient3.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void assertEquals(Element elA, Element elB) throws Exception {
    if (elA instanceof SOAPElement && elB instanceof SOAPElement) {
        SOAPElement soapA = (SOAPElement)elA;
        SOAPElement soapB = (SOAPElement)elB;
        Assert.assertEquals("StructWithAny soap element names don't match",
            soapA.getElementName(), soapB.getElementName());
        Assert.assertEquals("StructWithAny soap element text nodes don't match",
            soapA.getValue(), soapB.getValue());

        Iterator<?> itExp = soapA.getChildElements();
        Iterator<?> itGen = soapB.getChildElements();
        while (itExp.hasNext()) {
            if (!itGen.hasNext()) {
                fail("Incorrect number of child elements inside any");
            }
            Object objA = itExp.next();
            Object objB = itGen.next();
            if (objA instanceof SOAPElement) {
                if (objB instanceof SOAPElement) {
                    assertEquals((SOAPElement)objA, (SOAPElement)objB);
                } else {
                    fail("No matching soap element.");
                }
            }
        }
    }
}
 
Example #29
Source File: MUTube.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void addHeader(Message m, Set<QName> notUnderstoodHeaders) throws SOAPException {
    for (QName qname : notUnderstoodHeaders) {
        SOAPElement soapEl = SOAP_12.getSOAPFactory().createElement(MU_HEADER_DETAIL);
        soapEl.addNamespaceDeclaration("abc", qname.getNamespaceURI());
        soapEl.setAttribute("qname", "abc:" + qname.getLocalPart());
        Header header = new DOMHeader<Element>(soapEl);
        m.getHeaders().add(header);
    }
}
 
Example #30
Source File: SaajEmptyNamespaceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testAddElementToNullNsNoDeclarations() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}