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:org.codice.ddf.security.interceptor.AnonymousInterceptor.java

private void createIncludeTimestamp(SOAPFactory soapFactory, SOAPElement securityHeader) {
    SOAPElement timestamp = null;
    try {/*from www. j a  v a2s .co m*/
        timestamp = soapFactory.createElement(WSConstants.TIMESTAMP_TOKEN_LN, WSConstants.WSU_PREFIX,
                WSConstants.WSU_NS);
        SOAPElement created = soapFactory.createElement(WSConstants.CREATED_LN, WSConstants.WSU_PREFIX,
                WSConstants.WSU_NS);
        DateTime dateTime = new DateTime();
        created.addTextNode(dateTime.toString());
        SOAPElement expires = soapFactory.createElement(WSConstants.EXPIRES_LN, WSConstants.WSU_PREFIX,
                WSConstants.WSU_NS);
        expires.addTextNode(dateTime.plusMinutes(5).toString());
        timestamp.addChildElement(created);
        timestamp.addChildElement(expires);
        securityHeader.addChildElement(timestamp);
    } catch (SOAPException e) {
        LOGGER.error("Unable to create security timestamp.", e);
    }
}

From source file:org.codice.ddf.security.interceptor.AnonymousInterceptor.java

private void createAddressing(SoapMessage message, SOAPMessage soapMessage, SOAPFactory soapFactory) {

    String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
    AddressingProperties addressingProperties = new AddressingProperties();
    SOAPElement action = null;/*w  w w. j a v  a2  s .c  om*/

    try {
        action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        AttributedURIType attributedString = new AttributedURIType();
        String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION),
                "");
        attributedString.setValue(actionValue);
        addressingProperties.setAction(attributedString);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    SOAPElement messageId = null;
    try {
        messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        String uuid = "urn:uuid:" + UUID.randomUUID().toString();
        messageId.addTextNode(uuid);
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue(uuid);
        addressingProperties.setMessageID(attributedString);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    SOAPElement to = null;
    try {
        to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        endpointReferenceType.setAddress(attributedString);
        addressingProperties.setTo(endpointReferenceType);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    SOAPElement replyTo = null;
    try {
        replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
        replyTo.addChildElement(address);

        soapMessage.getSOAPHeader().addChildElement(messageId);
        soapMessage.getSOAPHeader().addChildElement(action);
        soapMessage.getSOAPHeader().addChildElement(to);
        soapMessage.getSOAPHeader().addChildElement(replyTo);
        message.put(addressingProperty, addressingProperties);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }
}

From source file:org.codice.ddf.security.interceptor.GuestInterceptor.java

private void createAddressing(SoapMessage message, SOAPMessage soapMessage) {
    SOAPFactory soapFactory;/* w  w  w. java  2 s.  c  om*/
    try {
        soapFactory = SOAPFactory.newInstance();
    } catch (SOAPException e) {
        LOGGER.error("Could not create a SOAPFactory.", e);
        return; // can't add anything if we can't create it
    }

    String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
    AddressingProperties addressingProperties = new AddressingProperties();

    try {
        SOAPElement action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        AttributedURIType attributedString = new AttributedURIType();
        String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION),
                "");
        attributedString.setValue(actionValue);
        addressingProperties.setAction(attributedString);
        soapMessage.getSOAPHeader().addChildElement(action);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing action.", e);
    }

    try {
        SOAPElement messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        String uuid = "urn:uuid:" + UUID.randomUUID().toString();
        messageId.addTextNode(uuid);
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue(uuid);
        addressingProperties.setMessageID(attributedString);
        soapMessage.getSOAPHeader().addChildElement(messageId);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing messageId.", e);
    }

    try {
        SOAPElement to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        endpointReferenceType.setAddress(attributedString);
        addressingProperties.setTo(endpointReferenceType);
        soapMessage.getSOAPHeader().addChildElement(to);
    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing to.", e);
    }

    try {
        SOAPElement replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME,
                org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX,
                org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
        replyTo.addChildElement(address);
        soapMessage.getSOAPHeader().addChildElement(replyTo);

    } catch (SOAPException e) {
        LOGGER.error("Unable to add addressing replyTo.", e);
    }
    message.put(addressingProperty, addressingProperties);
}

From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java

private void appendElements(SOAPElement bodyElement, NodeList nlist, SOAPFactory factory) throws SOAPException {
    String prefix = "uddi";
    String uddins = IRegistry.UDDI_V2_NAMESPACE;
    int len = nlist != null ? nlist.getLength() : 0;

    for (int i = 0; i < len; i++) {
        Node node = nlist.item(i);
        short nodeType = node != null ? node.getNodeType() : -100;
        if (Node.ELEMENT_NODE == nodeType) {
            Element el = (Element) node;
            Name name = factory.createName(el.getNodeName(), prefix, uddins);
            SOAPElement attachedEl = bodyElement.addChildElement(name);
            appendAttributes(attachedEl, el.getAttributes(), factory);
            appendElements(attachedEl, el.getChildNodes(), factory);
        } else if (nodeType == Node.TEXT_NODE) {
            bodyElement.addTextNode(node.getNodeValue());
        }/*from  w  ww .jav  a 2  s .c om*/
    }
}

From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java

private SOAPElement getSOAPElement(SOAPBody soapBody, Element elem) {
    String xmlns = IRegistry.UDDI_V2_NAMESPACE;
    SOAPElement soapElement = null;
    SOAPFactory factory = null;//from  w w  w.j  a v a 2s  . com
    try {
        factory = SOAPFactory.newInstance();
        //Go through the element
        String name = elem.getNodeName();
        String nsuri = elem.getNamespaceURI();
        if (nsuri == null)
            nsuri = xmlns;
        soapElement = factory.createElement(name, "ns1", nsuri);
        //Get Attributes
        if (elem.hasAttributes()) {
            NamedNodeMap nnm = elem.getAttributes();
            int len = nnm != null ? nnm.getLength() : 0;
            for (int i = 0; i < len; i++) {
                Node n = nnm.item(i);
                String nodename = n.getNodeName();
                String nodevalue = n.getNodeValue();
                soapElement.addAttribute(factory.createName(nodename), nodevalue);
            }
        } else {
            soapElement.addAttribute(factory.createName("xmlns:ns1"), nsuri);
        }

        NodeList nlist = elem.getChildNodes();
        int len = nlist != null ? nlist.getLength() : 0;

        for (int i = 0; i < len; i++) {
            Node node = nlist.item(i);
            short nodeType = node != null ? node.getNodeType() : -100;
            if (Node.ELEMENT_NODE == nodeType) {
                soapElement.addChildElement(getSOAPElement(soapBody, (Element) node));
            } else if (nodeType == Node.TEXT_NODE) {
                soapElement.addTextNode(node.getNodeValue());
            }

        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return soapElement;
}

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

public static void copyChildElement(SOAPElement parent, Element source) throws SOAPException {
    String localName = source.getLocalName();
    String prefix = source.getPrefix();
    String namespaceURI = source.getNamespaceURI();

    Name targetName;//from   www. j a va 2  s .co m
    SOAPEnvelope envelope = findEnvelope(parent);

    if (prefix == null || prefix.length() == 0) {
        // source has no prefix, distinguish between no namespace and default namespace
        if (namespaceURI == null || namespaceURI.length() == 0) {
            // no namespace
            targetName = envelope.createName(localName);
            if (traceEnabled)
                log.trace("appended element: " + localName);
        } else {
            // default namespace, look for existing prefix at target
            prefix = getPrefix(namespaceURI, parent);

            // no prefix for that namespace?
            if (prefix == null) {
                prefix = XmlUtil.generatePrefix(DEFAULT_NAMESPACE_PREFIX, source);
            }
            // BPEL-195 source maps prefix to another URI?
            else if (!namespaceURI.equals(source.getAttributeNS(BpelConstants.NS_XMLNS, prefix))) {
                prefix = XmlUtil.generatePrefix(prefix, source);
            }

            targetName = envelope.createName(localName, prefix, namespaceURI);
            if (traceEnabled)
                log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName);
        }
    } else {
        // source has prefix
        targetName = envelope.createName(localName, prefix, namespaceURI);
        if (traceEnabled)
            log.trace("added child element: {" + namespaceURI + '}' + prefix + ':' + localName);
    }

    SOAPElement target;
    if (parent instanceof SOAPBody) {
        /*
         * jboss-ws4ee throws ClassCastException upon calling the remote endpoint if child elements
         * other than SOAPBodyElements are added to SOAPBody
         */
        SOAPBody body = (SOAPBody) parent;
        target = body.addBodyElement(targetName);
    } else
        target = parent.addChildElement(targetName);

    // namespaces
    copyNamespaces(target, source);
    ensureOwnNamespaceDeclared(target);
    // attributes
    copyAttributes(target, source);
    // child nodes
    copyChildNodes(target, source);
}

From source file:org.mule.transport.soap.axis.style.DefaultMessageService.java

public void soapRequestResponse(SOAPEnvelope req, SOAPEnvelope resp) throws SOAPException {
    // Echo back// w  w w  . ja  v  a  2s . co m
    logger.debug("envelopeTest Called");
    SOAPBody body = resp.getBody();
    Name ns0 = resp.createName("TestNS0", "ns0", "http://example.com");
    Name ns1 = resp.createName("TestNS1", "ns1", "http://example.com");
    SOAPElement bodyElmnt = body.addBodyElement(ns0);
    SOAPElement el = bodyElmnt.addChildElement(ns1);
    el.addTextNode("TEST RESPONSE");
}

From source file:org.pentaho.platform.plugin.action.xmla.XMLABaseComponent.java

/**
 * Execute query//ww  w .jav a  2 s .c om
 *
 * @param query   - MDX to be executed
 * @param catalog
 * @param handler Callback handler
 * @throws XMLAException
 */
public boolean executeQuery(final String query, final String catalog) throws XMLAException {

    Object[][] columnHeaders = null;
    Object[][] rowHeaders = null;
    Object[][] data = null;

    int columnCount = 0;
    int rowCount = 0;

    SOAPConnection connection = null;
    SOAPMessage reply = null;

    try {
        connection = scf.createConnection();
        SOAPMessage msg = mf.createMessage();

        MimeHeaders mh = msg.getMimeHeaders();
        mh.setHeader("SOAPAction", XMLABaseComponent.EXECUTE_ACTION); //$NON-NLS-1$

        SOAPPart soapPart = msg.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);

        SOAPBody body = envelope.getBody();
        Name nEx = envelope.createName("Execute", "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$//$NON-NLS-2$

        SOAPElement eEx = body.addChildElement(nEx);
        eEx.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);

        // add the parameters

        // COMMAND parameter
        // <Command>
        // <Statement>select [Measures].members on Columns from
        // Sales</Statement>
        // </Command>
        Name nCom = envelope.createName("Command", "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$ //$NON-NLS-2$
        SOAPElement eCommand = eEx.addChildElement(nCom);
        Name nSta = envelope.createName("Statement", "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$ //$NON-NLS-2$
        SOAPElement eStatement = eCommand.addChildElement(nSta);
        eStatement.addTextNode(query);

        // <Properties>
        // <PropertyList>
        // <DataSourceInfo>Provider=MSOLAP;Data
        // Source=local</DataSourceInfo>
        // <Catalog>Foodmart 2000</Catalog>
        // <Format>Multidimensional</Format>
        // <AxisFormat>TupleFormat</AxisFormat> oder "ClusterFormat"
        // </PropertyList>
        // </Properties>
        Map paraList = new HashMap();
        paraList.put("DataSourceInfo", dataSource); //$NON-NLS-1$
        paraList.put("Catalog", catalog); //$NON-NLS-1$
        paraList.put("Format", "Multidimensional"); //$NON-NLS-1$ //$NON-NLS-2$
        paraList.put("AxisFormat", "TupleFormat"); //$NON-NLS-1$ //$NON-NLS-2$
        addParameterList(envelope, eEx, "Properties", "PropertyList", paraList); //$NON-NLS-1$ //$NON-NLS-2$

        msg.saveChanges();

        debug("Request for Execute"); //$NON-NLS-1$
        logSoapMsg(msg);

        // run the call
        reply = connection.call(msg, url);

        debug("Reply from Execute"); //$NON-NLS-1$
        logSoapMsg(reply);

        // error check
        errorCheck(reply);

        // process the reply
        SOAPElement eRoot = findExecRoot(reply);

        // for each axis, get the positions (tuples)
        Name name = envelope.createName("Axes", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$ //$NON-NLS-2$
        SOAPElement eAxes = selectSingleNode(eRoot, name);
        if (eAxes == null) {
            throw new XMLAException("Excecute result has no Axes element"); //$NON-NLS-1$
        }

        name = envelope.createName("Axis", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$ //$NON-NLS-2$
        Iterator itAxis = eAxes.getChildElements(name);

        AxisLoop: for (int iOrdinal = 0; itAxis.hasNext();) {
            SOAPElement eAxis = (SOAPElement) itAxis.next();
            name = envelope.createName("name"); //$NON-NLS-1$
            String axisName = eAxis.getAttributeValue(name);
            int axisOrdinal;
            if (axisName.equals("SlicerAxis")) { //$NON-NLS-1$
                continue;
            } else {
                axisOrdinal = iOrdinal++;
            }

            name = envelope.createName("Tuples", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$//$NON-NLS-2$
            SOAPElement eTuples = selectSingleNode(eAxis, name);
            if (eTuples == null) {
                continue AxisLoop; // what else?
            }

            name = envelope.createName("Tuple", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$//$NON-NLS-2$
            Iterator itTuple = eTuples.getChildElements(name);

            // loop over tuples
            int positionOrdinal = 0;
            while (itTuple.hasNext()) { // TupleLoop

                SOAPElement eTuple = (SOAPElement) itTuple.next();

                if ((axisOrdinal == XMLABaseComponent.AXIS_COLUMNS) && (columnHeaders == null)) {
                    columnCount = getChildCount(envelope, eTuples, "Tuple"); //$NON-NLS-1$
                    columnHeaders = new Object[getChildCount(envelope, eTuple, "Member")][columnCount]; //$NON-NLS-1$
                } else if ((axisOrdinal == XMLABaseComponent.AXIS_ROWS) && (rowHeaders == null)) {
                    rowCount = getChildCount(envelope, eTuples, "Tuple"); //$NON-NLS-1$
                    rowHeaders = new Object[rowCount][getChildCount(envelope, eTuple, "Member")]; //$NON-NLS-1$
                }

                int index = 0;
                name = envelope.createName("Member", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$//$NON-NLS-2$
                Iterator itMember = eTuple.getChildElements(name);
                while (itMember.hasNext()) { // MemberLoop
                    SOAPElement eMem = (SOAPElement) itMember.next();
                    // loop over children nodes
                    String caption = null;
                    Iterator it = eMem.getChildElements();
                    InnerLoop: while (it.hasNext()) {
                        Node n = (Node) it.next();
                        if (!(n instanceof SOAPElement)) {
                            continue InnerLoop;
                        }
                        SOAPElement el = (SOAPElement) n;
                        String enam = el.getElementName().getLocalName();
                        if (enam.equals("Caption")) { //$NON-NLS-1$
                            caption = el.getValue();
                        }
                    }
                    if (axisOrdinal == XMLABaseComponent.AXIS_COLUMNS) {
                        columnHeaders[index][positionOrdinal] = caption;
                    } else if (axisOrdinal == XMLABaseComponent.AXIS_ROWS) {
                        rowHeaders[positionOrdinal][index] = caption;
                    }
                    ++index;
                } // MemberLoop

                ++positionOrdinal;
            } // TupleLoop
        } // AxisLoop

        data = new Object[rowCount][columnCount];
        // loop over cells in result set
        name = envelope.createName("CellData", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$//$NON-NLS-2$
        SOAPElement eCellData = selectSingleNode(eRoot, name);
        name = envelope.createName("Cell", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$//$NON-NLS-2$
        Iterator itSoapCell = eCellData.getChildElements(name);
        while (itSoapCell.hasNext()) { // CellLoop
            SOAPElement eCell = (SOAPElement) itSoapCell.next();
            name = envelope.createName("CellOrdinal", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String cellOrdinal = eCell.getAttributeValue(name);
            int ordinal = Integer.parseInt(cellOrdinal);
            name = envelope.createName("Value", "", XMLABaseComponent.MDD_URI); //$NON-NLS-1$//$NON-NLS-2$
            Object value = selectSingleNode(eCell, name).getValue();

            int rowLoc = ordinal / columnCount;
            int columnLoc = ordinal % columnCount;

            data[rowLoc][columnLoc] = value;
        } // CellLoop

        MemoryResultSet resultSet = new MemoryResultSet();
        MemoryMetaData metaData = new MemoryMetaData(columnHeaders, rowHeaders);
        resultSet.setMetaData(metaData);
        for (Object[] element : data) {
            resultSet.addRow(element);
        }
        rSet = resultSet;
        if (resultSet != null) {
            if (getResultOutputName() != null) {
                setOutputValue(getResultOutputName(), resultSet);
            }
            return true;
        }
        return false;

    } catch (SOAPException se) {
        throw new XMLAException(se);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SOAPException e) {
                // log and ignore
                error("?", e); //$NON-NLS-1$
            }
        }

    }

}

From source file:org.pentaho.platform.plugin.action.xmla.XMLABaseComponent.java

/**
 * discover/*ww  w  .j  av a  2  s .co  m*/
 *
 * @param request
 * @param discoverUrl
 * @param restrictions
 * @param properties
 * @param rh
 * @throws XMLAException
 */
private void discover(final String request, final URL discoverUrl, final Map restrictions, final Map properties,
        final Rowhandler rh) throws XMLAException {

    try {
        SOAPConnection connection = scf.createConnection();

        SOAPMessage msg = mf.createMessage();

        MimeHeaders mh = msg.getMimeHeaders();
        mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Discover\""); //$NON-NLS-1$ //$NON-NLS-2$

        SOAPPart soapPart = msg.getSOAPPart();
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance"); //$NON-NLS-1$//$NON-NLS-2$
        envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema"); //$NON-NLS-1$ //$NON-NLS-2$
        SOAPBody body = envelope.getBody();
        Name nDiscover = envelope.createName("Discover", "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$//$NON-NLS-2$

        SOAPElement eDiscover = body.addChildElement(nDiscover);
        eDiscover.setEncodingStyle(XMLABaseComponent.ENCODING_STYLE);

        Name nPara = envelope.createName("RequestType", "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$//$NON-NLS-2$
        SOAPElement eRequestType = eDiscover.addChildElement(nPara);
        eRequestType.addTextNode(request);

        // add the parameters
        if (restrictions != null) {
            addParameterList(envelope, eDiscover, "Restrictions", "RestrictionList", restrictions); //$NON-NLS-1$ //$NON-NLS-2$
        }
        addParameterList(envelope, eDiscover, "Properties", "PropertyList", properties); //$NON-NLS-1$//$NON-NLS-2$

        msg.saveChanges();

        debug(Messages.getInstance().getString("XMLABaseComponent.DEBUG_0006_DISCOVER_REQUEST") + request); //$NON-NLS-1$
        logSoapMsg(msg);

        // run the call
        SOAPMessage reply = connection.call(msg, discoverUrl);

        debug(Messages.getInstance().getString("XMLABaseComponent.DEBUG_0007_DISCOVER_RESPONSE") + request); //$NON-NLS-1$
        logSoapMsg(reply);

        errorCheck(reply);

        SOAPElement eRoot = findDiscoverRoot(reply);

        Name nRow = envelope.createName("row", "", XMLABaseComponent.ROWS_URI); //$NON-NLS-1$ //$NON-NLS-2$
        Iterator itRow = eRoot.getChildElements(nRow);
        while (itRow.hasNext()) { // RowLoop

            SOAPElement eRow = (SOAPElement) itRow.next();
            rh.handleRow(eRow, envelope);

        } // RowLoop

        connection.close();
    } catch (UnsupportedOperationException e) {
        throw new XMLAException(e);
    } catch (SOAPException e) {
        throw new XMLAException(e);
    }

}

From source file:org.pentaho.platform.plugin.action.xmla.XMLABaseComponent.java

/**
 * add a list of Restrictions/Properties ...
 *///from  w w  w. j  a v a  2 s.  c  o m
private void addParameterList(final SOAPEnvelope envelope, final SOAPElement eParent, final String typeName,
        final String listName, final Map params) throws SOAPException {
    Name nPara = envelope.createName(typeName, "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$
    SOAPElement eType = eParent.addChildElement(nPara);
    nPara = envelope.createName(listName, "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$
    SOAPElement eList = eType.addChildElement(nPara);
    if (params == null) {
        return;
    }
    Iterator it = params.keySet().iterator();
    while (it.hasNext()) {
        String tag = (String) it.next();
        String value = (String) params.get(tag);
        nPara = envelope.createName(tag, "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$
        SOAPElement eTag = eList.addChildElement(nPara);
        eTag.addTextNode(value);
    }
}