Search in sources :

Example 26 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class JaxWsServerFactoryBeanTest method testSimpleServiceClass.

@Test
public void testSimpleServiceClass() throws Exception {
    ServerFactoryBean factory = new ServerFactoryBean();
    factory.setServiceClass(Hello.class);
    String address = "http://localhost:9001/jaxwstest";
    factory.setAddress(address);
    Server server = factory.create();
    Endpoint endpoint = server.getEndpoint();
    ServiceInfo service = endpoint.getEndpointInfo().getService();
    assertNotNull(service);
    Bus bus = factory.getBus();
    Definition def = new ServiceWSDLBuilder(bus, service).build();
    WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
    Document doc = wsdlWriter.getDocument(def);
    Map<String, String> ns = new HashMap<>();
    ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils xpather = new XPathUtils(ns);
    xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding", doc, XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation", doc, XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='" + address + "']", doc, XPathConstants.NODE);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) Definition(javax.wsdl.Definition) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) WSDLWriter(javax.wsdl.xml.WSDLWriter) Document(org.w3c.dom.Document) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) XPathUtils(org.apache.cxf.helpers.XPathUtils) Test(org.junit.Test)

Example 27 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class ClientServerMiscTest method testAnonymousMinOccursConfig.

@Test
public void testAnonymousMinOccursConfig() throws Exception {
    HttpURLConnection httpConnection = getHttpConnection(ServerMisc.DOCLIT_CODEFIRST_SETTINGS_URL + "?wsdl");
    httpConnection.connect();
    assertEquals(200, httpConnection.getResponseCode());
    assertEquals("OK", httpConnection.getResponseMessage());
    InputStream in = httpConnection.getInputStream();
    assertNotNull(in);
    Document doc = StaxUtils.read(in);
    assertNotNull(doc);
    Map<String, String> ns = new HashMap<>();
    ns.put("soap", Soap11.SOAP_NAMESPACE);
    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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) InputStream(java.io.InputStream) XPathUtils(org.apache.cxf.helpers.XPathUtils) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) JaxbElementTest(org.apache.cxf.jaxb_element_test.JaxbElementTest) Test(org.junit.Test)

Example 28 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class ClientServerMiscTest method testWSDLDocs.

@Test
public void testWSDLDocs() throws Exception {
    Map<String, String> ns = new HashMap<>();
    ns.put("wsdl", WSDLConstants.NS_WSDL11);
    XPathUtils xpu = new XPathUtils(ns);
    Document wsdl = StaxUtils.read(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));
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Document(org.w3c.dom.Document) JaxbElementTest(org.apache.cxf.jaxb_element_test.JaxbElementTest) Test(org.junit.Test)

Example 29 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class ClientServerRPCLitTest method testDispatchClient.

@Test
public void testDispatchClient() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    Dispatch<Source> disp = service.createDispatch(portName, Source.class, javax.xml.ws.Service.Mode.PAYLOAD);
    updateAddressPort(disp, PORT);
    String req = "<ns1:sendReceiveData xmlns:ns1=\"http://apache.org/hello_world_rpclit\">" + "<in xmlns:ns2=\"http://apache.org/hello_world_rpclit/types\">" + "<ns2:elem1>elem1</ns2:elem1><ns2:elem2>elem2</ns2:elem2><ns2:elem3>45</ns2:elem3>" + "</in></ns1:sendReceiveData>";
    Source source = new StreamSource(new StringReader(req));
    Source resp = disp.invoke(source);
    assertNotNull(resp);
    Node nd = StaxUtils.read(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));
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) W3CNamespaceContext(org.apache.cxf.staxutils.W3CNamespaceContext) XPathUtils(org.apache.cxf.helpers.XPathUtils) StreamSource(javax.xml.transform.stream.StreamSource) Node(org.w3c.dom.Node) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 30 with XPathUtils

use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.

the class TestHandler method handleFault.

public boolean handleFault(T ctx) {
    methodCalled("handleFault");
    printHandlerInfo("handleFault", isOutbound(ctx));
    if (isServerSideHandler()) {
        if (!"handler2".equals(getHandlerId())) {
            return true;
        }
        DOMSource source = (DOMSource) ctx.getMessage().getPayload();
        Node node = source.getNode();
        Map<String, String> ns = new HashMap<>();
        ns.put("s", Soap11.SOAP_NAMESPACE);
        XPathUtils xu = new XPathUtils(ns);
        String exceptionText = (String) xu.getValue("//s:Fault/faultstring/text()", node, XPathConstants.STRING);
        if ("handler2HandleFaultThrowsRunException".equals(exceptionText)) {
            throw new RuntimeException("handler2 HandleFault throws RuntimeException");
        } else if ("handler2HandleFaultThrowsSOAPFaultException".equals(exceptionText)) {
            throw createSOAPFaultException("handler2 HandleFault " + "throws SOAPFaultException");
        }
    }
    return true;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Node(org.w3c.dom.Node)

Aggregations

XPathUtils (org.apache.cxf.helpers.XPathUtils)39 HashMap (java.util.HashMap)33 Document (org.w3c.dom.Document)26 Test (org.junit.Test)24 Element (org.w3c.dom.Element)22 Node (org.w3c.dom.Node)15 File (java.io.File)11 Bus (org.apache.cxf.Bus)9 Definition (javax.wsdl.Definition)7 QName (javax.xml.namespace.QName)7 StringReader (java.io.StringReader)6 WSDLWriter (javax.wsdl.xml.WSDLWriter)6 Server (org.apache.cxf.endpoint.Server)6 ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)6 URL (java.net.URL)5 InputStream (java.io.InputStream)4 Source (javax.xml.transform.Source)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)4 LocalTransportFactory (org.apache.cxf.transport.local.LocalTransportFactory)4