Search in sources :

Example 16 with WSDLServiceFactory

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

the class STSClientTest method testWCFWsdl.

// A unit test to make sure that we can parse a WCF wsdl properly. See CXF-5817.
@Test
public void testWCFWsdl() throws Exception {
    Bus bus = BusFactory.getThreadDefaultBus();
    // Load WSDL
    InputStream inStream = getClass().getResourceAsStream("wcf.wsdl");
    Document doc = StaxUtils.read(inStream);
    NodeList metadataSections = doc.getElementsByTagNameNS("http://schemas.xmlsoap.org/ws/2004/09/mex", "MetadataSection");
    Element wsdlDefinition = null;
    List<Element> schemas = new ArrayList<>();
    for (int i = 0; i < metadataSections.getLength(); i++) {
        Node node = metadataSections.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            String dialect = element.getAttributeNS(null, "Dialect");
            if ("http://schemas.xmlsoap.org/wsdl/".equals(dialect)) {
                wsdlDefinition = DOMUtils.getFirstElement(element);
            } else if ("http://www.w3.org/2001/XMLSchema".equals(dialect)) {
                schemas.add(DOMUtils.getFirstElement(element));
            }
        }
    }
    assertNotNull(wsdlDefinition);
    assertTrue(!schemas.isEmpty());
    WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
    Definition definition = wsdlManager.getDefinition(wsdlDefinition);
    for (Element schemaElement : schemas) {
        QName schemaName = new QName(schemaElement.getNamespaceURI(), schemaElement.getLocalName());
        ExtensibilityElement exElement = wsdlManager.getExtensionRegistry().createExtension(Types.class, schemaName);
        ((Schema) exElement).setElement(schemaElement);
        definition.getTypes().addExtensibilityElement(exElement);
    }
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, definition);
    SourceDataBinding dataBinding = new SourceDataBinding();
    factory.setDataBinding(dataBinding);
    Service service = factory.create();
    service.setDataBinding(dataBinding);
}
Also used : Bus(org.apache.cxf.Bus) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) NodeList(org.w3c.dom.NodeList) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Schema(javax.wsdl.extensions.schema.Schema) ArrayList(java.util.ArrayList) Definition(javax.wsdl.Definition) Service(org.apache.cxf.service.Service) Document(org.w3c.dom.Document) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Test(org.junit.Test)

Example 17 with WSDLServiceFactory

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

the class TestBase method common.

protected void common(String wsdl, QName portName, Class<?>... jaxbClasses) throws Exception {
    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    WSDLManagerImpl manager = new WSDLManagerImpl();
    XMLWSDLExtensionLoader.registerExtensors(manager);
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andStubReturn(manager);
    BindingFactoryManager bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andStubReturn(bindingFactoryManager);
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
    control.replay();
    assertNotNull(bus.getExtension(WSDLManager.class));
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource(wsdl).toString(), new QName(portName.getNamespaceURI(), "XMLService"));
    org.apache.cxf.service.Service service = factory.create();
    EndpointInfo epi = service.getEndpointInfo(portName);
    serviceInfo = epi.getService();
    assertNotNull(epi);
    Binding xmlBinding = new XMLBindingFactory().createBinding(epi.getBinding());
    control.reset();
    JAXBDataBinding db = new JAXBDataBinding();
    db.initialize(service);
    db.setContext(JAXBContext.newInstance(jaxbClasses));
    service.setDataBinding(db);
    Endpoint endpoint = control.createMock(EndpointImpl.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andStubReturn(epi);
    EasyMock.expect(endpoint.getBinding()).andStubReturn(xmlBinding);
    EasyMock.expect(endpoint.getService()).andStubReturn(service);
    EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
    control.replay();
    xmlMessage.getExchange().put(Endpoint.class, endpoint);
    xmlMessage.getExchange().put(org.apache.cxf.service.Service.class, service);
}
Also used : Binding(org.apache.cxf.binding.Binding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Bus(org.apache.cxf.Bus) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) WSDLManager(org.apache.cxf.wsdl.WSDLManager) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) XMLBindingFactory(org.apache.cxf.binding.xml.XMLBindingFactory)

Example 18 with WSDLServiceFactory

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

the class CorbaServerConduitTest method setupServiceInfo.

protected void setupServiceInfo(String ns, String wsdl, String serviceName, String portName) {
    URL wsdlUrl = getClass().getResource(wsdl);
    assertNotNull(wsdlUrl);
    WSDLServiceFactory f = new WSDLServiceFactory(bus, wsdlUrl.toString(), new QName(ns, serviceName));
    Service service = f.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, portName));
}
Also used : WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) URL(java.net.URL)

Example 19 with WSDLServiceFactory

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

the class TestBase method setUp.

@Before
public void setUp() throws Exception {
    bus = BusFactory.newInstance().createBus();
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    IMocksControl control = createNiceControl();
    BindingFactory bf = control.createMock(BindingFactory.class);
    Binding binding = control.createMock(Binding.class);
    expect(bf.createBinding(null)).andStubReturn(binding);
    expect(binding.getInFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    expect(binding.getOutFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/org/apache/cxf/jaxb/resources/wsdl/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class }));
    service.setDataBinding(db);
    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);
    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
Also used : Binding(org.apache.cxf.binding.Binding) GreetMe(org.apache.hello_world_soap_http.types.GreetMe) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) BindingFactory(org.apache.cxf.binding.BindingFactory) Before(org.junit.Before)

Aggregations

WSDLServiceFactory (org.apache.cxf.wsdl11.WSDLServiceFactory)19 QName (javax.xml.namespace.QName)14 Service (org.apache.cxf.service.Service)12 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)8 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 URL (java.net.URL)6 Exchange (org.apache.cxf.message.Exchange)5 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)5 MessageImpl (org.apache.cxf.message.MessageImpl)5 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)5 SourceDataBinding (org.apache.cxf.databinding.source.SourceDataBinding)4 ClientImpl (org.apache.cxf.endpoint.ClientImpl)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Definition (javax.wsdl.Definition)3 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 WSDLManager (org.apache.cxf.wsdl.WSDLManager)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 WebService (javax.jws.WebService)2 Schema (javax.wsdl.extensions.schema.Schema)2