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;
}
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);
}
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);
}
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"));
}
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"));
}
Aggregations