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