Search in sources :

Example 16 with WSDLWriter

use of javax.wsdl.xml.WSDLWriter in project cxf by apache.

the class PolicyAnnotationTest method testAnnotationImplNoInterfacePolicies.

@org.junit.Test
public void testAnnotationImplNoInterfacePolicies() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplWithPoliciesNoInterface());
    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='#TestImplWithPoliciesNoInterfaceServiceSoapBindingBindingPolicy']", wsdl).getLength());
        final EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 17 with WSDLWriter

use of javax.wsdl.xml.WSDLWriter in project cxf by apache.

the class PolicyAnnotationTest method testAnnotations.

@org.junit.Test
public void testAnnotations() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    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);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestImplPortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input", "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output", "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/", "TestImplServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input", "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output", "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestImplServiceServicePolicy");
        assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/" + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl).getLength());
        EndpointPolicy policy = bus.getExtension(PolicyEngine.class).getServerEndpointPolicy(s.getEndpoint().getEndpointInfo(), null, null);
        assertNotNull(policy);
        assertEquals(1, policy.getChosenAlternative().size());
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 18 with WSDLWriter

use of javax.wsdl.xml.WSDLWriter in project cxf by apache.

the class PolicyAnnotationTest method testAnnotationsInterfaceAsClass.

@org.junit.Test
public void testAnnotationsInterfaceAsClass() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImpl());
    factory.setServiceClass(TestInterface.class);
    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);
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/wsdl:port", "TestInterfacePortPortPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/", "TestInterfacePortTypePolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/", "echoIntPortTypeOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:input", "echoIntPortTypeOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:portType/wsdl:operation/wsdl:output", "echoIntPortTypeOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/", "TestInterfaceServiceSoapBindingBindingPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/", "echoIntBindingOpPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:input", "echoIntBindingOpInputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:binding/wsdl:operation/wsdl:output", "echoIntBindingOpOutputPolicy");
        check(xpu, wsdl, "/wsdl:definitions/wsdl:service/", "TestInterfaceServiceServicePolicy");
        assertEquals(1, xpu.getValueList("/wsdl:definitions/wsdl:binding/wsdl:operation/" + "wsp:PolicyReference[@URI='#echoIntBindingOpPolicy']", wsdl).getLength());
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) LocalTransportFactory(org.apache.cxf.transport.local.LocalTransportFactory) Element(org.w3c.dom.Element) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) XPathUtils(org.apache.cxf.helpers.XPathUtils) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 19 with WSDLWriter

use of javax.wsdl.xml.WSDLWriter in project cxf by apache.

the class WSDLGetUtils method writeWSDLDocument.

/**
 * Write the contents of a wsdl Definition object to a file.
 *
 * @param message
 * @param mp  a map of known wsdl Definition objects
 * @param smp a map of known xsd SchemaReference objects
 * @param wsdl name of the wsdl file to write
 * @param base the request URL
 * @param endpointInfo information for a web service 'port' inside of a service
 * @return Document
 * @throws WSDLException
 */
public Document writeWSDLDocument(Message message, Map<String, Definition> mp, Map<String, SchemaReference> smp, String wsdl, String base, EndpointInfo endpointInfo) throws WSDLException {
    Document doc;
    Bus bus = message.getExchange().getBus();
    Definition def = lookupDefinition(bus, mp, wsdl, base);
    String epurl = base;
    synchronized (def) {
        // writing a def is not threadsafe.  Sync on it to make sure
        // we don't get any ConcurrentModificationExceptions
        epurl = getPublishableEndpointUrl(def, epurl, endpointInfo);
        WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
        def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
        doc = wsdlWriter.getDocument(def);
    }
    updateDoc(doc, epurl, mp, smp, message, wsdl);
    return doc;
}
Also used : Bus(org.apache.cxf.Bus) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) Document(org.w3c.dom.Document)

Example 20 with WSDLWriter

use of javax.wsdl.xml.WSDLWriter in project cxf by apache.

the class TestUtilities method getWSDLDocument.

/**
 * Return a DOM tree for the WSDL for a server.
 *
 * @param server the server.
 * @return the DOM tree.
 * @throws WSDLException
 */
public Document getWSDLDocument(Server server) throws WSDLException {
    Definition definition = getWSDLDefinition(server);
    WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
    return writer.getDocument(definition);
}
Also used : Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter)

Aggregations

WSDLWriter (javax.wsdl.xml.WSDLWriter)22 Definition (javax.wsdl.Definition)14 HashMap (java.util.HashMap)9 IOException (java.io.IOException)7 WSDLException (javax.wsdl.WSDLException)7 Bus (org.apache.cxf.Bus)7 ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)7 Element (org.w3c.dom.Element)7 Writer (java.io.Writer)6 Server (org.apache.cxf.endpoint.Server)6 XPathUtils (org.apache.cxf.helpers.XPathUtils)6 ToolException (org.apache.cxf.tools.common.ToolException)6 Message (org.apache.cxf.common.i18n.Message)5 File (java.io.File)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 LocalTransportFactory (org.apache.cxf.transport.local.LocalTransportFactory)4 Document (org.w3c.dom.Document)4 QName (javax.xml.namespace.QName)3 EndpointPolicy (org.apache.cxf.ws.policy.EndpointPolicy)3 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)3