use of javax.wsdl.Service in project cxf by apache.
the class WSDLDefinitionBuilderTest method testBuildImportedWSDLSpacesInPath.
@Test
public void testBuildImportedWSDLSpacesInPath() throws Exception {
WSDLDefinitionBuilder builder = new WSDLDefinitionBuilder(BusFactory.getDefaultBus());
String wsdlUrl = getClass().getResource("/folder with spaces/import_test.wsdl").toString();
Definition def = builder.build(wsdlUrl);
assertNotNull(def);
Map<?, ?> services = def.getServices();
assertNotNull(services);
assertEquals(1, services.size());
String serviceQName = "urn:S1importS2S3/resources/wsdl/S1importsS2S3Test1";
Service service = (Service) services.get(new QName(serviceQName, "S1importsS2S3TestService"));
assertNotNull(service);
Map<?, ?> ports = service.getPorts();
assertNotNull(ports);
assertEquals(1, ports.size());
Port port = service.getPort("S1importsS2S3TestPort");
assertNotNull(port);
}
use of javax.wsdl.Service in project cxf by apache.
the class WSDLDefinitionBuilderTest method testBuildImportedWSDL.
@Test
public void testBuildImportedWSDL() throws Exception {
String wsdlUrl = getClass().getResource("hello_world_services.wsdl").toString();
WSDLDefinitionBuilder builder = new WSDLDefinitionBuilder(BusFactory.getDefaultBus());
Definition def = builder.build(wsdlUrl);
assertNotNull(def);
Map<?, ?> services = def.getServices();
assertNotNull(services);
assertEquals(1, services.size());
String serviceQName = "http://apache.org/hello_world/services";
Service service = (Service) services.get(new QName(serviceQName, "SOAPService"));
assertNotNull(service);
Map<?, ?> ports = service.getPorts();
assertNotNull(ports);
assertEquals(1, ports.size());
Port port = service.getPort("SoapPort");
assertNotNull(port);
Binding binding = port.getBinding();
assertNotNull(binding);
QName bindingQName = new QName("http://apache.org/hello_world/bindings", "SOAPBinding");
assertEquals(bindingQName, binding.getQName());
PortType portType = binding.getPortType();
assertNotNull(portType);
QName portTypeQName = new QName("http://apache.org/hello_world", "Greeter");
assertEquals(portTypeQName, portType.getQName());
Operation op1 = portType.getOperation("sayHi", "sayHiRequest", "sayHiResponse");
assertNotNull(op1);
QName messageQName = new QName("http://apache.org/hello_world/messages", "sayHiRequest");
assertEquals(messageQName, op1.getInput().getMessage().getQName());
Part part = op1.getInput().getMessage().getPart("in");
assertNotNull(part);
assertEquals(new QName("http://apache.org/hello_world/types", "sayHi"), part.getElementName());
}
use of javax.wsdl.Service in project cxf by apache.
the class IDLToWSDLProcessor method generateCORBAService.
public void generateCORBAService(Definition def, Binding[] bindings, boolean isDefaultMapping) throws Exception {
Map<String, Service> serviceMap = new HashMap<>();
Map<String, String> serviceNames = getServiceNames(bindings, isDefaultMapping);
for (int i = 0; i < bindings.length; i++) {
QName portTypeName = bindings[i].getPortType().getQName();
Service service;
if (isDefaultMapping) {
service = def.createService();
service.setQName(new QName(def.getTargetNamespace(), portTypeName.getLocalPart() + "CORBAService"));
def.addService(service);
} else {
String ns = portTypeName.getNamespaceURI();
String serviceName = serviceNames.get(ns);
service = serviceMap.get(ns);
if (service == null) {
service = def.createService();
serviceMap.put(ns, service);
String[] serviceTokens = serviceName.split("\\.");
String serviceToken = serviceTokens[serviceTokens.length - 1];
QName serviceQName = new QName(def.getTargetNamespace(), serviceToken);
Service existingService = def.getService(serviceQName);
if (existingService != null) {
String existingServiceNS = ((Port) existingService.getPorts().values().iterator().next()).getBinding().getPortType().getQName().getNamespaceURI();
existingService.setQName(new QName(def.getTargetNamespace(), serviceNames.get(existingServiceNS)));
serviceMap.put(existingServiceNS, existingService);
service.setQName(new QName(def.getTargetNamespace(), serviceName));
} else {
service.setQName(serviceQName);
}
def.addService(service);
}
}
Port port = def.createPort();
port.setName(portTypeName.getLocalPart() + "CORBAPort");
AddressType address = (AddressType) def.getExtensionRegistry().createExtension(Port.class, CorbaConstants.NE_CORBA_ADDRESS);
String addr = null;
String addrFileName = (String) env.get(ToolCorbaConstants.CFG_ADDRESSFILE);
if (addrFileName != null) {
BufferedReader bufferedReader = null;
try {
File addrFile = new File(addrFileName);
FileReader fileReader = new FileReader(addrFile);
bufferedReader = new BufferedReader(fileReader);
addr = bufferedReader.readLine();
} catch (Exception ex) {
throw new ToolException(ex.getMessage(), ex);
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
}
} else {
addr = (String) env.get(ToolCorbaConstants.CFG_ADDRESS);
}
if (addr == null) {
addr = "IOR:";
}
address.setLocation(addr);
port.addExtensibilityElement((ExtensibilityElement) address);
service.addPort(port);
port.setBinding(bindings[i]);
}
}
use of javax.wsdl.Service in project cxf by apache.
the class PublishedEndpointUrlTest method testPublishedEndpointUrl.
@Test
public void testPublishedEndpointUrl() throws Exception {
Greeter implementor = new org.apache.hello_world_soap_http.GreeterImpl();
String publishedEndpointUrl = "http://cxf.apache.org/publishedEndpointUrl";
Bus bus = BusFactory.getDefaultBus();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setBus(bus);
svrFactory.setServiceClass(Greeter.class);
svrFactory.setAddress("http://localhost:" + PORT + "/publishedEndpointUrl");
svrFactory.setPublishedEndpointUrl(publishedEndpointUrl);
svrFactory.setServiceBean(implementor);
Server server = svrFactory.create();
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose", false);
URL url = new URL(svrFactory.getAddress() + "?wsdl=1");
HttpURLConnection connect = (HttpURLConnection) url.openConnection();
assertEquals(500, connect.getResponseCode());
Definition wsdl = wsdlReader.readWSDL(svrFactory.getAddress() + "?wsdl");
assertNotNull(wsdl);
Collection<Service> services = CastUtils.cast(wsdl.getAllServices().values());
final String failMesg = "WSDL provided incorrect soap:address location";
for (Service service : services) {
Collection<Port> ports = CastUtils.cast(service.getPorts().values());
for (Port port : ports) {
List<?> extensions = port.getExtensibilityElements();
for (Object extension : extensions) {
String actualUrl = null;
if (extension instanceof SOAP12Address) {
actualUrl = ((SOAP12Address) extension).getLocationURI();
} else if (extension instanceof SOAPAddress) {
actualUrl = ((SOAPAddress) extension).getLocationURI();
}
// System.out.println("Checking url: " + actualUrl + " against " + publishedEndpointUrl);
assertEquals(failMesg, publishedEndpointUrl, actualUrl);
}
}
}
server.stop();
server.destroy();
bus.shutdown(true);
}
use of javax.wsdl.Service in project cxf by apache.
the class CorbaObjectReferenceHelper method getServiceName.
public static QName getServiceName(Binding binding, Definition wsdlDef) {
LOG.log(Level.FINE, "Getting service name for an object reference");
Collection<Service> services = CastUtils.cast(wsdlDef.getServices().values());
for (Service serv : services) {
Collection<Port> ports = CastUtils.cast(serv.getPorts().values());
for (Port pt : ports) {
if (pt.getBinding().equals(binding)) {
return serv.getQName();
}
}
}
return null;
}
Aggregations