Search in sources :

Example 56 with Binding

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

the class WSDLToSoapProcessorTest method testRpcLitWithoutFault.

@Test
public void testRpcLitWithoutFault() throws Exception {
    String[] args = new String[] { "-i", "GreeterRPCLit", "-n", "http://apache.org/hello_world_rpclit_test", "-b", "Greeter_SOAPBinding_NewBinding", "-style", "rpc", "-use", "literal", "-d", output.getCanonicalPath(), "-o", "hello_world_rpc_lit_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_rpc_lit.wsdl") };
    WSDLToSoap.main(args);
    File outputFile = new File(output, "hello_world_rpc_lit_newbinding.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToSoapProcessor processor = new WSDLToSoapProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_SOAPBinding_NewBinding"));
        if (binding == null) {
            fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
        }
        boolean found = false;
        for (Object obj : binding.getExtensibilityElements()) {
            SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
            if (soapBinding != null && soapBinding.getStyle().equalsIgnoreCase("rpc")) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail("Element soap:binding style=rpc Missed!");
        }
        BindingOperation bo = binding.getBindingOperation("sendReceiveData", null, null);
        if (bo == null) {
            fail("Element <wsdl:operation name=\"sendReceiveData\"> Missed!");
        }
        found = false;
        for (Object obj : bo.getExtensibilityElements()) {
            SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
            if (soapOperation != null && soapOperation.getStyle().equalsIgnoreCase("rpc")) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail("Element soap:operation style=rpc Missed!");
        }
        BindingInput bi = bo.getBindingInput();
        found = false;
        for (Object obj : bi.getExtensibilityElements()) {
            SoapBody soapBody = SOAPBindingUtil.getSoapBody(obj);
            if (soapBody != null && soapBody.getUse().equalsIgnoreCase("literal")) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail("Element soap:body use=literal Missed!");
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) QName(javax.xml.namespace.QName) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) BindingInput(javax.wsdl.BindingInput) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) BindingOperation(javax.wsdl.BindingOperation) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) Test(org.junit.Test)

Example 57 with Binding

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

the class WSDLToSoapProcessorTest method testWithoutBinding.

@Test
public void testWithoutBinding() throws Exception {
    String[] args = new String[] { "-i", "Greeter", "-b", "Greeter_SOAPBinding", "-d", output.getCanonicalPath(), "-o", "hello_world_soap_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_nobinding.wsdl") };
    WSDLToSoap.main(args);
    File outputFile = new File(output, "hello_world_soap_newbinding.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    assertTrue("Generated file is empty!", outputFile.length() > 0);
    WSDLToSoapProcessor processor = new WSDLToSoapProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_SOAPBinding"));
        if (binding == null) {
            fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
        }
        for (Object obj : binding.getExtensibilityElements()) {
            assertTrue(SOAPBindingUtil.isSOAPBinding(obj));
            assertTrue(obj instanceof SOAPBinding);
            SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
            assertNotNull(soapBinding);
            assertTrue("document".equalsIgnoreCase(soapBinding.getStyle()));
            assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(soapBinding.getTransportURI()));
        }
        BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
        if (bo == null) {
            fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
        }
        for (Object obj : bo.getExtensibilityElements()) {
            assertTrue(SOAPBindingUtil.isSOAPOperation(obj));
            assertTrue(obj instanceof SOAPOperation);
            SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
            assertNotNull(soapOperation);
            assertTrue("document".equalsIgnoreCase(soapOperation.getStyle()));
        }
        BindingInput bi = bo.getBindingInput();
        for (Object obj : bi.getExtensibilityElements()) {
            assertTrue(SOAPBindingUtil.isSOAPBody(obj));
            assertTrue(obj instanceof SOAPBody);
            SoapBody soapBody = SOAPBindingUtil.getSoapBody(obj);
            assertNotNull(soapBody);
            assertTrue("literal".equalsIgnoreCase(soapBody.getUse()));
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) QName(javax.xml.namespace.QName) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) BindingInput(javax.wsdl.BindingInput) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) BindingOperation(javax.wsdl.BindingOperation) SOAPBody(javax.wsdl.extensions.soap.SOAPBody) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) Test(org.junit.Test)

Example 58 with Binding

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

the class WSDLServiceFactory method create.

public Service create() {
    List<ServiceInfo> services;
    if (serviceName == null) {
        try {
            WSDLServiceBuilder builder = new WSDLServiceBuilder(getBus());
            builder.setAllowElementRefs(allowRefs);
            services = builder.buildServices(definition);
        } catch (XmlSchemaException ex) {
            throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
        }
        if (services.isEmpty()) {
            throw new ServiceConstructionException(new Message("NO_SERVICE_EXC", LOG));
        }
        // @@TODO  - this isn't good, need to return all the services
        serviceName = services.get(0).getName();
        // get all the service info's that match that first one.
        Iterator<ServiceInfo> it = services.iterator();
        while (it.hasNext()) {
            if (!it.next().getName().equals(serviceName)) {
                it.remove();
            }
        }
    } else {
        javax.wsdl.Service wsdlService = definition.getService(serviceName);
        if (wsdlService == null) {
            if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName)) && (!PartialWSDLProcessor.isBindingExisted(definition, serviceName)) && (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
                try {
                    Map<QName, PortType> portTypes = CastUtils.cast(definition.getAllPortTypes());
                    String existPortName = null;
                    PortType portType = null;
                    for (Map.Entry<QName, PortType> entry : portTypes.entrySet()) {
                        existPortName = entry.getKey().getLocalPart();
                        if (serviceName.getLocalPart().contains(existPortName)) {
                            portType = entry.getValue();
                            break;
                        }
                    }
                    WSDLFactory factory = WSDLFactory.newInstance();
                    ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
                    Binding binding = PartialWSDLProcessor.doAppendBinding(definition, existPortName, portType, extReg);
                    definition.addBinding(binding);
                    wsdlService = PartialWSDLProcessor.doAppendService(definition, existPortName, extReg, binding);
                    definition.addService(wsdlService);
                } catch (Exception e) {
                    throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
                }
            } else {
                throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
            }
        }
        try {
            services = new WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService, endpointName);
            if (services.isEmpty()) {
                throw new ServiceConstructionException(new Message("NO_SUCH_ENDPOINT_EXC", LOG, endpointName));
            }
        } catch (XmlSchemaException ex) {
            throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
        }
    }
    ServiceImpl service = new ServiceImpl(services);
    setService(service);
    return service;
}
Also used : Binding(javax.wsdl.Binding) Message(org.apache.cxf.common.i18n.Message) XmlSchemaException(org.apache.ws.commons.schema.XmlSchemaException) QName(javax.xml.namespace.QName) ServiceImpl(org.apache.cxf.service.ServiceImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) XmlSchemaException(org.apache.ws.commons.schema.XmlSchemaException) WSDLException(javax.wsdl.WSDLException) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) WSDLFactory(javax.wsdl.factory.WSDLFactory) Map(java.util.Map) PortType(javax.wsdl.PortType)

Example 59 with Binding

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

the class ServiceWSDLBuilderTest method testBinding.

@Test
public void testBinding() throws Exception {
    setupWSDL(WSDL_PATH);
    assertEquals(newDef.getBindings().size(), 1);
    Binding binding = newDef.getBinding(new QName(newDef.getTargetNamespace(), "Greeter_SOAPBinding"));
    assertNotNull(binding);
    assertEquals(4, binding.getBindingOperations().size());
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) Test(org.junit.Test)

Example 60 with Binding

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

the class ServiceWSDLBuilder method buildBinding.

protected void buildBinding(Definition definition, Collection<BindingInfo> bindingInfos, Collection<PortType> portTypes) {
    for (BindingInfo bindingInfo : bindingInfos) {
        final Binding binding = definition.createBinding();
        addDocumentation(binding, bindingInfo.getDocumentation());
        binding.setUndefined(false);
        for (PortType portType : portTypes) {
            if (portType.getQName().equals(bindingInfo.getInterface().getName())) {
                binding.setPortType(portType);
                break;
            }
        }
        binding.setQName(bindingInfo.getName());
        if (!bindingInfo.getName().getNamespaceURI().equals(definition.getTargetNamespace())) {
            addNamespace(bindingInfo.getName().getNamespaceURI(), definition);
        }
        buildBindingOperation(definition, binding, bindingInfo.getOperations());
        addExtensibilityElements(definition, binding, getWSDL11Extensors(bindingInfo));
        definition.addBinding(binding);
    }
}
Also used : Binding(javax.wsdl.Binding) BindingInfo(org.apache.cxf.service.model.BindingInfo) PortType(javax.wsdl.PortType)

Aggregations

Binding (javax.wsdl.Binding)69 QName (javax.xml.namespace.QName)39 BindingOperation (javax.wsdl.BindingOperation)28 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)22 Definition (javax.wsdl.Definition)18 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)18 Test (org.junit.Test)18 Port (javax.wsdl.Port)17 Operation (javax.wsdl.Operation)16 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)15 PortType (javax.wsdl.PortType)14 Service (javax.wsdl.Service)12 BindingType (org.apache.cxf.binding.corba.wsdl.BindingType)12 ToolException (org.apache.cxf.tools.common.ToolException)12 File (java.io.File)9 ArrayList (java.util.ArrayList)8 BindingInput (javax.wsdl.BindingInput)8 Message (javax.wsdl.Message)8 Map (java.util.Map)7 HashSet (java.util.HashSet)6