Package org.apache.axiom.om.xpath

Examples of org.apache.axiom.om.xpath.AXIOMXPath


     * @return the average last price for each stock symbol
     * @throws Exception
     */
    public static String parseMarketActivityResponse(OMElement result) throws Exception {

        AXIOMXPath xPath = new AXIOMXPath("//ns:last");
        xPath.addNamespace("ns","http://services.samples/xsd");
        List lastNodes = xPath.selectNodes(result);

        if (lastNodes == null) {
            throw new Exception("Unexpected response : " + result);
        }

View Full Code Here


     *          <Price>82.90</Price>
     *      </CheckPriceResponse>
     */
    public static String parseCustomQuoteResponse(OMElement result) throws Exception {

        AXIOMXPath xPath = new AXIOMXPath("//ns:Price");
        xPath.addNamespace("ns","http://services.samples/xsd");
        OMElement price = (OMElement) xPath.selectSingleNode(result);       
        if (price != null) {
            return price.getText();
        } else {
            throw new Exception("Unexpected response : " + result);
        }
View Full Code Here

            if(dataRef == null || dataRef.getXpath() == null) {
                continue;
            }

            try {
                XPath xp = new AXIOMXPath(dataRef.getXpath());

                Iterator nsIter = namespaces.iterator();

                while (nsIter.hasNext())
                {
                    OMNamespace tmpNs = (OMNamespace)nsIter.next();
                    xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
                }

                Iterator nodesIterator = xp.selectNodes(envelope).iterator();

                while (nodesIterator.hasNext()) {
                    decryptedElements.put(nodesIterator.next(), Boolean.valueOf(dataRef.isContent()));
                }


            } catch (JaxenException e) {
                // This has to be changed to propagate an instance of a RampartException up
                throw new RampartException("An error occurred while searching for decrypted elements.", e);
            }

        }

       
        //Check for encrypted body
        if(rpd.isEncryptBody()&& !rpd.isEncryptBodyOptional()) {
           
            if( !isRefIdPresent(encrRefs, data.getBodyEncrDataId())){
                throw new RampartException("encryptedPartMissing",
                        new String[]{data.getBodyEncrDataId()});
            }
        }

        for (int i = 0 ; i < encryptedParts.size() ; i++) {
           
            WSEncryptionPart encPart = (WSEncryptionPart)encryptedParts.get(i);
           
            //This is the encrypted Body and we already checked encrypted body
            if (encPart.getType() == WSConstants.PART_TYPE_BODY) {
                continue;
            }
           
            if ((WSConstants.SIG_LN.equals(encPart.getName()) &&
                    WSConstants.SIG_NS.equals(encPart.getNamespace()))
                   || encPart.getType() == WSConstants.PART_TYPE_HEADER ) {
                if (!isRefIdPresent(encrRefs, new QName(encPart.getNamespace(),encPart.getName()))) {
                    throw new RampartException("encryptedPartMissing",
                            new String[]{encPart.getNamespace()+":"+encPart.getName()});
                }
                continue;
            }

            // it is not a header or body part... verify encrypted xpath elements
            String xpath = encPart.getXpath();
            boolean found = false;
            try {
                XPath xp = new AXIOMXPath(xpath);
                Iterator nsIter = namespaces.iterator();

                while (nsIter.hasNext()) {
                    OMNamespace tmpNs = (OMNamespace) nsIter.next();
                    xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
                }

                Iterator nodesIterator = xp.selectNodes(envelope).iterator();

                while (nodesIterator.hasNext()) {
                    Object result = decryptedElements.get(nodesIterator.next());
                    if (result != null &&
                            ("Element".equals(encPart.getEncModifier())
View Full Code Here

        SOAPEnvelope envelope = context.getMessageContext().getEnvelope();
        Object result;
       
        try {
            if (compiledXPath == null) {
                compiledXPath = new AXIOMXPath(source);
            }
            result = compiledXPath.evaluate(envelope);
        } catch (JaxenException e) {
            throw new EvaluatorException("Error while parsing the XPath expression: " + source, e);
        }
View Full Code Here

        Iterator elementsIter = elements.iterator();
        while (elementsIter.hasNext())
        {
                String expression = (String)elementsIter.next();
                try {
                                XPath xp = new AXIOMXPath(expression);
                                Iterator nsIter = namespaces.iterator();
                               
                                while (nsIter.hasNext())
                                {
                                        OMNamespace tmpNs = (OMNamespace)nsIter.next();
                                        xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
                                }
                               
                                List selectedNodes = xp.selectNodes(envelope);
                               
                                Iterator nodesIter = selectedNodes.iterator();
                               
                            while (nodesIter.hasNext())
                            {
View Full Code Here

        Iterator elementsIter = elements.iterator();
        while (elementsIter.hasNext())
        {
          String expression = (String)elementsIter.next();
          try {
        XPath xp = new AXIOMXPath(expression);
        Iterator nsIter = namespaces.iterator();
       
        while (nsIter.hasNext())
        {
          OMNamespace tmpNs = (OMNamespace)nsIter.next();
          xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
        }
       
        List selectedNodes = xp.selectNodes(envelope);
       
        Iterator nodesIter = selectedNodes.iterator();
          while (nodesIter.hasNext())
          {
            OMElement e = (OMElement)nodesIter.next();
View Full Code Here

        SOAPHeader header = envelope.getHeader();
       
        Set namespaces = findAllPrefixNamespaces(header, decNamespaces);

        try {
                        XPath xp = new AXIOMXPath(expression);
                        Iterator nsIter = namespaces.iterator();
                       
                        while (nsIter.hasNext())
                        {
                                OMNamespace tmpNs = (OMNamespace)nsIter.next();
                                xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
                        }
                       
                        List selectedNodes = xp.selectNodes(header);
                       
                        if (selectedNodes.size() == 0 ) {
                            return false;
                        }
               
View Full Code Here

    public void testXPath() {
        try {
            OMElement element = AXIOMUtil.stringToOM(getXmlOfMediatorScenarioOneA("full"));

            AXIOMXPath xPath = new AXIOMXPath("//property/@name");
            //xPath.addNamespace(SynapseConstants.SYNAPSE_NAMESPACE, "");
            Object o = xPath.selectSingleNode(element);
            if (o instanceof OMAttribute) {
                System.out.println(((OMAttribute) o).getAttributeValue());
            }
        } catch (XMLStreamException e) {
            e.printStackTrace();
View Full Code Here

     * @param synCtx the message context
     * @return the OMNode against which validation should be performed
     */
    private OMNode getValidateSource(MessageContext synCtx) {

        AXIOMXPath sourceXPath = source;
        // do not change the source XPath if not specified, as it is shared..
        // and will cause confusion to concurrent messages and erroneous results

        if (sourceXPath == null) {
            log.debug("validation source was not specified.. defaulting to SOAP Body");
            try {
                sourceXPath = new AXIOMXPath("//SOAP-ENV:Body/child::*");
                sourceXPath.addNamespace("SOAP-ENV", synCtx.isSOAP11() ?
                    SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI : SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
            } catch (JaxenException e) {
                // this should not cause a runtime exception!
            }
        }

        try {
            Object o = sourceXPath.evaluate(synCtx.getEnvelope());
            if (o instanceof OMNode) {
                return (OMNode) o;
            } else if (o instanceof List && !((List) o).isEmpty()) {
                return (OMNode) ((List) o).get(0)// Always fetches *only* the first
            } else {
View Full Code Here

            throw new SynapseException(msg);
        }

        if (attSource != null) {
            try {
                AXIOMXPath xp = new AXIOMXPath(attSource.getAttributeValue());
                Util.addNameSpaces(xp, elem, log);
                transformMediator.setSource(xp);

            } catch (JaxenException e) {
                String msg = "Invalid XPath specified for the source attribute : " + attSource.getAttributeValue();
View Full Code Here

TOP

Related Classes of org.apache.axiom.om.xpath.AXIOMXPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.