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);
}
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);
}
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));
}
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());
}
Aggregations