Search in sources :

Example 1 with XPathUtils

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

the class PolicyAnnotationTest method testAnnotationImplNoInterface.

@org.junit.Test
public void testAnnotationImplNoInterface() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplNoInterface());
    factory.setStart(false);
    List<String> tp = Arrays.asList("http://schemas.xmlsoap.org/soap/http", "http://schemas.xmlsoap.org/wsdl/http/", "http://schemas.xmlsoap.org/wsdl/soap/http", "http://www.w3.org/2003/05/soap/bindings/HTTP/", "http://cxf.apache.org/transports/http/configuration", "http://cxf.apache.org/bindings/xformat");
    LocalTransportFactory f = new LocalTransportFactory();
    f.getUriPrefixes().add("http");
    f.setTransportIds(tp);
    Server s = factory.create();
    try {
        ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, s.getEndpoint().getService().getServiceInfos());
        Definition def = builder.build();
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        Element wsdl = wsdlWriter.getDocument(def).getDocumentElement();
        Map<String, String> ns = new HashMap<>();
        ns.put("wsdl", WSDLConstants.NS_WSDL11);
        ns.put("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
        ns.put("wsp", Constants.URI_POLICY_13_NS);
        XPathUtils xpu = new XPathUtils(ns);
        // org.apache.cxf.helpers.XMLUtils.printDOM(wsdl);
        assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/" + "wsp:PolicyReference[@URI='#TestImplNoInterfaceServiceSoapBindingBindingPolicy']", wsdl).getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 2 with XPathUtils

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

the class SoapFaultSerializerTest method assertValid.

private void assertValid(String xpathExpression, Document doc) {
    Map<String, String> namespaces = new HashMap<>();
    namespaces.put("s", "http://schemas.xmlsoap.org/soap/envelope/");
    namespaces.put("xsd", "http://www.w3.org/2001/XMLSchema");
    namespaces.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    namespaces.put("wsdlsoap", "http://schemas.xmlsoap.org/wsdl/soap/");
    namespaces.put("soap", "http://schemas.xmlsoap.org/soap/");
    namespaces.put("soap12env", "http://www.w3.org/2003/05/soap-envelope");
    namespaces.put("xml", "http://www.w3.org/XML/1998/namespace");
    XPathUtils xpu = new XPathUtils(namespaces);
    if (!xpu.isExist(xpathExpression, doc, XPathConstants.NODE)) {
        fail("Failed to select any nodes for expression:\n" + xpathExpression + " from document:\n" + StaxUtils.toString(doc));
    }
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils)

Example 3 with XPathUtils

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

the class ClientFaultConverter method setStackTrace.

private void setStackTrace(Fault fault, Message msg) {
    Throwable cause = null;
    Map<String, String> ns = new HashMap<>();
    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<>();
    if (!StringUtils.isEmpty(ss)) {
        Iterator<String> linesIterator = Arrays.asList(CAUSE_SUFFIX_SPLITTER.split(ss)).iterator();
        while (linesIterator.hasNext()) {
            String oneLine = linesIterator.next();
            if (oneLine.startsWith("Caused by:")) {
                cause = getCause(linesIterator, oneLine);
                break;
            }
            stackTraceList.add(parseStackTrackLine(oneLine));
        }
        if (!stackTraceList.isEmpty() || cause != null) {
            Exception e = msg.getContent(Exception.class);
            if (!stackTraceList.isEmpty()) {
                StackTraceElement[] stackTraceElement = new StackTraceElement[stackTraceList.size()];
                e.setStackTrace(stackTraceList.toArray(stackTraceElement));
            } else if (cause != null && cause.getMessage() != null && cause.getMessage().startsWith(e.getClass().getName())) {
                e.setStackTrace(cause.getStackTrace());
                if (cause.getCause() != null) {
                    e.initCause(cause.getCause());
                }
            } else if (cause != null) {
                e.initCause(cause);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) ArrayList(java.util.ArrayList) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 4 with XPathUtils

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

the class JaxWsServerFactoryBeanTest method testJaxwsServiceClass.

@Test
public void testJaxwsServiceClass() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(CalculatorPortType.class);
    factory.setServiceBean(new CalculatorImpl());
    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) 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) CalculatorImpl(org.apache.cxf.calculator.CalculatorImpl) Test(org.junit.Test)

Example 5 with XPathUtils

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

the class ClientServerRPCLitTest method testNoElementParts.

@Test
public void testNoElementParts() throws Exception {
    HttpURLConnection httpConnection = getHttpConnection("http://localhost:" + PORT + "/TestRPCWsdl?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("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());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HashMap(java.util.HashMap) InputStream(java.io.InputStream) XPathUtils(org.apache.cxf.helpers.XPathUtils) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) Test(org.junit.Test)

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