Example usage for javax.xml.soap SOAPElement getChildElements

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

Introduction

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

Prototype

public Iterator<Node> getChildElements(QName qname);

Source Link

Document

Returns an Iterator over all the immediate child Node s of this element with the specified qname.

Usage

From source file:com.qubit.solution.fenixedu.bennu.webservices.services.server.BennuWebServiceHandler.java

@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    //for response message only, true for outbound messages, false for inbound
    if (!isRequest) {
        try {//from   w w  w.j  ava2s.com

            WebServiceServerConfiguration configuration = getWebServiceServerConfiguration(
                    ((com.sun.xml.ws.api.server.WSEndpoint) context.get("com.sun.xml.ws.api.server.WSEndpoint"))
                            .getImplementationClass().getName());

            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnv.getHeader();

            if (!configuration.isActive()) {
                generateSOAPErrorMessage(soapMsg, "Sorry webservice is disabled at application level!");
            }

            if (configuration.isAuthenticatioNeeded()) {

                if (configuration.isUsingWSSecurity()) {
                    if (soapHeader == null) {
                        generateSOAPErrorMessage(soapMsg,
                                "No header in message, unabled to validate security credentials");
                    }

                    String username = null;
                    String password = null;
                    String nonce = null;
                    String created = null;

                    Iterator<SOAPElement> childElements = soapHeader.getChildElements(QNAME_WSSE_SECURITY);
                    if (childElements.hasNext()) {
                        SOAPElement securityElement = childElements.next();
                        Iterator<SOAPElement> usernameTokens = securityElement
                                .getChildElements(QNAME_WSSE_USERNAME_TOKEN);
                        if (usernameTokens.hasNext()) {
                            SOAPElement usernameToken = usernameTokens.next();
                            username = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_USERNAME)
                                    .next()).getValue();
                            password = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_PASSWORD)
                                    .next()).getValue();
                            nonce = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_NONCE).next())
                                    .getValue();
                            created = ((SOAPElement) usernameToken.getChildElements(QNAME_WSSE_CREATED).next())
                                    .getValue();
                        }
                    }
                    if (username == null || password == null || nonce == null || created == null) {
                        generateSOAPErrorMessage(soapMsg,
                                "Missing information, unabled to validate security credentials");
                    }

                    SecurityHeader securityHeader = new SecurityHeader(configuration, username, password, nonce,
                            created);
                    if (!securityHeader.isValid()) {
                        generateSOAPErrorMessage(soapMsg, "Invalid credentials");
                    } else {
                        context.put(BennuWebService.SECURITY_HEADER, securityHeader);
                        context.setScope(BennuWebService.SECURITY_HEADER, Scope.APPLICATION);
                    }
                } else {
                    com.sun.xml.ws.transport.Headers httpHeader = (Headers) context
                            .get(MessageContext.HTTP_REQUEST_HEADERS);
                    String username = null;
                    String password = null;
                    List<String> list = httpHeader.get("authorization");
                    if (list != null) {
                        for (String value : list) {
                            if (value.startsWith("Basic")) {
                                String[] split = value.split(" ");
                                try {
                                    String decoded = new String(Base64.decodeBase64(split[1]), "UTF-8");
                                    String[] split2 = decoded.split(":");
                                    if (split2.length == 2) {
                                        username = split2[0];
                                        password = split2[1];
                                    }
                                } catch (UnsupportedEncodingException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }

                    if (username == null || password == null) {
                        generateSOAPErrorMessage(soapMsg,
                                "Missing information, unabled to validate security credentials");
                    }

                    if (!configuration.validate(username, password)) {
                        generateSOAPErrorMessage(soapMsg, "Invalid credentials");
                    }
                }
            }

        } catch (SOAPException e) {
            System.err.println(e);
        }
    }

    //continue other handler chain
    return true;
}

From source file:edu.xtec.colex.client.beans.ColexIndexBean.java

/**
 * Returns a Vector containing the guest collections (Collection,Guest)
 * stored into SOAPMessage//from   w w  w . j  a v  a  2 s. c  o  m
 *
 * @param sm the SOAPMessage
 * @throws javax.xml.soap.SOAPException when a SOAPException error occurs
 * @return the Vector
 */
protected Vector getListGuestCollections(SOAPMessage sm) throws SOAPException {
    Vector vRes = new Vector();

    SOAPBody sb = sm.getSOAPBody();

    Iterator it = sb.getChildElements();
    Iterator it2 = null;

    SOAPElement se = (SOAPElement) it.next();

    it = se.getChildElements(sf.createName("guestCollections"));

    se = (SOAPElement) it.next();

    it = se.getChildElements(sf.createName("guestCollection"));

    while (it.hasNext()) {
        se = (SOAPElement) it.next();

        it2 = se.getChildElements(sf.createName("collection"));

        Collection c = new Collection((SOAPElement) it2.next());
        vRes.add(c);

        it2 = se.getChildElements(sf.createName("guest"));

        Guest g = new Guest((SOAPElement) it2.next());
        vRes.add(g);
    }
    return vRes;
}

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

protected void handleTuplesElement(JRXmlaResultAxis axis, SOAPElement tuplesElement) throws SOAPException {
    Name tName = sf.createName("Tuple", "", MDD_URI);
    for (Iterator<?> itTuple = tuplesElement.getChildElements(tName); itTuple.hasNext();) {
        SOAPElement eTuple = (SOAPElement) itTuple.next();
        handleTupleElement(axis, eTuple);
    }//from  ww w. j a  v  a 2s .c o m
}

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

protected void parseCellDataElement(SOAPElement cellDataElement) throws SOAPException {
    Name name = sf.createName("Cell", "", MDD_URI);
    Iterator<?> itCells = cellDataElement.getChildElements(name);
    while (itCells.hasNext()) {
        SOAPElement cellElement = (SOAPElement) itCells.next();

        Name errorName = sf.createName("Error", "", MDD_URI);
        Iterator<?> errorElems = cellElement.getChildElements(errorName);
        if (errorElems.hasNext()) {
            handleCellErrors(errorElems);
        }//from w ww .  ja v a  2s . c  om

        Name ordinalName = sf.createName("CellOrdinal");
        String cellOrdinal = cellElement.getAttributeValue(ordinalName);

        Object value = null;
        Iterator<?> valueElements = cellElement.getChildElements(sf.createName("Value", "", MDD_URI));
        if (valueElements.hasNext()) {
            SOAPElement valueElement = (SOAPElement) valueElements.next();
            String valueType = valueElement.getAttribute("xsi:type");
            if (valueType.equals("xsd:int")) {
                value = Long.valueOf(valueElement.getValue());
            } else if (valueType.equals("xsd:double") || valueType.equals("xsd:decimal")) {
                value = Double.valueOf(valueElement.getValue());
            } else {
                value = valueElement.getValue();
            }
        }

        String fmtValue = "";
        Iterator<?> fmtValueElements = cellElement.getChildElements(sf.createName("FmtValue", "", MDD_URI));
        if (fmtValueElements.hasNext()) {
            SOAPElement fmtValueElement = ((SOAPElement) fmtValueElements.next());
            fmtValue = fmtValueElement.getValue();
        }

        int pos = Integer.parseInt(cellOrdinal);
        JRXmlaCell cell = new JRXmlaCell(value, fmtValue);
        xmlaResult.setCell(cell, pos);
    }
}

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

protected void parseAxesElement(SOAPElement axesElement) throws SOAPException {
    // Cycle over Axis-Elements
    Name aName = sf.createName("Axis", "", MDD_URI);
    Iterator<?> itAxis = axesElement.getChildElements(aName);
    while (itAxis.hasNext()) {
        SOAPElement axisElement = (SOAPElement) itAxis.next();
        Name name = sf.createName("name");
        String axisName = axisElement.getAttributeValue(name);

        if (axisName.equals(SLICER_AXIS_NAME)) {
            continue;
        }//  w w w.j av  a 2  s. co  m

        // LookUp for the Axis
        JRXmlaResultAxis axis = xmlaResult.getAxisByName(axisName);

        // retrieve the tuples by <Tuples>
        name = sf.createName("Tuples", "", MDD_URI);
        Iterator<?> itTuples = axisElement.getChildElements(name);
        if (itTuples.hasNext()) {
            SOAPElement eTuples = (SOAPElement) itTuples.next();
            handleTuplesElement(axis, eTuples);
        }
    }
}

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

protected void parseAxesInfoElement(SOAPElement axesInfoElement) throws SOAPException {
    // Cycle over AxisInfo-Elements
    Name axisInfoName = sf.createName("AxisInfo", "", MDD_URI);
    Iterator<?> itAxis = axesInfoElement.getChildElements(axisInfoName);
    while (itAxis.hasNext()) {
        SOAPElement axisElement = (SOAPElement) itAxis.next();
        Name name = sf.createName("name");
        String axisName = axisElement.getAttributeValue(name);
        if (axisName.equals(SLICER_AXIS_NAME)) {
            continue;
        }//from w  w w.  j  av  a2  s.c om

        JRXmlaResultAxis axis = new JRXmlaResultAxis(axisName);
        xmlaResult.addAxis(axis);

        if (log.isDebugEnabled()) {
            log.debug("adding axis: " + axis.getAxisName());
        }

        // retrieve the hierarchies by <HierarchyInfo>
        name = sf.createName("HierarchyInfo", "", MDD_URI);
        Iterator<?> itHierInfo = axisElement.getChildElements(name);
        while (itHierInfo.hasNext()) {
            SOAPElement eHierInfo = (SOAPElement) itHierInfo.next();
            handleHierInfo(axis, eHierInfo);
        }
    }
}

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

protected void handleCellErrors(Iterator<?> errorElems) throws SOAPException {
    SOAPElement errorElem = (SOAPElement) errorElems.next();

    StringBuilder errorMsg = new StringBuilder();
    errorMsg.append("Cell error: ");

    Iterator<?> descriptionElems = errorElem.getChildElements(sf.createName("Description", "", MDD_URI));
    if (descriptionElems.hasNext()) {
        SOAPElement descrElem = (SOAPElement) descriptionElems.next();
        errorMsg.append(descrElem.getValue());
        errorMsg.append("; ");
    }//from  ww w  . jav  a 2 s.  c  o  m

    Iterator<?> sourceElems = errorElem.getChildElements(sf.createName("Source", "", MDD_URI));
    if (sourceElems.hasNext()) {
        SOAPElement sourceElem = (SOAPElement) sourceElems.next();
        errorMsg.append("Source: ");
        errorMsg.append(sourceElem.getValue());
        errorMsg.append("; ");
    }

    Iterator<?> codeElems = errorElem.getChildElements(sf.createName("ErrorCode", "", MDD_URI));
    if (codeElems.hasNext()) {
        SOAPElement codeElem = (SOAPElement) codeElems.next();
        errorMsg.append("Code: ");
        errorMsg.append(codeElem.getValue());
        errorMsg.append("; ");
    }

    throw new JRRuntimeException(errorMsg.toString());
}

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

protected void handleTupleElement(JRXmlaResultAxis axis, SOAPElement tupleElement) throws SOAPException {
    JRXmlaMemberTuple tuple = new JRXmlaMemberTuple(axis.getHierarchiesOnAxis().length);

    Name memName = sf.createName("Member", "", MDD_URI);
    Iterator<?> itMember = tupleElement.getChildElements(memName);
    int memNum = 0;
    while (itMember.hasNext()) {
        SOAPElement memElement = (SOAPElement) itMember.next();

        Name name = sf.createName("Hierarchy", "", "");
        String hierName = memElement.getAttributeValue(name);

        String uName = "";
        Iterator<?> uNameElements = memElement.getChildElements(sf.createName("UName", "", MDD_URI));
        if (uNameElements.hasNext()) {
            uName = ((SOAPElement) uNameElements.next()).getValue();
        }//from   w w  w.  j  a v a 2 s . com
        String caption = "";
        Iterator<?> captionElements = memElement.getChildElements(sf.createName("Caption", "", MDD_URI));
        if (captionElements.hasNext()) {
            caption = ((SOAPElement) captionElements.next()).getValue();
        }
        String lName = "";
        Iterator<?> lNameElements = memElement.getChildElements(sf.createName("LName", "", MDD_URI));
        if (lNameElements.hasNext()) {
            String levelUniqueName = ((SOAPElement) lNameElements.next()).getValue();
            Matcher matcher = LEVEL_UNIQUE_NAME_PATTERN.matcher(levelUniqueName);
            if (matcher.matches()) {
                lName = matcher.group(LEVEL_UNIQUE_NAME_PATTERN_NAME_GROUP);
            } else {
                matcher = HIERARCHY_LEVEL_UNIQUE_NAME_PATTERN.matcher(levelUniqueName);
                if (matcher.matches()) {
                    lName = matcher.group(HIERARCHY_LEVEL_UNIQUE_NAME_PATTERN_NAME_GROUP);
                } else {
                    throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NO_LEVEL_NAME,
                            new Object[] { levelUniqueName });
                }
            }
        }

        int lNum = 0;
        Iterator<?> lNumElements = memElement.getChildElements(sf.createName("LNum", "", MDD_URI));
        if (lNumElements.hasNext()) {
            lNum = Integer.parseInt(((SOAPElement) lNumElements.next()).getValue());
        }
        JRXmlaMember member = new JRXmlaMember(caption, uName, hierName, lName, lNum);

        if (log.isDebugEnabled()) {
            log.debug("Adding member: axis - " + axis.getAxisName() + " hierName - " + hierName + " lName - "
                    + lName + " uName - " + uName);
        }
        tuple.setMember(memNum++, member);
    }

    axis.addTuple(tuple);
}

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

protected void parseOLAPInfoElement(SOAPElement olapInfoElement) throws SOAPException {
    // CubeInfo-Element is not needed

    // Get the AxesInfo-Node
    Name axesInfoName = sf.createName("AxesInfo", "", MDD_URI);
    SOAPElement axesElement = null;
    Iterator<?> axesInfoElements = olapInfoElement.getChildElements(axesInfoName);
    if (axesInfoElements.hasNext()) {
        Object axesObj = axesInfoElements.next();
        if (axesObj == null) {
            throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "AxesInfo" });
        }/*from   w  w w  . j  av a 2  s  .c  o  m*/
        axesElement = (SOAPElement) axesObj;
    } else {
        throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT,
                new Object[] { "AxesInfo" });
    }

    parseAxesInfoElement(axesElement);

    // CellInfo is not needed
}

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

protected void handleTuplesElement(JRXmlaResultAxis axis, SOAPElement tuplesElement) throws SOAPException {
    Name tName = sf.createName("Tuple", "", MDD_URI);
    for (Iterator itTuple = tuplesElement.getChildElements(tName); itTuple.hasNext();) {
        SOAPElement eTuple = (SOAPElement) itTuple.next();
        handleTupleElement(axis, eTuple);
    }/* w  w w.j av a2s  . co m*/
}