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