Search in sources :

Example 6 with XPathUtils

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

the class ToolSpec method getElementById.

public Element getElementById(String id) {
    Element ele = doc.getElementById(id);
    if (ele != null) {
        return ele;
    }
    XPathUtils xpather = new XPathUtils(new HashMap<String, String>());
    NodeList nl = (NodeList) xpather.getValue("//*[@id='" + id + "']", doc, XPathConstants.NODESET);
    if (nl != null && nl.getLength() > 0) {
        return (Element) nl.item(0);
    }
    return null;
}
Also used : XPathUtils(org.apache.cxf.helpers.XPathUtils) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList)

Example 7 with XPathUtils

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

the class SecurityPolicyTest method testDispatchClient.

@Test
public void testDispatchClient() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = SecurityPolicyTest.class.getResource("DoubleIt.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPortEncryptThenSign");
    Dispatch<Source> disp = service.createDispatch(portQName, Source.class, Mode.PAYLOAD);
    disp.getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, new KeystorePasswordCallback());
    disp.getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    disp.getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
    updateAddressPort(disp, PORT);
    String req = "<ns2:DoubleIt xmlns:ns2=\"http://www.example.org/schema/DoubleIt\">" + "<numberToDouble>25</numberToDouble></ns2:DoubleIt>";
    Source source = new StreamSource(new StringReader(req));
    source = disp.invoke(source);
    Node nd = StaxUtils.read(source);
    if (nd instanceof Document) {
        nd = ((Document) nd).getDocumentElement();
    }
    Map<String, String> ns = new HashMap<>();
    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(StaxUtils.toString(nd), "50", o);
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) Node(org.w3c.dom.Node) Service(javax.xml.ws.Service) Document(org.w3c.dom.Document) URL(java.net.URL) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) XPathUtils(org.apache.cxf.helpers.XPathUtils) StringReader(java.io.StringReader) KeystorePasswordCallback(org.apache.cxf.systest.ws.common.KeystorePasswordCallback) Test(org.junit.Test)

Example 8 with XPathUtils

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

the class JavaToProcessorTest method testPropOrderInException.

@Test
public void testPropOrderInException() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception_prop_order.wsdl");
    // env.put(ToolConstants.CFG_OUTPUTFILE, "/x1/tmp/exception_prop_order.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.EchoImpl");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception_prop_order.wsdl");
    assertTrue(wsdlFile.exists());
    Document doc = StaxUtils.read(wsdlFile);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils util = new XPathUtils(map);
    Element summary = (Element) util.getValueNode("//xsd:element[@name='summary']", doc);
    Element from = (Element) util.getValueNode("//xsd:element[@name='from']", doc);
    Element id = (Element) util.getValueNode("//xsd:element[@name='id']", doc);
    assertNotNull(summary);
    assertNotNull(from);
    assertNotNull(id);
    Node nd = summary.getNextSibling();
    while (nd != null) {
        if (nd == from) {
            from = null;
        } else if (nd == id) {
            if (from != null) {
                fail("id before from");
            }
            id = null;
        }
        nd = nd.getNextSibling();
    }
    assertNull(id);
    assertNull(from);
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test)

Example 9 with XPathUtils

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

the class JavaToProcessorTest method testExceptionTypeAdapter.

@Test
public void testExceptionTypeAdapter() throws Exception {
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/exception-type-adapter.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.TypeAdapterEcho");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    processor.setEnvironment(env);
    processor.process();
    File wsdlFile = new File(output, "exception-type-adapter.wsdl");
    assertTrue(wsdlFile.exists());
    Document doc = StaxUtils.read(wsdlFile);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    XPathUtils util = new XPathUtils(map);
    Node nd = util.getValueNode("//xsd:complexType[@name='myClass2']", doc);
    assertNotNull(nd);
    nd = util.getValueNode("//xsd:element[@name='adapted']", doc);
    assertNotNull(nd);
    String at = ((Element) nd).getAttribute("type");
    assertTrue(at.contains("myClass2"));
    assertEquals("0", ((Element) nd).getAttribute("minOccurs"));
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) Test(org.junit.Test)

Example 10 with XPathUtils

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

the class JavaToWSTest method testXmlList.

@Test
public void testXmlList() throws Exception {
    String[] args = new String[] { "-o", output.getPath() + "/xml-list.wsdl", "-verbose", "-wsdl", "org.apache.cxf.tools.fortest.xmllist.AddNumbersPortType" };
    CommandInterfaceUtils.commandCommonMain();
    JavaToWS j2w = new JavaToWS(args);
    j2w.run();
    File file = new File(output.getPath() + "/xml-list.wsdl");
    Document doc = StaxUtils.read(file);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils util = new XPathUtils(map);
    Element node = (Element) util.getValueNode("//xsd:list", doc);
    assertNotNull(node);
    assertTrue(node.getAttribute("itemType").contains("string"));
}
Also used : HashMap(java.util.HashMap) XPathUtils(org.apache.cxf.helpers.XPathUtils) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) File(java.io.File) 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