use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.
the class GenericExceptionTest method testGenericException.
@Test
public void testGenericException() throws Exception {
String address = "http://localhost:" + PORT + "/generic";
URL wsdlURL = new URL(address + "?wsdl");
// check wsdl element
InputStream ins = wsdlURL.openStream();
Document doc = StaxUtils.read(ins);
Map<String, String> ns = new HashMap<>();
ns.put("xsd", "http://www.w3.org/2001/XMLSchema");
ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
ns.put("tns", "http://cxf.apache.org/test/HelloService");
XPathUtils xpu = new XPathUtils(ns);
Node nd = xpu.getValueNode("//xsd:complexType[@name='objectWithGenerics']", doc);
assertNotNull(nd);
assertNotNull(xpu.getValueNode("//xsd:element[@name='a']", nd));
assertNotNull(xpu.getValueNode("//xsd:element[@name='b']", nd));
Service service = Service.create(wsdlURL, serviceName);
service.addPort(new QName("http://cxf.apache.org/test/HelloService", "HelloPort"), SOAPBinding.SOAP11HTTP_BINDING, address);
GenericsEcho port = service.getPort(new QName("http://cxf.apache.org/test/HelloService", "HelloPort"), GenericsEcho.class);
try {
port.echo("test");
fail("Exception is expected");
} catch (GenericsException e) {
ObjectWithGenerics<Boolean, Integer> genericObj = e.getObj();
assertTrue(genericObj.getA());
assertEquals(100, genericObj.getB().intValue());
}
}
use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.
the class AbstractWSATestBase method getLogValue.
protected String getLogValue(String log, String xpath) throws XMLStreamException {
String s = log.substring(log.indexOf("Payload: ") + 9);
Document doc = StaxUtils.read(new StringReader(s));
Map<String, String> ns = new HashMap<>();
ns.put("wsa", "http://www.w3.org/2005/08/addressing");
ns.put("soap", "http://schemas.xmlsoap.org/soap/envelope/");
XPathUtils xpathu = new XPathUtils(ns);
return xpathu.getValueString(xpath, doc.getDocumentElement());
}
use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.
the class X509TokenTest method testAsymmetricIssuerSerialDispatch.
@org.junit.Test
public void testAsymmetricIssuerSerialDispatch() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
URL busFile = X509TokenTest.class.getResource("client.xml");
Bus bus = bf.createBus(busFile.toString());
BusFactory.setDefaultBus(bus);
BusFactory.setThreadDefaultBus(bus);
URL wsdl = X509TokenTest.class.getResource("DoubleItX509.wsdl");
Service service = Service.create(wsdl, SERVICE_QNAME);
QName portQName = new QName(NAMESPACE, "DoubleItAsymmetricIssuerSerialOperationPort");
Dispatch<Source> disp = service.createDispatch(portQName, Source.class, Mode.PAYLOAD);
updateAddressPort(disp, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(disp);
}
// We need to set the wsdl operation name here, or otherwise the policy layer won't pick
// up the security policy attached at the operation level
QName wsdlOperationQName = new QName(NAMESPACE, "DoubleIt");
disp.getRequestContext().put(MessageContext.WSDL_OPERATION, wsdlOperationQName);
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();
}
XPathUtils xp = new XPathUtils(Collections.singletonMap("ns2", "http://www.example.org/schema/DoubleIt"));
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 Soap12ClientServerTest method testSayHiSoap12ToSoap11.
@Test
public void testSayHiSoap12ToSoap11() throws Exception {
HttpURLConnection httpConnection = getHttpConnection("http://localhost:" + PORT + "/SoapContext/Soap11Port/sayHi");
httpConnection.setDoOutput(true);
InputStream reqin = Soap12ClientServerTest.class.getResourceAsStream("sayHiSOAP12Req.xml");
assertNotNull("could not load test data", reqin);
httpConnection.setRequestMethod("POST");
httpConnection.addRequestProperty("Content-Type", "text/xml;charset=utf-8");
OutputStream reqout = httpConnection.getOutputStream();
IOUtils.copy(reqin, reqout);
reqout.close();
assertEquals(500, httpConnection.getResponseCode());
InputStream respin = httpConnection.getErrorStream();
assertNotNull(respin);
// we expect a soap 1.1 fault from the soap 1.1 test service that does not support soap 1.2
assertEquals("text/xml;charset=utf-8", stripSpaces(httpConnection.getContentType().toLowerCase()));
Document doc = StaxUtils.read(respin);
assertNotNull(doc);
Map<String, String> ns = new HashMap<>();
ns.put("soap11", Soap11.SOAP_NAMESPACE);
XPathUtils xu = new XPathUtils(ns);
Node fault = (Node) xu.getValue("/soap11:Envelope/soap11:Body/soap11:Fault", doc, XPathConstants.NODE);
assertNotNull(fault);
String codev = (String) xu.getValue("//faultcode/text()", fault, XPathConstants.STRING);
assertNotNull(codev);
assertTrue("VersionMismatch expected", codev.endsWith("VersionMismatch"));
}
use of org.apache.cxf.helpers.XPathUtils in project camel by apache.
the class CxfMtomProducerPayloadModeTest method testProducer.
@SuppressWarnings("unchecked")
@Test
public void testProducer() throws Exception {
if (MtomTestHelper.isAwtHeadless(logger, null)) {
return;
}
// START SNIPPET: producer
Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
List<Source> elements = new ArrayList<Source>();
elements.add(new DOMSource(StaxUtils.read(new StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement()));
CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), elements, null);
exchange.getIn().setBody(body);
exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
}
});
// process response
CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
Assert.assertEquals(1, out.getBody().size());
Map<String, String> ns = new HashMap<String, String>();
ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
ns.put("xop", MtomTestHelper.XOP_NS);
XPathUtils xu = new XPathUtils(ns);
Element oute = new XmlConverter().toDOMElement(out.getBody().get(0));
Element ele = (Element) xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", oute, XPathConstants.NODE);
// skip "cid:"
String photoId = ele.getAttribute("href").substring(4);
ele = (Element) xu.getValue("//ns:DetailResponse/ns:image/xop:Include", oute, XPathConstants.NODE);
// skip "cid:"
String imageId = ele.getAttribute("href").substring(4);
DataHandler dr = exchange.getOut().getAttachment(decodingReference(photoId));
Assert.assertEquals("application/octet-stream", dr.getContentType());
MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
dr = exchange.getOut().getAttachment(decodingReference(imageId));
Assert.assertEquals("image/jpeg", dr.getContentType());
BufferedImage image = ImageIO.read(dr.getInputStream());
Assert.assertEquals(560, image.getWidth());
Assert.assertEquals(300, image.getHeight());
// END SNIPPET: producer
}
Aggregations