This is an automated email from the ASF dual-hosted git repository. dkulp pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push: new d2f8885 [CXF-7979] Add another test case, document the 3 options to get it to work @ignore it for now as streaming isn't working. :( d2f8885 is described below commit d2f8885af9ec324ac8ba9e6b201b127922f59645 Author: Daniel Kulp <dk...@apache.org> AuthorDate: Mon Mar 25 12:22:06 2019 -0400 [CXF-7979] Add another test case, document the 3 options to get it to work @ignore it for now as streaming isn't working. :( --- .../apache/cxf/systest/ws/x509/X509TokenTest.java | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java index 70cbcb4..fa01fe1 100644 --- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java +++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/x509/X509TokenTest.java @@ -28,7 +28,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.XMLConstants; import javax.xml.namespace.QName; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.ws.BindingProvider; @@ -39,6 +42,7 @@ import javax.xml.ws.handler.MessageContext; import javax.xml.xpath.XPathConstants; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.w3c.dom.Node; import org.apache.cxf.Bus; @@ -47,6 +51,7 @@ import org.apache.cxf.bus.spring.SpringBusFactory; import org.apache.cxf.endpoint.Client; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.headers.Header; +import org.apache.cxf.helpers.DOMUtils; import org.apache.cxf.helpers.XPathUtils; import org.apache.cxf.jaxb.JAXBDataBinding; import org.apache.cxf.staxutils.StaxUtils; @@ -586,6 +591,66 @@ public class X509TokenTest extends AbstractBusClientServerTestBase { bus.shutdown(true); } + + @org.junit.Ignore("Streaming mode not working yet") + @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(); + + Element requestElement = xmlDocument.createElementNS("http://www.example.org/schema/DoubleIt", "tns:DoubleIt"); + requestElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:tns", + "http://www.example.org/schema/DoubleIt"); + Element dataElement = xmlDocument.createElement("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(); + + 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); + } + @org.junit.Test public void testAsymmetricSHA512() throws Exception {