Package org.apache.cxf.helpers

Examples of org.apache.cxf.helpers.XPathUtils


            if (el instanceof Document) {
                el = ((Document)el).getDocumentElement();
            }
            Map<String, String> ns = new HashMap<String, String>();
            ns.put("ns2", "http://www.example.org/schema/DoubleIt");
            XPathUtils xp = new XPathUtils(ns);
            String o = (String)xp.getValue("//ns2:DoubleIt/numberToDouble", el, XPathConstants.STRING);
            int i = Integer.parseInt(o);
           
            String req = "<ns2:DoubleItResponse xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">"
                + "<doubledNumber>" + Integer.toString(i * 2) + "</doubledNumber></ns2:DoubleItResponse>";
            return new StreamSource(new StringReader(req));
View Full Code Here


    }
    @Test
    public void testWSDLDocs() throws Exception {
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        XPathUtils xpu = new XPathUtils(ns);
        Document wsdl = XMLUtils.parse(this.getHttpConnection(ServerMisc.DOCLIT_CODEFIRST_URL + "?wsdl")
                                          .getInputStream());
        //XMLUtils.printDOM(wsdl.getDocumentElement());
        assertEquals("DocLitWrappedCodeFirstService impl",
                     xpu.getValue("/wsdl:definitions/wsdl:service/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("DocLitWrappedCodeFirstService interface",
                     xpu.getValue("/wsdl:definitions/wsdl:portType/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("DocLitWrappedCodeFirstService top level doc",
                     xpu.getValue("/wsdl:definitions/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("DocLitWrappedCodeFirstService binding doc",
                     xpu.getValue("/wsdl:definitions/wsdl:binding/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("DocLitWrappedCodeFirstService service/port doc",
                     xpu.getValue("/wsdl:definitions/wsdl:service/wsdl:port/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut doc",
                     xpu.getValue("/wsdl:definitions/wsdl:portType/wsdl:operation[@name='multiInOut']"
                                  + "/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut Input doc",
                     xpu.getValue("/wsdl:definitions/wsdl:portType/wsdl:operation[@name='multiInOut']"
                                  + "/wsdl:input/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut Output doc",
                     xpu.getValue("/wsdl:definitions/wsdl:portType/wsdl:operation[@name='multiInOut']"
                                  + "/wsdl:output/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut InputMessage doc",
                     xpu.getValue("/wsdl:definitions/wsdl:message[@name='multiInOut']"
                                  + "/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut OutputMessage doc",
                     xpu.getValue("/wsdl:definitions/wsdl:message[@name='multiInOutResponse']"
                                  + "/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut binding doc",
                     xpu.getValue("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='multiInOut']"
                                  + "/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut binding Input doc",
                     xpu.getValue("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='multiInOut']"
                                  + "/wsdl:input/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("multiInOut binding Output doc",
                     xpu.getValue("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='multiInOut']"
                                  + "/wsdl:output/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("fault binding doc",
                     xpu.getValue("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='throwException']"
                                  + "/wsdl:fault/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("fault porttype doc",
                     xpu.getValue("/wsdl:definitions/wsdl:portType/wsdl:operation[@name='throwException']"
                                  + "/wsdl:fault/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
        assertEquals("fault message doc",
                     xpu.getValue("/wsdl:definitions/wsdl:message[@name='CustomException']"
                                  + "/wsdl:documentation",
                                  wsdl.getDocumentElement(),
                                  XPathConstants.STRING));
    }
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

    private static String parseResponse(DOMSource domResponse) {
        Element el = ((Document)domResponse.getNode()).getDocumentElement();
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
        ns.put("ns", "http://cxf.apache.org/greeter_control/types");
        XPathUtils xp = new XPathUtils(ns);
        return (String)xp.getValue("/soap:Envelope/soap:Body"
                                   + "/ns:greetMeResponse/ns:responseType",
                                   el,
                                   XPathConstants.STRING);
    }
View Full Code Here

        if (nd instanceof Document) {
            nd = ((Document)nd).getDocumentElement();
        }
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("ns2", "http://www.example.org/schema/DoubleIt");
        XPathUtils xp = new XPathUtils(ns);
        Object o = xp.getValue("//ns2:DoubleItResponse/doubledNumber", nd, XPathConstants.STRING);
        assertEquals(XMLUtils.toString(nd), "50", o);
    }
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/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

        assertNotNull(doc);
       
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("soap", Soap11.SOAP_NAMESPACE);
        ns.put("ns2", "http://apache.org/hello_world_soap_http/types");
        XPathUtils xu = new XPathUtils(ns);
        Node body = (Node) xu.getValue("/soap:Envelope/soap:Body", doc, XPathConstants.NODE);
        assertNotNull(body);
        String response = (String) xu.getValue("//ns2:sayHiResponse/ns2:responseType/text()",
                                               body,
                                               XPathConstants.STRING);
        assertEquals("Bonjour", response);
    }
View Full Code Here

        assertNotNull(doc);
       
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("soap", Soap11.SOAP_NAMESPACE);
        ns.put("ns2", "http://apache.org/hello_world_soap_http/types");
        XPathUtils xu = new XPathUtils(ns);
        Node body = (Node) xu.getValue("/soap:Envelope/soap:Body", doc, XPathConstants.NODE);
        assertNotNull(body);
        String response = (String) xu.getValue("//ns2:greetMeResponse/ns2:responseType/text()",
                                               body,
                                               XPathConstants.STRING);
        assertEquals("Hello cxf", response);
    }
View Full Code Here

        assertNotNull(doc);
       
        Map<String, String> ns = new HashMap<String, String>();
        ns.put("soap", Soap11.SOAP_NAMESPACE);
        ns.put("ns2", "http://apache.org/hello_world_soap_http/types");
        XPathUtils xu = new XPathUtils(ns);
        Node body = (Node) xu.getValue("/soap:Envelope/soap:Body", doc, XPathConstants.NODE);
        assertNotNull(body);
        String response = (String) xu.getValue("//ns2:greetMeResponse/ns2:responseType/text()",
                                               body,
                                               XPathConstants.STRING);
        assertEquals("Hello cxf (was CeltixFire)", response);
    }
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) {
                return new FailureLocation((Location)node.getUserData(WSDLConstants.NODE_LOCATION),
                                           doc.getDocumentURI());
            }
        }
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.