Search in sources :

Example 36 with Service

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);
}
Also used : QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) Test(org.junit.Test)

Example 37 with Service

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());
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) Operation(javax.wsdl.Operation) PortType(javax.wsdl.PortType) Test(org.junit.Test)

Example 38 with Service

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]);
    }
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) Service(javax.wsdl.Service) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ToolException(org.apache.cxf.tools.common.ToolException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ToolException(org.apache.cxf.tools.common.ToolException) AddressType(org.apache.cxf.binding.corba.wsdl.AddressType) File(java.io.File)

Example 39 with Service

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);
}
Also used : Bus(org.apache.cxf.Bus) Server(org.apache.cxf.endpoint.Server) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Greeter(org.apache.hello_world_soap_http.Greeter) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) WSDLReader(javax.wsdl.xml.WSDLReader) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) Test(org.junit.Test)

Example 40 with Service

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;
}
Also used : Port(javax.wsdl.Port) Service(javax.wsdl.Service)

Aggregations

Service (javax.wsdl.Service)53 Port (javax.wsdl.Port)37 QName (javax.xml.namespace.QName)28 Definition (javax.wsdl.Definition)21 Test (org.junit.Test)16 Binding (javax.wsdl.Binding)12 File (java.io.File)10 HashMap (java.util.HashMap)10 Map (java.util.Map)8 BindingOperation (javax.wsdl.BindingOperation)8 WSDLReader (javax.wsdl.xml.WSDLReader)8 SOAPAddress (javax.wsdl.extensions.soap.SOAPAddress)7 ToolException (org.apache.cxf.tools.common.ToolException)6 List (java.util.List)5 Operation (javax.wsdl.Operation)5 Part (javax.wsdl.Part)5 PortType (javax.wsdl.PortType)5 WSDLFactory (javax.wsdl.factory.WSDLFactory)5 Bus (org.apache.cxf.Bus)5 URI (java.net.URI)4