use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.
the class DocLiteralInInterceptorTest method testUnmarshalSourceDataWrapped.
@Test
public void testUnmarshalSourceDataWrapped() throws Exception {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("resources/docLitWrappedReq.xml"));
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
XMLStreamReader filteredReader = new PartialXMLStreamReader(reader, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"));
// advance the xml reader to the message parts
StaxUtils.read(filteredReader);
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
Message m = new MessageImpl();
// request to keep the document as wrapped
m.put(DocLiteralInInterceptor.KEEP_PARAMETERS_WRAPPER, true);
Exchange exchange = new ExchangeImpl();
Service service = control.createMock(Service.class);
exchange.put(Service.class, service);
EasyMock.expect(service.getDataBinding()).andReturn(new SourceDataBinding()).anyTimes();
EasyMock.expect(service.size()).andReturn(0).anyTimes();
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
exchange.put(Endpoint.class, endpoint);
// wrapped
OperationInfo operationInfo = new OperationInfo();
MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT, new QName(NS, "foo"));
messageInfo.addMessagePart(new MessagePartInfo(new QName(NS, "personId"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName(NS, "ssn"), null));
messageInfo.getMessagePart(0).setConcreteName(new QName(NS, "personId"));
messageInfo.getMessagePart(1).setConcreteName(new QName(NS, "ssn"));
operationInfo.setInput("inputName", messageInfo);
// wrapper
OperationInfo operationInfoWrapper = new OperationInfo();
MessageInfo messageInfoWrapper = new MessageInfo(operationInfo, Type.INPUT, new QName(NS, "foo"));
messageInfoWrapper.addMessagePart(new MessagePartInfo(new QName(NS, "GetPerson"), null));
messageInfoWrapper.getMessagePart(0).setConcreteName(new QName(NS, "GetPerson"));
operationInfoWrapper.setInput("inputName", messageInfoWrapper);
operationInfoWrapper.setUnwrappedOperation(operationInfo);
ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
EasyMock.expect(serviceInfo.getName()).andReturn(new QName("http://foo.com", "service")).anyTimes();
InterfaceInfo interfaceInfo = control.createMock(InterfaceInfo.class);
EasyMock.expect(serviceInfo.getInterface()).andReturn(interfaceInfo).anyTimes();
EasyMock.expect(interfaceInfo.getName()).andReturn(new QName("http://foo.com", "interface")).anyTimes();
BindingInfo bindingInfo = new BindingInfo(serviceInfo, "");
BindingOperationInfo boi = new BindingOperationInfo(bindingInfo, operationInfoWrapper);
exchange.put(BindingOperationInfo.class, boi);
EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
BindingInfo binding = control.createMock(BindingInfo.class);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
EasyMock.expect(endpointInfo.getBinding()).andReturn(binding).anyTimes();
EasyMock.expect(binding.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).anyTimes();
EasyMock.expect(endpointInfo.getName()).andReturn(new QName("http://foo.com", "endpoint")).anyTimes();
EasyMock.expect(endpointInfo.getProperty("URI", URI.class)).andReturn(new URI("dummy")).anyTimes();
List<OperationInfo> operations = new ArrayList<>();
EasyMock.expect(interfaceInfo.getOperations()).andReturn(operations).anyTimes();
m.setExchange(exchange);
m.put(Message.SCHEMA_VALIDATION_ENABLED, false);
m.setContent(XMLStreamReader.class, reader);
control.replay();
new DocLiteralInInterceptor().handleMessage(m);
MessageContentsList params = (MessageContentsList) m.getContent(List.class);
// we expect a wrapped document
assertEquals(1, params.size());
Map<String, String> ns = new HashMap<>();
ns.put("ns", NS);
XPathUtils xu = new XPathUtils(ns);
assertEquals("hello", xu.getValueString("//ns:GetPerson/ns:personId", ((DOMSource) params.get(0)).getNode().getFirstChild()));
assertEquals("1234", xu.getValueString("//ns:GetPerson/ns:ssn", ((DOMSource) params.get(0)).getNode().getFirstChild()));
}
use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.
the class JAXRSClientServerResourceCreatedSpringProviderTest method testPetStoreWadl.
@Test
public void testPetStoreWadl() throws Exception {
List<Element> resourceEls = getWadlResourcesInfo("http://localhost:" + PORT + "/webapp/pets", "http://localhost:" + PORT + "/webapp/pets/", 1);
checkPetStoreInfo(resourceEls.get(0));
Element el = (Element) resourceEls.get(0).getParentNode().getParentNode();
Map<String, String> namespaces = new HashMap<>();
namespaces.put("xsd", "http://www.w3.org/2001/XMLSchema");
namespaces.put("ns", "http://pets");
namespaces.put("wadl", "http://wadl.dev.java.net/2009/02");
XPathUtils xpu = new XPathUtils(namespaces);
assertValidType(xpu, "//xsd:element[@name='elstatus']/@type", "petStoreStatusElement", el);
assertValidType(xpu, "//xsd:schema[@targetNamespace='http://pets']/xsd:element[@name='status']/@type", "status", el);
assertValidType(xpu, "//xsd:element[@name='statusType']/@type", "statusType", el);
assertValidType(xpu, "//xsd:element[@name='statusImpl1']/@type", "petStoreStatusImpl1", el);
assertValidType(xpu, "//xsd:element[@name='statusImpl1']/@substitutionGroup", "statusType", el);
assertValidType(xpu, "//xsd:element[@name='statusImpl2']/@type", "petStoreStatusImpl2", el);
assertValidType(xpu, "//xsd:element[@name='statusImpl2']/@substitutionGroup", "statusType", el);
assertValid(xpu, "//wadl:representation[@element='prefix1:status']", el);
assertValid(xpu, "//wadl:representation[@element='prefix1:elstatus']", el);
assertValid(xpu, "//wadl:representation[@element='prefix1:statuses']", el);
assertValid(xpu, "//wadl:representation[@element='prefix1:statusType']", el);
}
use of org.apache.cxf.helpers.XPathUtils in project cxf by apache.
the class X509TokenTest method testAsymmetricIssuerSerialDispatchMessage.
@org.junit.Test
public void testAsymmetricIssuerSerialDispatchMessage() 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<SOAPMessage> disp = service.createDispatch(portQName, SOAPMessage.class, Mode.MESSAGE);
updateAddressPort(disp, test.getPort());
if (test.isStreaming()) {
SecurityTestUtil.enableStreaming(disp);
}
Document xmlDocument = DOMUtils.newDocument();
final String ns = "http://www.example.org/schema/DoubleIt";
Element requestElement = xmlDocument.createElementNS(ns, "tns:DoubleIt");
requestElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:tns", ns);
Element dataElement = xmlDocument.createElementNS(null, "numberToDouble");
dataElement.appendChild(xmlDocument.createTextNode("25"));
requestElement.appendChild(dataElement);
xmlDocument.appendChild(requestElement);
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage request = factory.createMessage();
request.getSOAPBody().appendChild(request.getSOAPPart().adoptNode(requestElement));
// 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
// this can be done in one of three ways:
// 1) set the WSDL_OPERATION context property
// QName wsdlOperationQName = new QName(NAMESPACE, "DoubleIt");
// disp.getRequestContext().put(MessageContext.WSDL_OPERATION, wsdlOperationQName);
// 2) Set the "find.dispatch.operation" to TRUE to have CXF explicitly try and determine it from the payload
disp.getRequestContext().put("find.dispatch.operation", Boolean.TRUE);
// 3) Turn on WS-Addressing as that will force #2
// TODO - add code for this, really is adding WS-Addressing feature to the createDispatch call above
SOAPMessage resp = disp.invoke(request);
Node nd = resp.getSOAPBody().getFirstChild();
XPathUtils xp = new XPathUtils(Collections.singletonMap("ns2", ns));
Object o = xp.getValue("//ns2:DoubleItResponse/doubledNumber", DOMUtils.getDomElement(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 AbstractWSATestBase method assertLogNotContains.
protected void assertLogNotContains(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);
assertNull(xpathu.getValueNode(xpath, doc.getDocumentElement()));
}
Aggregations