Search in sources :

Example 16 with Service

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

the class WSDLToServiceProcessorTest method testNewService.

@Test
public void testNewService() throws Exception {
    String[] args = new String[] { "-transport", "soap", "-e", "serviceins", "-p", "portins", "-n", "Greeter_SOAPBinding", "-a", "http://localhost:9000/newservice/newport", "-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/newservice/newport")) {
                    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 17 with Service

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

the class WSDLToXMLProcessorTest method testAllDefault.

@Test
public void testAllDefault() throws Exception {
    String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
    WSDLToXML.main(args);
    File outputFile = new File(output, "hello_world-xmlbinding.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToXMLProcessor processor = new WSDLToXMLProcessor();
    processor.setEnvironment(env);
    processor.parseWSDL(outputFile.getAbsolutePath());
    Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLBinding"));
    if (binding == null) {
        fail("Element wsdl:binding Greeter_XMLBinding Missed!");
    }
    boolean found = false;
    for (Object obj : binding.getExtensibilityElements()) {
        if (obj instanceof XMLFormatBinding) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Element <xformat:binding/> Missed!");
    }
    BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
    if (bo == null) {
        fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
    }
    found = false;
    for (Object obj : bo.getBindingInput().getExtensibilityElements()) {
        if (obj instanceof XMLBindingMessageFormat && ((XMLBindingMessageFormat) obj).getRootNode().getLocalPart().equals("sayHi")) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Element <xformat:body rootNode=\"tns:sayHi\" /> Missed!");
    }
    Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_XMLService"));
    if (service == null) {
        fail("Element wsdl:service Greeter_XMLService Missed!");
    }
    found = false;
    for (Object obj : service.getPort("Greeter_XMLPort").getExtensibilityElements()) {
        if (obj instanceof HTTPAddress) {
            HTTPAddress xmlHttpAddress = (HTTPAddress) obj;
            if (xmlHttpAddress.getLocationURI() != null) {
                found = true;
                break;
            }
        }
    }
    if (!found) {
        fail("Element http:address of service port Missed!");
    }
}
Also used : XMLFormatBinding(org.apache.cxf.bindings.xformat.XMLFormatBinding) Binding(javax.wsdl.Binding) HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) BindingOperation(javax.wsdl.BindingOperation) XMLBindingMessageFormat(org.apache.cxf.bindings.xformat.XMLBindingMessageFormat) XMLFormatBinding(org.apache.cxf.bindings.xformat.XMLFormatBinding) File(java.io.File) Test(org.junit.Test)

Example 18 with Service

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

the class WSDLDefinitionBuilderTest method testBuildSimpleWSDL.

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

Example 19 with Service

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

the class BPELProcessProxy method genEPRfromWSDL.

/**
 * Get the EPR of this service from the WSDL.
 *
 * @param wsdlDef     WSDL Definition
 * @param serviceName service name
 * @param portName    port name
 * @return XML representation of the EPR
 */
public static Element genEPRfromWSDL(final Definition wsdlDef, final QName serviceName, final String portName) {
    Service serviceDef = wsdlDef.getService(serviceName);
    if (serviceDef != null) {
        Port portDef = serviceDef.getPort(portName);
        if (portDef != null) {
            Document doc = DOMUtils.newDocument();
            Element service = doc.createElementNS(Namespaces.WSDL_11, "service");
            service.setAttribute("name", serviceDef.getQName().getLocalPart());
            service.setAttribute("targetNamespace", serviceDef.getQName().getNamespaceURI());
            Element port = doc.createElementNS(Namespaces.WSDL_11, "port");
            service.appendChild(port);
            port.setAttribute("name", portDef.getName());
            port.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:bindns", portDef.getBinding().getQName().getNamespaceURI());
            port.setAttribute("bindns:binding", portDef.getName());
            for (Object extElmt : portDef.getExtensibilityElements()) {
                if (extElmt instanceof SOAPAddress) {
                    Element soapAddr = doc.createElementNS(Namespaces.SOAP_NS, "address");
                    port.appendChild(soapAddr);
                    soapAddr.setAttribute("location", ((SOAPAddress) extElmt).getLocationURI());
                } else if (extElmt instanceof HTTPAddress) {
                    Element httpAddr = doc.createElementNS(Namespaces.HTTP_NS, "address");
                    port.appendChild(httpAddr);
                    httpAddr.setAttribute("location", ((HTTPAddress) extElmt).getLocationURI());
                } else if (extElmt instanceof SOAP12Address) {
                    Element soap12Addr = doc.createElementNS(Namespaces.SOAP12_NS, "address");
                    port.appendChild(soap12Addr);
                    soap12Addr.setAttribute("location", ((SOAP12Address) extElmt).getLocationURI());
                } else {
                    port.appendChild(doc.importNode(((UnknownExtensibilityElement) extElmt).getElement(), true));
                }
            }
            return service;
        }
    }
    return null;
}
Also used : HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) Port(javax.wsdl.Port) OMElement(org.apache.axiom.om.OMElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Element(org.w3c.dom.Element) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Service(javax.wsdl.Service) AxisService(org.apache.axis2.description.AxisService) Document(org.w3c.dom.Document) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address)

Example 20 with Service

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

the class HTTPBindingHandler method inferBinding.

private void inferBinding() {
    Service serviceDef = wsdl.getService(serviceName);
    if (serviceDef == null) {
        throw new NullPointerException(Messages.msgServiceDefinitionNotFound(serviceName.getLocalPart()));
    }
    Port port = serviceDef.getPort(portName);
    if (port == null) {
        throw new NullPointerException(Messages.msgServicePortNotFound(serviceName.getLocalPart(), portName));
    }
    httpBinding = port.getBinding();
    if (httpBinding == null) {
        throw new NullPointerException(Messages.msgBindingNotFound(serviceName.getLocalPart(), portName));
    }
}
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