Java Code Examples for javax.wsdl.Definition#getServices()

The following examples show how to use javax.wsdl.Definition#getServices() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Port getWSDLPort()
	throws IOException {
	Port port = wsdlPort;
	if( port == null && hasParameter( "wsdl" ) && getParameterFirstValue( "wsdl" ).hasChildren( "port" ) ) {
		String portName = getParameterFirstValue( "wsdl" ).getFirstChild( "port" ).strValue();
		Definition definition = getWSDLDefinition();
		if( definition != null ) {
			Map< QName, Service > services = definition.getServices();
			Iterator< Entry< QName, Service > > it = services.entrySet().iterator();
			while( port == null && it.hasNext() ) {
				port = it.next().getValue().getPort( portName );
			}
		}
		if( port != null ) {
			wsdlPort = port;
		}
	}
	return port;
}
 
Example 2
private String getPortName(Definition wsdl, BindingOperation operation) {
    Binding binding = null;
    final Map<QName, ?> bindings = wsdl.getBindings();
    for (Map.Entry<QName, ?> entry : bindings.entrySet()) {
        Binding examined = wsdl.getBinding((QName) entry.getKey());
        if (examined.getBindingOperations().contains(operation)) {
            binding = examined;
            break;
        }
    }
    Map<QName, Service> services = wsdl.getServices();
    for (Service service : services.values()) {
        Map<QName, Port> ports = service.getPorts();
        for (Port port : ports.values()) {
            if (port.getBinding().equals(binding)) {
                return port.getName();
            }
        }
    }
    return "";
}
 
Example 3
Source Project: cxf   File: WSDLDefinitionBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildSimpleWSDL() throws Exception {
    String qname = "http://apache.org/hello_world_soap_http";
    String wsdlUrl = getClass().getResource("hello_world.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());
    Service service = (Service)services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);
}
 
Example 4
Source Project: cxf   File: WSDLDefinitionBuilderTest.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source Project: cxf   File: WSDLManagerImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildSimpleWSDL() throws Exception {
    String qname = "http://apache.org/hello_world_soap_http";
    String wsdlUrl = getClass().getResource("hello_world.wsdl").toString();

    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(wsdlUrl);
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service)services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("SoapPort");
    assertNotNull(port);
}
 
Example 6
Source Project: syndesis   File: SoapApiModelParser.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void validateModel(Definition definition, SoapApiModelInfo.Builder builder) {
    final Map<QName, Service> services = definition.getServices();

    // check that WSDL has at least one Service
    if (services.isEmpty()) {
        addError(builder, "Missing Service in WSDL");
    } else {

        final List<QName> serviceNames = services.entrySet().stream()
                .filter(e -> !e.getValue().getPorts().isEmpty()) // ignore Services without Ports
                .map(Map.Entry::getKey)
                .sorted(Comparator.comparing(QName::toString))
                .collect(Collectors.toList());
        builder.services(serviceNames);

        // service MUST have a Port
        if (serviceNames.isEmpty()) {
            addError(builder, "Missing Service with Port in WSDL");
        } else {

            final Map<QName, List<String>> ports = services.entrySet().stream()
                    .collect(Collectors.toMap(Map.Entry::getKey, e -> ((Map<String, Port>) e.getValue().getPorts()).values().stream()
                            .filter(SoapApiModelParser::isaSoapPort)
                            .map(Port::getName)
                            .collect(Collectors.toList())));
            if (ports.isEmpty()) {
                addError(builder, "Missing Port with SOAP Address in WSDL");
            } else {
                builder.ports(ports);
            }
        }
    }
}
 
Example 7
Source Project: cxf   File: WSDLDefinitionBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source Project: cxf   File: WSDLManagerImplTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildImportedWSDL() throws Exception {
    String wsdlUrl = getClass().getResource("hello_world_services.wsdl").toString();

    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(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());
}
 
Example 9
Source Project: development   File: WSPortConnector.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Reads the WSDL and determines the target namespace.
 * 
 * @param locator
 *            The URL of the WSDL.
 * @param host
 *            optional the host to be used when the one from the wsdl must
 *            not be used
 * @return The service's target namespace.
 * @throws WSDLException
 *             Thrown in case the WSDL could not be evaluated.
 */
private WSPortDescription getServiceDetails(WSDLLocator locator, String host)
        throws WSDLException {
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();

    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    Definition serviceDefinition = wsdlReader.readWSDL(locator);
    String tns = serviceDefinition.getTargetNamespace();
    // read the port name
    String endpointURL = null;
    final Map<?, ?> services = serviceDefinition.getServices();
    if (services != null) {
        for (Object serviceValue : services.values()) {
            javax.wsdl.Service service = (javax.wsdl.Service) serviceValue;
            Map<?, ?> ports = service.getPorts();
            if (ports != null) {
                for (Object portValue : ports.values()) {
                    Port port = (Port) portValue;
                    List<?> extensibilityElements = port
                            .getExtensibilityElements();
                    for (Object ex : extensibilityElements) {
                        ExtensibilityElement ext = (ExtensibilityElement) ex;
                        if (ext instanceof SOAPAddress) {
                            SOAPAddress address = (SOAPAddress) ext;
                            endpointURL = address.getLocationURI();
                            if (host != null) {
                                int idx = endpointURL.indexOf("//") + 2;
                                String tmp = endpointURL.substring(0, idx)
                                        + host
                                        + endpointURL.substring(endpointURL
                                                .indexOf(':', idx));
                                endpointURL = tmp;
                            }
                        }
                    }
                }
            }
        }
    }

    WSPortDescription result = new WSPortDescription();
    result.setTargetNamespace(tns);
    result.setEndpointURL(endpointURL);
    Element versionElement = serviceDefinition.getDocumentationElement();
    if (versionElement != null) {
        result.setVersion(versionElement.getTextContent());
    }
    return result;
}
 
Example 10
Source Project: cxf   File: JAXWSDefinitionBuilderTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testBuildDefinitionWithXMLBinding() {
    String qname = "http://apache.org/hello_world_xml_http/bare";
    String wsdlUrl = getClass().getResource("resources/hello_world_xml_bare.wsdl").toString();

    JAXWSDefinitionBuilder builder = new JAXWSDefinitionBuilder();
    builder.setBus(BusFactory.getDefaultBus());
    builder.setContext(env);
    Definition def = builder.build(wsdlUrl);
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    Service service = (Service)services.get(new QName(qname, "XMLService"));
    assertNotNull(service);

    Map<?, ?> ports = service.getPorts();
    assertNotNull(ports);
    assertEquals(1, ports.size());
    Port port = service.getPort("XMLPort");
    assertNotNull(port);

    assertEquals(1, port.getExtensibilityElements().size());
    Object obj = port.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement)obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an AddressType",
               obj instanceof AddressType);

    Binding binding = port.getBinding();
    assertNotNull(binding);
    assertEquals(new QName(qname, "Greeter_XMLBinding"), binding.getQName());

    BindingOperation operation = binding.getBindingOperation("sayHi", null, null);
    assertNotNull(operation);

    BindingInput input = operation.getBindingInput();
    assertNotNull(input);
    assertEquals(1, input.getExtensibilityElements().size());
    obj = input.getExtensibilityElements().get(0);
    if (obj instanceof JAXBExtensibilityElement) {
        obj = ((JAXBExtensibilityElement)obj).getValue();
    }
    assertTrue(obj.getClass().getName() + " is not an XMLBindingMessageFormat",
               obj instanceof XMLBindingMessageFormat);
}
 
Example 11
Source Project: cxf   File: WSDLManagerImplTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testRemoveDefinition() throws Exception {
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }

    // Copy hello_world.wsdl so that we can delete it
    Path path1 = FileSystems.getDefault().getPath(basedir,
            "/src/test/resources/org/apache/cxf/wsdl11/hello_world.wsdl");
    Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/hello_world2.wsdl");
    Files.copy(path1, path2);

    // Load the resource
    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(path2.toString());
    assertNotNull(def);

    // Delete the resource
    Files.delete(path2);

    // Now load it again to test caching
    def = builder.getDefinition(path2.toString());
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    String qname = "http://apache.org/hello_world_soap_http";
    Service service = (Service) services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    // Now remove it
    builder.removeDefinition(def);

    // This time loading should fail as the original resource is removed
    try {
        builder.getDefinition(path2.toString());
        fail("Failure expected");
    } catch (NullPointerException ex) {
        // expected
    }
}
 
Example 12
Source Project: cxf   File: WSDLManagerImplTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testRemoveDefinitionByURL() throws Exception {
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }

    // Copy hello_world.wsdl so that we can delete it
    Path path1 = FileSystems.getDefault().getPath(basedir,
            "/src/test/resources/org/apache/cxf/wsdl11/hello_world.wsdl");
    Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/hello_world2.wsdl");
    Files.copy(path1, path2);

    // Load the resource
    WSDLManager builder = new WSDLManagerImpl();
    Definition def = builder.getDefinition(path2.toString());
    assertNotNull(def);

    // Delete the resource
    Files.delete(path2);

    // Now load it again to test caching
    def = builder.getDefinition(path2.toString());
    assertNotNull(def);

    Map<?, ?> services = def.getServices();
    assertNotNull(services);
    assertEquals(1, services.size());
    String qname = "http://apache.org/hello_world_soap_http";
    Service service = (Service) services.get(new QName(qname, "SOAPService"));
    assertNotNull(service);

    // Now remove it
    builder.removeDefinition(path2.toString());

    // This time loading should fail as the original resource is removed
    try {
        builder.getDefinition(path2.toString());
        fail("Failure expected");
    } catch (NullPointerException ex) {
        // expected
    }
}