Search in sources :

Example 11 with Service

use of javax.wsdl.Service in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method updateEndpoints.

/**
 * Clear the actual service endpoints in {@code definition} and use {@code selectedEndpoint} instead of
 * actual endpoints.
 *
 * @param selectedEndpoint Endpoint which will replace the WSDL endpoints
 * @param definition       WSDL Definition
 * @throws APIMgtWSDLException If an error occurred while updating endpoints
 */
private void updateEndpoints(String selectedEndpoint, Definition definition) throws APIMgtWSDLException {
    Map serviceMap = definition.getAllServices();
    for (Object service : serviceMap.entrySet()) {
        Map.Entry svcEntry = (Map.Entry) service;
        Service svc = (Service) svcEntry.getValue();
        Map portMap = svc.getPorts();
        for (Object o : portMap.entrySet()) {
            Map.Entry portEntry = (Map.Entry) o;
            Port port = (Port) portEntry.getValue();
            List extensibilityElementList = port.getExtensibilityElements();
            for (Object extensibilityElement : extensibilityElementList) {
                setAddressUrl(extensibilityElement, selectedEndpoint);
            }
        }
    }
}
Also used : Port(javax.wsdl.Port) Service(javax.wsdl.Service) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with Service

use of javax.wsdl.Service in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method getEndpoints.

/**
 * Get endpoints defined in the provided WSDL definition.
 *
 * @param definition WSDL Definition
 * @return a Map of endpoint names and their URIs.
 * @throws APIMgtWSDLException if error occurs while reading endpoints
 */
private Map<String, String> getEndpoints(Definition definition) throws APIMgtWSDLException {
    Map serviceMap = definition.getAllServices();
    Iterator serviceItr = serviceMap.entrySet().iterator();
    Map<String, String> serviceEndpointMap = new HashMap<>();
    while (serviceItr.hasNext()) {
        Map.Entry svcEntry = (Map.Entry) serviceItr.next();
        Service svc = (Service) svcEntry.getValue();
        Map portMap = svc.getPorts();
        for (Object o : portMap.entrySet()) {
            Map.Entry portEntry = (Map.Entry) o;
            Port port = (Port) portEntry.getValue();
            List extensibilityElementList = port.getExtensibilityElements();
            for (Object extensibilityElement : extensibilityElementList) {
                String addressURI = getAddressUrl(extensibilityElement);
                serviceEndpointMap.put(port.getName(), addressURI);
            }
        }
    }
    return serviceEndpointMap;
}
Also used : HashMap(java.util.HashMap) Port(javax.wsdl.Port) Iterator(java.util.Iterator) Service(javax.wsdl.Service) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Service

use of javax.wsdl.Service in project cxf by apache.

the class JAXWSDefinitionBuilderTest method testBuildDefinitionWithXMLBinding.

@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);
}
Also used : Binding(javax.wsdl.Binding) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) QName(javax.xml.namespace.QName) Port(javax.wsdl.Port) Definition(javax.wsdl.Definition) Service(javax.wsdl.Service) BindingInput(javax.wsdl.BindingInput) BindingOperation(javax.wsdl.BindingOperation) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) AddressType(org.apache.cxf.wsdl.http.AddressType) JAXWSDefinitionBuilder(org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder) Test(org.junit.Test)

Example 14 with Service

use of javax.wsdl.Service in project cxf by apache.

the class WSDLToServiceProcessorTest method testDefaultLocation.

@Test
public void testDefaultLocation() throws Exception {
    String[] args = new String[] { "-transport", "soap", "-e", "serviceins", "-p", "portins", "-n", "Greeter_SOAPBinding", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
    WSDLToService.main(args);
    File outputFile = new File(output, "hello_world-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "serviceins"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        boolean found = false;
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAPAddress) {
                SOAPAddress soapAddress = (SOAPAddress) obj;
                if (soapAddress.getLocationURI() != null && soapAddress.getLocationURI().equals("http://localhost:9000/serviceins/portins")) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            fail("Element soap:address of service port Missed!");
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) WSDLToService(org.apache.cxf.tools.misc.WSDLToService) Service(javax.wsdl.Service) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) Test(org.junit.Test)

Example 15 with Service

use of javax.wsdl.Service in project cxf by apache.

the class WSDLToServiceProcessorTest method testNewServiceSoap12.

@Test
public void testNewServiceSoap12() throws Exception {
    String[] args = new String[] { "-soap12", "-transport", "soap", "-e", "SOAPService", "-p", "SoapPort", "-n", "Greeter_SOAPBinding", "-a", "http://localhost:9000/SOAPService/SoapPort", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world_soap12.wsdl") };
    WSDLToService.main(args);
    File outputFile = new File(output, "hello_world_soap12-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "SOAPService"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("SoapPort").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAP12Address) {
                SOAP12Address soapAddress = (SOAP12Address) obj;
                assertNotNull(soapAddress.getLocationURI());
                assertEquals("http://localhost:9000/SOAPService/SoapPort", soapAddress.getLocationURI());
                break;
            }
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) WSDLToService(org.apache.cxf.tools.misc.WSDLToService) Service(javax.wsdl.Service) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) Test(org.junit.Test)

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