Example usage for javax.xml.soap Name getLocalName

List of usage examples for javax.xml.soap Name getLocalName

Introduction

In this page you can find the example usage for javax.xml.soap Name getLocalName.

Prototype

String getLocalName();

Source Link

Document

Gets the local name part of the XML name that this Name object represents.

Usage

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

/**
 * locate "root" in DisoverResponse/*from w  ww . j a va 2  s. com*/
 */
private SOAPElement findDiscoverRoot(final SOAPMessage reply) throws SOAPException, XMLAException {

    SOAPPart sp = reply.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    Name childName;
    SOAPElement eResponse = null;
    if (provider == 0) {
        // unknown provider - recognize by prefix of DiscoverResponse
        Iterator itBody = body.getChildElements();
        while (itBody.hasNext()) {
            Node n = (Node) itBody.next();
            if (!(n instanceof SOAPElement)) {
                continue;
            }
            Name name = ((SOAPElement) n).getElementName();
            if (name.getLocalName().equals("DiscoverResponse")) { //$NON-NLS-1$
                eResponse = (SOAPElement) n;
                provider = getProviderFromDiscoverResponse(envelope, eResponse);
                break;
            }
        }
        if (eResponse == null) {
            throw new XMLAException(
                    Messages.getInstance().getString("XMLABaseComponent.ERROR_0013_NO_DISCOVER_RESPONSE")); //$NON-NLS-1$
        }

    } else {
        if ((provider == XMLABaseComponent.PROVIDER_MICROSOFT)
                || (provider == XMLABaseComponent.PROVIDER_ESSBASE)) { // Microsoft
            // or
            // Essbase
            childName = envelope.createName("DiscoverResponse", "m", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$ //$NON-NLS-2$
        } else if ((provider == XMLABaseComponent.PROVIDER_SAP)
                || (provider == XMLABaseComponent.PROVIDER_MONDRIAN)) { // SAP
            // or
            // Mondrian
            childName = envelope.createName("DiscoverResponse", "", XMLABaseComponent.XMLA_URI); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            throw new IllegalArgumentException(
                    Messages.getInstance().getString("XMLABaseComponent.ERROR_0014_NO_PROVIDER_SPEC")); //$NON-NLS-1$
        }
        eResponse = selectSingleNode(body, childName);
        if (eResponse == null) {
            throw new XMLAException(Messages.getInstance()
                    .getString("XMLABaseComponent.ERROR_0015_NO_DISCOVER_RESPONSE_ELEMENT")); //$NON-NLS-1$
        }
    }

    SOAPElement eReturn = getDiscoverReturn(envelope, eResponse);
    if (eReturn == null) {
        throw new XMLAException(
                Messages.getInstance().getString("XMLABaseComponent.ERROR_0016_NO_RESULT_RETURN_ELEMENT")); //$NON-NLS-1$
    }

    SOAPElement eRoot = getDiscoverRoot(envelope, eReturn);
    if (eRoot == null) {
        throw new XMLAException(
                Messages.getInstance().getString("XMLABaseComponent.ERROR_0017_NO_RESULT_ROOT_ELEMENT")); //$NON-NLS-1$
    }
    return eRoot;
}

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

/**
 * Find the Provider type in the DiscoverResponse
 *
 * @param n/* w w w .j  a v a2  s  .  com*/
 * @return
 * @throws XMLAException
 * @throws SOAPException
 */
private int getProviderFromDiscoverResponse(final SOAPEnvelope envelope, final SOAPElement e)
        throws XMLAException, SOAPException {
    Name name = e.getElementName();
    if (!name.getLocalName().equals("DiscoverResponse")) { //$NON-NLS-1$
        throw new XMLAException(
                Messages.getInstance().getString("XMLABaseComponent.ERROR_0018_NOT_A_DISCOVER_RESPONSE") //$NON-NLS-1$
                        + name.getLocalName());
    }

    // Look for return/root/row/ProviderName

    SOAPElement walker = getDiscoverReturn(envelope, e);

    if (walker == null) {
        throw new XMLAException(
                Messages.getInstance().getString("XMLABaseComponent.ERROR_0019_NO_RESULT_DISCOVER_RESPONSE")); //$NON-NLS-1$
    }

    walker = getDiscoverRoot(envelope, walker);

    if (walker == null) {
        throw new XMLAException(Messages.getInstance()
                .getString("XMLABaseComponent.ERROR_0020_NO_RESULT_DISCOVER_RETURN_ROOT")); //$NON-NLS-1$
    }

    walker = getDiscoverRow(envelope, walker);

    if (walker == null) {
        throw new XMLAException(
                Messages.getInstance().getString("XMLABaseComponent.ERROR_0021_NO_DISCOVER_RESPONSE_ROW")); //$NON-NLS-1$
    }

    /*
     * Name nProviderName = envelope.createName("ProviderName", "", ROWS_URI); SOAPElement eProviderName =
     * selectSingleNode(e, nProviderName);
     * 
     * if (eProviderName == null) { throw new OlapException("Discover result has no
     * DiscoverResponse/return/root/row/ProviderName element"); } value = eProviderName.getValue();
     */
    String value = null;
    Iterator it = walker.getChildElements();
    while (it.hasNext()) {
        Object o = it.next();
        if (!(o instanceof SOAPElement)) {
            continue; // bypass text nodes
        }
        SOAPElement e2 = (SOAPElement) o;
        String nameString = e2.getElementName().getLocalName();
        if (nameString.equals("ProviderName")) { //$NON-NLS-1$
            value = e2.getValue();
            debug(Messages.getInstance().getString("XMLABaseComponent.DEBUG_0008_FOUND_PROVIDER") + value); //$NON-NLS-1$
            break;
        }
    }

    if ((value == null) || (value.trim().length() == 0)) {
        throw new XMLAException(
                Messages.getInstance().getString("XMLABaseComponent.ERROR_0022_NO_PROVIDER_NAME_ELEMENT")); //$NON-NLS-1$
    }

    return determineProvider("Provider=" + value); //$NON-NLS-1$
}

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

/**
 * check SOAP reply for Error, return fault Code
 *
 * @param reply   the message to check//from   www.  j ava 2s .co  m
 * @param aReturn ArrayList containing faultcode,faultstring,faultactor
 */
private boolean soapFault(final SOAPMessage reply, final String[] faults) throws SOAPException {
    SOAPPart sp = reply.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPBody body = envelope.getBody();
    if (!body.hasFault()) {
        return false;
    }
    SOAPFault fault = body.getFault();

    faults[0] = fault.getFaultCode();
    faults[1] = fault.getFaultString();
    faults[2] = fault.getFaultActor();

    // probably not neccessary with Microsoft;
    Detail detail = fault.getDetail();
    if (detail == null) {
        return true;
    }
    String detailMsg = ""; //$NON-NLS-1$
    Iterator it = detail.getDetailEntries();
    for (; it.hasNext();) {
        DetailEntry det = (DetailEntry) it.next();
        Iterator ita = det.getAllAttributes();
        for (boolean cont = false; ita.hasNext(); cont = true) {
            Name name = (Name) ita.next();
            if (cont) {
                detailMsg += "; "; //$NON-NLS-1$
            }
            detailMsg += name.getLocalName();
            detailMsg += " = "; //$NON-NLS-1$
            detailMsg += det.getAttributeValue(name);
        }
    }
    faults[3] = detailMsg;

    return true;
}

From source file:org.springframework.ws.soap.saaj.support.SaajUtils.java

/**
 * Converts a <code>javax.xml.soap.Name</code> to a <code>javax.xml.namespace.QName</code>.
 *
 * @param name the <code>Name</code> to convert
 * @return the converted <code>QName</code>
 *//*from  w ww  . ja  v  a  2s  .  co  m*/
public static QName toQName(Name name) {
    if (StringUtils.hasLength(name.getURI()) && StringUtils.hasLength(name.getPrefix())) {
        return QNameUtils.createQName(name.getURI(), name.getLocalName(), name.getPrefix());
    } else if (StringUtils.hasLength(name.getURI())) {
        return new QName(name.getURI(), name.getLocalName());
    } else {
        return new QName(name.getLocalName());
    }
}

From source file:xsul.dsig.globus.security.authentication.wssec.WSSecurityUtil.java

/**
 * Returns first WS-Security header for a given actor.
 * Only one WS-Security header is allowed for an actor.
 *//*w ww.j av a2s  . co m*/
public static SOAPHeaderElement getSecurityHeader(SOAPEnvelope env, String actor) throws SOAPException {
    SOAPHeader header = env.getHeader();

    if (header == null) {
        return null;
    }

    Iterator headerElements = header.examineHeaderElements(actor);

    while (headerElements.hasNext()) {
        SOAPHeaderElement he = (SOAPHeaderElement) headerElements.next();
        Name nm = he.getElementName();

        // find ws-security header
        if (nm.getLocalName().equalsIgnoreCase(WSConstants.WS_SEC_LN)
                && nm.getURI().equalsIgnoreCase(WSConstants.WSSE_NS)) {
            return he;
        }
    }

    return null;
}