Example usage for javax.xml.soap SOAPElement addChildElement

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

Introduction

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

Prototype

public SOAPElement addChildElement(SOAPElement element) throws SOAPException;

Source Link

Document

Add a SOAPElement as a child of this SOAPElement instance.

Usage

From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java

@SuppressWarnings("unchecked")
protected void getResponse(Document query, SOAPMessage responseMessage, SOAPMessage requestMessage)
        throws Exception {
    XTeeHeader header = metaService ? null : parseXteeHeader(requestMessage);

    // Build request message
    List<XTeeAttachment> attachments = new ArrayList<XTeeAttachment>();
    for (Iterator<AttachmentPart> i = requestMessage.getAttachments(); i.hasNext();) {
        AttachmentPart a = i.next();
        attachments.add(new XTeeAttachment(a.getContentId(), a.getContentType(), a.getRawContentBytes()));
    }//from   w  w  w. java 2  s  .c o m
    XTeeMessage<Document> request = new BeanXTeeMessage<Document>(header, query, attachments);

    SOAPElement teenusElement = createXteeMessageStructure(requestMessage, responseMessage);
    if (XRoadProtocolVersion.V2_0 == version) {
        if (!metaService) {
            copyParing(query, teenusElement);
        }
        teenusElement = teenusElement.addChildElement("keha");
    }

    // Build response message
    XTeeMessage<Element> response = new BeanXTeeMessage<Element>(header, teenusElement,
            new ArrayList<XTeeAttachment>());

    // Run logic
    invokeInternalEx(request, response, requestMessage, responseMessage);

    // Add any attachments
    for (XTeeAttachment a : response.getAttachments()) {
        AttachmentPart attachment = responseMessage.createAttachmentPart(a.getDataHandler());
        attachment.setContentId("<" + a.getCid() + ">");
        responseMessage.addAttachmentPart(attachment);
    }
}

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

@Validated
@Test//from  ww w  . j  a  va 2s  .  com
public void testRemoveContents() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addChildElement(new QName("child1"));
    element.addChildElement(new QName("child2"));
    element.removeContents();
    assertNull(element.getFirstChild());
}

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

@Validated
@Test//from ww  w  .  ja v  a  2  s  .c om
public void testGetParentElement() throws Exception {
    SOAPElement parent = saajUtil.createSOAPElement(null, "parent", null);
    SOAPElement child = parent.addChildElement(new QName("child"));
    assertSame(parent, child.getParentElement());
}

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

@Validated
@Test//from  w  ww  .  ja  v a  2 s .c  om
public void testGetChildElementsByQName() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement a1 = element.addChildElement(new QName("urn:ns1", "a"));
    element.addChildElement(new QName("urn:ns2", "a"));
    SOAPElement a2 = element.addChildElement(new QName("urn:ns1", "a", "ns1"));
    element.addChildElement(new QName("urn:ns1", "b"));
    Iterator it = element.getChildElements(new QName("urn:ns1", "a"));
    assertTrue(it.hasNext());
    assertSame(a1, it.next());
    assertTrue(it.hasNext());
    assertSame(a2, it.next());
    assertFalse(it.hasNext());
}

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

@Validated
@Test/*  w w w.  ja  va  2s. c  o m*/
public void testGetChildElementsByName() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    SOAPElement a1 = element.addChildElement(new QName("urn:ns1", "a"));
    element.addChildElement(new QName("urn:ns2", "a"));
    SOAPElement a2 = element.addChildElement(new QName("urn:ns1", "a", "ns1"));
    element.addChildElement(new QName("urn:ns1", "b"));
    Iterator it = element.getChildElements(a1.getElementName());
    assertTrue(it.hasNext());
    assertSame(a1, it.next());
    assertTrue(it.hasNext());
    assertSame(a2, it.next());
    assertFalse(it.hasNext());
}

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

/**
 * Tests the behavior of {@link SOAPElement#getChildElements()} when there are text nodes among
 * the children of the element. In contrast to what the name of the method suggests, they will
 * also be returned by the iterator.//from w  ww  .ja v a  2  s  .c o  m
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetChildElementsWithTextNodes() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addTextNode("foo");
    element.addChildElement(new QName("child"));
    element.addTextNode("bar");
    Iterator it = element.getChildElements();
    assertTrue(it.hasNext());
    assertTrue(it.next() instanceof Text);
    assertTrue(it.hasNext());
    assertTrue(it.next() instanceof SOAPElement);
    assertTrue(it.hasNext());
    assertTrue(it.next() instanceof Text);
    assertFalse(it.hasNext());
}

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

@Validated
@Test/*from   ww  w  .ja  v  a2  s .c  om*/
public void testGetNamespaceURIForPrefixDeclaredOnParent() throws Exception {
    SOAPElement parent = saajUtil.createSOAPElement("urn:ns", "test", "p");
    parent.addNamespaceDeclaration("p", "urn:ns");
    SOAPElement child = parent.addChildElement(new QName("child"));
    assertEquals("urn:ns", child.getNamespaceURI("p"));
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, String listName,
        Map<String, String> params) throws SOAPException {
    Name nPara = envelope.createName(typeName, "", XMLA_URI);
    SOAPElement eType = eParent.addChildElement(nPara);
    nPara = envelope.createName(listName, "", XMLA_URI);
    SOAPElement eList = eType.addChildElement(nPara);
    if (params == null) {
        return;//  w w w.j  ava 2s  .com
    }
    for (Iterator<Map.Entry<String, String>> entryIt = params.entrySet().iterator(); entryIt.hasNext();) {
        Map.Entry<String, String> entry = entryIt.next();
        String tag = entry.getKey();
        String value = entry.getValue();
        nPara = envelope.createName(tag, "", XMLA_URI);
        SOAPElement eTag = eList.addChildElement(nPara);
        eTag.addTextNode(value);
    }
}

From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java

protected SOAPMessage createQueryMessage() {
    String queryStr = getQueryString();

    if (log.isDebugEnabled()) {
        log.debug("MDX query: " + queryStr);
    }/*from  w  ww.  j  a v a2  s  .  c  o  m*/

    try {
        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage message = mf.createMessage();

        MimeHeaders mh = message.getMimeHeaders();
        mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\"");

        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        SOAPBody body = envelope.getBody();
        Name nEx = envelope.createName("Execute", "", XMLA_URI);

        SOAPElement eEx = body.addChildElement(nEx);

        // add the parameters

        // COMMAND parameter
        // <Command>
        // <Statement>queryStr</Statement>
        // </Command>
        Name nCom = envelope.createName("Command", "", XMLA_URI);
        SOAPElement eCommand = eEx.addChildElement(nCom);
        Name nSta = envelope.createName("Statement", "", XMLA_URI);
        SOAPElement eStatement = eCommand.addChildElement(nSta);
        eStatement.addTextNode(queryStr);

        // <Properties>
        // <PropertyList>
        // <DataSourceInfo>dataSource</DataSourceInfo>
        // <Catalog>catalog</Catalog>
        // <Format>Multidimensional</Format>
        // <AxisFormat>TupleFormat</AxisFormat>
        // </PropertyList>
        // </Properties>
        Map<String, String> paraList = new HashMap<String, String>();
        String datasource = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_DATASOURCE);
        paraList.put("DataSourceInfo", datasource);
        String catalog = (String) getParameterValue(JRXmlaQueryExecuterFactory.PARAMETER_XMLA_CATALOG);
        paraList.put("Catalog", catalog);
        paraList.put("Format", "Multidimensional");
        paraList.put("AxisFormat", "TupleFormat");
        addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
        message.saveChanges();

        if (log.isDebugEnabled()) {
            log.debug("XML/A query message: \n" + prettyPrintSOAP(message.getSOAPPart().getEnvelope()));
        }

        return message;
    } catch (SOAPException e) {
        throw new JRRuntimeException(e);
    }
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java

protected void addParameterList(SOAPEnvelope envelope, SOAPElement eParent, String typeName, String listName,
        Map params) throws SOAPException {
    Name nPara = envelope.createName(typeName, "", XMLA_URI);
    SOAPElement eType = eParent.addChildElement(nPara);
    nPara = envelope.createName(listName, "", XMLA_URI);
    SOAPElement eList = eType.addChildElement(nPara);
    if (params == null)
        return;//from  w  w w. j  a v  a 2  s. c  o  m

    Iterator it = params.keySet().iterator();
    while (it.hasNext()) {
        String tag = (String) it.next();
        String value = (String) params.get(tag);
        nPara = envelope.createName(tag, "", XMLA_URI);
        SOAPElement eTag = eList.addChildElement(nPara);
        eTag.addTextNode(value);
    }
}