Package org.apache.cxf.helpers

Examples of org.apache.cxf.helpers.XPathUtils


        String node = null;
        Element detail = null;

        Map<String, String> ns = new HashMap<String, String>();
        ns.put("s", Soap12.SOAP_NAMESPACE);
        XPathUtils xu = new XPathUtils(ns);       
       
        try {
            Document fault = StaxUtils.read(new FragmentStreamReader(reader));
            Element el = (Element)xu.getValue("//s:Fault/s:Code/s:Value",
                                      fault,
                                      XPathConstants.NODE);
            if (el != null) {
                faultCode = XMLUtils.getQName(el.getTextContent(), el);
            }
           
            el = (Element)xu.getValue("//s:Fault/s:Code/s:Subcode/s:Value",
                                      fault,
                                      XPathConstants.NODE);
            if (el != null) {
                subCode = XMLUtils.getQName(el.getTextContent(), el);
            }
           
            exMessage = (String) xu.getValue("//s:Fault/s:Reason/s:Text/text()",
                                             fault,
                                             XPathConstants.STRING);
           
            Node detailNode = (Node) xu.getValue("//s:Fault/s:Detail",
                                                 fault,
                                                 XPathConstants.NODE);
            if (detailNode != null) {
                detail = (Element) detailNode;
            }
           
            role = (String) xu.getValue("//s:Fault/s:Role/text()",
                                        fault,
                                        XPathConstants.STRING);

            node = (String) xu.getValue("//s:Fault/s:Node/text()",
                                        fault,
                                        XPathConstants.STRING);                      
        } catch (XMLStreamException e) {
            throw new SoapFault("Could not parse message.",
                                message.getVersion().getSender());
View Full Code Here


        String node = null;
        Element detail = null;

        Map<String, String> ns = new HashMap<String, String>();
        ns.put("s", Soap12.SOAP_NAMESPACE);
        XPathUtils xu = new XPathUtils(ns);       
        try {
            Node mainNode = message.getContent(Node.class);
            Node fault = null;
           
            if (reader instanceof W3CDOMStreamReader) {
                W3CDOMStreamReader dr = (W3CDOMStreamReader)reader;
                fault = dr.getCurrentElement();
                dr.consumeFrame();
            } else if (mainNode != null) {
                Node bodyNode = (Node) xu.getValue("//s:Body",
                                                   mainNode,
                                                   XPathConstants.NODE);

                StaxUtils.readDocElements(bodyNode.getOwnerDocument(),
                                          bodyNode,
                                          new FragmentStreamReader(reader),
                                          false, false);
                fault = (Element)xu.getValue("//s:Fault", bodyNode, XPathConstants.NODE);
            } else {
                fault = StaxUtils.read(new FragmentStreamReader(reader));
            }
            Element el = (Element)xu.getValue("//s:Fault/s:Code/s:Value",
                                      fault,
                                      XPathConstants.NODE);
            if (el != null) {
                faultCode = XMLUtils.getQName(el.getTextContent(), el);
            }
           
            el = (Element)xu.getValue("//s:Fault/s:Code/s:Subcode",
                                      fault,
                                      XPathConstants.NODE);
            if (el != null) {
                subCodes = new LinkedList<QName>();
                NodeList vlist = el.getElementsByTagNameNS(Soap12.SOAP_NAMESPACE, "Value");
                for (int i = 0; i < vlist.getLength(); i++) {
                    Node v = vlist.item(i);
                    subCodes.add(XMLUtils.getQName(v.getTextContent(), v));
                }
            }
           
            exMessage = (String) xu.getValue("//s:Fault/s:Reason/s:Text/text()",
                                             fault,
                                             XPathConstants.STRING);
           
            Node detailNode = (Node) xu.getValue("//s:Fault/s:Detail",
                                                 fault,
                                                 XPathConstants.NODE);
            if (detailNode != null) {
                detail = (Element) detailNode;
            }
           
            role = (String) xu.getValue("//s:Fault/s:Role/text()",
                                        fault,
                                        XPathConstants.STRING);

            node = (String) xu.getValue("//s:Fault/s:Node/text()",
                                        fault,
                                        XPathConstants.STRING);                      
        } catch (XMLStreamException e) {
            throw new SoapFault("Could not parse message.",
                                e,
View Full Code Here

    }
   
    private void setStackTrace(Fault fault, Message msg) {
        Throwable cause = null;
        Map<String, String> ns = new HashMap<String, String>();
        XPathUtils xu = new XPathUtils(ns);
        ns.put("s", Fault.STACKTRACE_NAMESPACE);
        String ss = (String) xu.getValue("//s:" + Fault.STACKTRACE + "/text()", fault.getDetail(),
                XPathConstants.STRING);
        List<StackTraceElement> stackTraceList = new ArrayList<StackTraceElement>();
        if (!StringUtils.isEmpty(ss)) {
            StringTokenizer st = new StringTokenizer(ss, "\n");
            while (st.hasMoreTokens()) {
View Full Code Here

        ns.put("tns", "http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService");
        ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
        ns.put("xs", "http://www.w3.org/2001/XMLSchema");
       
       
        XPathUtils xu = new XPathUtils(ns);
       
        //make sure the wrapper types are anonymous types
        Node ct = (Node) xu.getValue("//wsdl:definitions/wsdl:types/xs:schema"
                                     + "/xs:element[@name='getFooSetResponse']/xs:complexType/xs:sequence",
                                     doc, XPathConstants.NODE);
        assertNotNull(ct);
       
        //make sure the params are nillable, not minOccurs=0
        ct = (Node) xu.getValue("//wsdl:definitions/wsdl:types/xs:schema"
                                + "/xs:element[@name='multiInOut']/xs:complexType/xs:sequence"
                                + "/xs:element[@nillable='true']",
                                doc, XPathConstants.NODE);
        assertNotNull(ct);
    }
View Full Code Here

        return docs;
    }

    private boolean isExist(List<Document> docs, XNode vNode) {
        XPathUtils xpather = new XPathUtils(vNode.getNSMap());
        String expression = vNode.toString();
        for (Document doc : docs) {
            if (xpather.isExist(expression, doc, XPathConstants.NODE)) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

    private FailureLocation getFailureLocation(List<Document> docs, XNode fNode) {
        if (fNode == null) {
            return null;
        }

        XPathUtils xpather = new XPathUtils(fNode.getNSMap());
        for (Document doc : docs) {
            Node node = (Node) xpather.getValue(fNode.toString(), doc, XPathConstants.NODE);
            if (null != node) {
                try {
                    return new FailureLocation((Location)node.getUserData("location"),
                                               doc.getDocumentURI());
                } catch (Exception ex) {
View Full Code Here

           
            Map<String, String> ns = new HashMap<String, String>();
            ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
            ns.put("xop", MtomTestHelper.XOP_NS);

            XPathUtils xu = new XPathUtils(ns);
            Element body = new XmlConverter().toDOMElement(in.getBody().get(0));
            Element ele = (Element)xu.getValue("//ns:Detail/ns:photo/xop:Include", body,
                                               XPathConstants.NODE);
            String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
            Assert.assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId);

            ele = (Element)xu.getValue("//ns:Detail/ns:image/xop:Include", body,
                                               XPathConstants.NODE);
            String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
            Assert.assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);

            DataHandler dr = exchange.getIn().getAttachment(photoId);
View Full Code Here

       
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
        ns.put("xop", MtomTestHelper.XOP_NS);
       
        XPathUtils xu = new XPathUtils(ns);
        Element oute = new XmlConverter().toDOMElement(out.getBody().get(0));
        Element ele = (Element)xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute,
                                           XPathConstants.NODE);
        String photoId = ele.getAttribute("href").substring(4); // skip "cid:"

        ele = (Element)xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute,
                                           XPathConstants.NODE);
        String imageId = ele.getAttribute("href").substring(4); // skip "cid:"

        DataHandler dr = exchange.getOut().getAttachment(photoId);
        Assert.assertEquals("application/octet-stream", dr.getContentType());
View Full Code Here

       
        Node nd = XMLUtils.fromSource(resp);
        if (nd instanceof Document) {
            nd = ((Document)nd).getDocumentElement();
        }
        XPathUtils xpu = new XPathUtils(new W3CNamespaceContext((Element)nd));
        assertTrue(xpu.isExist("/ns1:sendReceiveDataResponse/out", nd, XPathConstants.NODE));
    }
View Full Code Here

        ns.put("soap", Soap11.SOAP_NAMESPACE);
        ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
        ns.put("xs", "http://www.w3.org/2001/XMLSchema");
       
       
        XPathUtils xu = new XPathUtils(ns);
       
        //make sure the wrapper types are anonymous types
        NodeList ct = (NodeList) xu.getValue("//wsdl:definitions/wsdl:message/wsdl:part[@element != '']",
                                             doc, XPathConstants.NODESET);
        assertNotNull(ct);
        assertEquals(0, ct.getLength());
       
        ct = (NodeList) xu.getValue("//wsdl:definitions/wsdl:message/wsdl:part[@type != '']",
                                     doc, XPathConstants.NODESET);
        assertEquals(4, ct.getLength());
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.helpers.XPathUtils

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.