Search in sources :

Example 1 with ServiceWSDLBuilder

use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.

the class CodeFirstTest method createService.

private Definition createService(boolean wrapped) throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(Hello.class);
    bean.setWrapped(wrapped);
    Service service = bean.create();
    InterfaceInfo i = service.getServiceInfos().get(0).getInterface();
    assertEquals(5, i.getOperations().size());
    ServerFactoryBean svrFactory = new ServerFactoryBean();
    svrFactory.setBus(bus);
    svrFactory.setServiceFactory(bean);
    svrFactory.setAddress(address);
    svrFactory.create();
    Collection<BindingInfo> bindings = service.getServiceInfos().get(0).getBindings();
    assertEquals(1, bindings.size());
    ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, service.getServiceInfos().get(0));
    return wsdlBuilder.build();
}
Also used : Bus(org.apache.cxf.Bus) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) BindingInfo(org.apache.cxf.service.model.BindingInfo) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) GenericsService(org.apache.cxf.jaxws.service.GenericsService) ArrayService(org.apache.cxf.jaxws.service.ArrayService) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder)

Example 2 with ServiceWSDLBuilder

use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.

the class CodeFirstWSDLTest method testOnlyRootElementOnFaultBean.

@Test
public void testOnlyRootElementOnFaultBean() throws Exception {
    // CXF-4016
    EndpointImpl ep = (EndpointImpl) Endpoint.publish("local://foo4016", new CXF4016Impl());
    ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, ep.getService().getServiceInfos().get(0));
    Definition def = wsdlBuilder.build();
    Document d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
    this.addNamespace("http://www.example.org/contract/DoubleIt", "tns");
    // org.apache.cxf.helpers.XMLUtils.printDOM(d);
    assertXPathEquals("//xsd:element/@ref", new QName("http://www.example.org/contract/DoubleIt", "CustomMessageBean"), d);
}
Also used : QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Document(org.w3c.dom.Document) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) Test(org.junit.Test)

Example 3 with ServiceWSDLBuilder

use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.

the class CodeFirstWSDLTest method testDocumentationOnImpl.

@Test
public void testDocumentationOnImpl() throws Exception {
    // CXF-3092
    EndpointImpl ep = (EndpointImpl) Endpoint.publish("local://foo", new CXF3092Impl());
    ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, ep.getService().getServiceInfos().get(0));
    Definition def = wsdlBuilder.build();
    Document d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
    // org.apache.cxf.helpers.XMLUtils.printDOM(d);
    assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:service/wsdl:documentation", "My Service documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
    JaxwsServiceBuilder builder = new JaxwsServiceBuilder();
    builder.setServiceClass(CXF3092Impl.class);
    ServiceInfo serviceInfo = builder.createService();
    wsdlBuilder = new ServiceWSDLBuilder(bus, serviceInfo);
    def = wsdlBuilder.build();
    d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
    // org.apache.cxf.helpers.XMLUtils.printDOM(d);
    assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:service/wsdl:documentation", "My Service documentation", d.getDocumentElement());
    assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Definition(javax.wsdl.Definition) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Document(org.w3c.dom.Document) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) Test(org.junit.Test)

Example 4 with ServiceWSDLBuilder

use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.

the class JaxWsServerFactoryBeanTest method testJaxwsServiceClass.

@Test
public void testJaxwsServiceClass() throws Exception {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(CalculatorPortType.class);
    factory.setServiceBean(new CalculatorImpl());
    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);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) HashMap(java.util.HashMap) Definition(javax.wsdl.Definition) WSDLWriter(javax.wsdl.xml.WSDLWriter) Document(org.w3c.dom.Document) ServiceWSDLBuilder(org.apache.cxf.wsdl11.ServiceWSDLBuilder) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) XPathUtils(org.apache.cxf.helpers.XPathUtils) CalculatorImpl(org.apache.cxf.calculator.CalculatorImpl) Test(org.junit.Test)

Example 5 with ServiceWSDLBuilder

use of org.apache.cxf.wsdl11.ServiceWSDLBuilder in project cxf by apache.

the class PolicyAnnotationTest method testAnnotationImplNoInterface.

@org.junit.Test
public void testAnnotationImplNoInterface() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestImplNoInterface());
    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='#TestImplNoInterfaceServiceSoapBindingBindingPolicy']", 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)

Aggregations

ServiceWSDLBuilder (org.apache.cxf.wsdl11.ServiceWSDLBuilder)16 Definition (javax.wsdl.Definition)13 Bus (org.apache.cxf.Bus)10 HashMap (java.util.HashMap)7 WSDLWriter (javax.wsdl.xml.WSDLWriter)7 Test (org.junit.Test)7 Document (org.w3c.dom.Document)7 Server (org.apache.cxf.endpoint.Server)6 XPathUtils (org.apache.cxf.helpers.XPathUtils)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 Service (org.apache.cxf.service.Service)5 Element (org.w3c.dom.Element)5 WebService (javax.jws.WebService)4 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)4 LocalTransportFactory (org.apache.cxf.transport.local.LocalTransportFactory)4 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)3 EndpointPolicy (org.apache.cxf.ws.policy.EndpointPolicy)3 WSDLManager (org.apache.cxf.wsdl.WSDLManager)3 ReflectionServiceFactoryBean (org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean)3 Endpoint (org.apache.cxf.endpoint.Endpoint)2