Search in sources :

Example 61 with Binding

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

the class WSDLToIDLAction method createInterface.

private IdlType createInterface(org.apache.cxf.binding.corba.wsdl.Object obj, IdlScopeBase scope, String local) throws Exception {
    IdlType result = null;
    QName bqname = obj.getBinding();
    Binding binding = def.getBinding(bqname);
    if (binding != null) {
        IdlDefn defn = scope.lookup(local);
        if (defn instanceof IdlInterface) {
            return (IdlInterface) defn;
        } else if (defn == null) {
            try {
                IdlInterface storedIntf = intf;
                intf = IdlInterface.create(scope, local);
                scope.holdForScope(intf);
                collectIdlDefns(binding);
                scope.promoteHeldToScope();
                result = intf;
                intf = storedIntf;
            } catch (Exception ex) {
                // NOPMD
                String msgStr = "Interface type " + intf.fullName() + " not found.";
                org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
                throw new Exception(msg.toString());
            }
        }
    }
    return result;
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) IdlDefn(org.apache.cxf.tools.corba.common.idltypes.IdlDefn) IdlInterface(org.apache.cxf.tools.corba.common.idltypes.IdlInterface) IdlString(org.apache.cxf.tools.corba.common.idltypes.IdlString) IdlType(org.apache.cxf.tools.corba.common.idltypes.IdlType) ToolException(org.apache.cxf.tools.common.ToolException) IdlException(org.apache.cxf.tools.corba.common.idltypes.IdlException)

Example 62 with Binding

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

the class WSDLToIDLAction method generateIDL.

public void generateIDL(Definition definition) throws Exception {
    if (definition == null) {
        typeProcessor.parseWSDL(wsdlFileName);
        def = typeProcessor.getWSDLDefinition();
    } else {
        def = definition;
    }
    if (printWriter == null) {
        printWriter = createPrintWriter(outputFile);
    }
    try (PrintWriter pw = printWriter != null ? printWriter : createPrintWriter(outputFile)) {
        if (!isGenerateAllBindings()) {
            Binding binding = findBinding(def);
            if (binding == null) {
                String msgStr = "Binding " + bindingName + " doesn't exists in WSDL.";
                org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
                throw new ToolException(msg.toString());
            }
            generateIDL(def, binding);
        } else {
            // generate idl for all bindings in the file.
            // each idl file will have the name of the binding.
            Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
            if (bindings.isEmpty()) {
                String msgStr = "No bindings exists within this WSDL.";
                org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
                throw new ToolException(msg.toString());
            }
            List<QName> portTypes = new ArrayList<>();
            for (Binding binding : bindings) {
                List<?> ext = binding.getExtensibilityElements();
                if (!(ext.get(0) instanceof BindingType)) {
                    continue;
                }
                if (portTypes.contains(binding.getPortType().getQName())) {
                    continue;
                }
                portTypes.add(binding.getPortType().getQName());
                generateIDL(def, binding);
                root = IdlRoot.create();
            }
        }
    }
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) IdlString(org.apache.cxf.tools.corba.common.idltypes.IdlString) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) ToolException(org.apache.cxf.tools.common.ToolException) PrintWriter(java.io.PrintWriter)

Example 63 with Binding

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

the class WSDLToCorbaBinding method generateCORBABinding.

public Binding[] generateCORBABinding(Definition definition) throws Exception {
    def = definition;
    helper.setWsdlDefinition(def);
    typeProcessor.setWSDLDefinition(def);
    wsdlParameter = new WSDLParameter();
    if (idlNamespace == null) {
        setIdlNamespace(def);
    }
    generateNSPrefix(def, getIdlNamespace(), "ns");
    typeProcessor.process();
    xmlSchemaList = typeProcessor.getXmlSchemaTypes();
    helper.setXMLSchemaList(xmlSchemaList);
    final List<PortType> intfs;
    if (!interfaceNames.isEmpty()) {
        intfs = new ArrayList<>(interfaceNames.size());
        for (String interfaceName : interfaceNames) {
            PortType portType = null;
            Map<QName, PortType> portTypes = CastUtils.cast(def.getAllPortTypes());
            if (portTypes != null) {
                for (Entry<QName, PortType> entry : portTypes.entrySet()) {
                    if (!entry.getKey().getLocalPart().equals(interfaceName)) {
                        portType = null;
                    } else {
                        portType = entry.getValue();
                        break;
                    }
                }
            }
            if (portType == null) {
                String msgStr = "PortType " + interfaceName + " doesn't exist in WSDL.";
                throw new ToolException(msgStr);
            }
            intfs.add(portType);
        }
    } else {
        // gets default portType or all portTypes.
        intfs = getPortTypeList();
    }
    Binding[] bindings = new Binding[intfs.size()];
    for (int i = 0; i < intfs.size(); i++) {
        bindings[i] = generateCORBABinding(def, intfs.get(i));
        generateCORBAServiceForBinding(def, intfs.get(i), bindings[i]);
    }
    return bindings;
}
Also used : Binding(javax.wsdl.Binding) QName(javax.xml.namespace.QName) ToolException(org.apache.cxf.tools.common.ToolException) PortType(javax.wsdl.PortType)

Example 64 with Binding

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

the class WSDLToCorbaBindingTest method testCORBABindingGeneration.

@Test
public void testCORBABindingGeneration() throws Exception {
    String fileName = getClass().getResource("/wsdl/simpleList.wsdl").toString();
    generator.setWsdlFile(fileName);
    generator.addInterfaceName("BasePortType");
    Definition model = generator.generateCORBABinding();
    QName bName = new QName("http://schemas.apache.org/tests", "BaseCORBABinding", "tns");
    Binding binding = model.getBinding(bName);
    assertNotNull(binding);
    assertEquals("BaseCORBABinding", binding.getQName().getLocalPart());
    assertEquals("BasePortType", binding.getPortType().getQName().getLocalPart());
    assertEquals(1, binding.getExtensibilityElements().size());
    assertEquals(1, binding.getBindingOperations().size());
    for (ExtensibilityElement extElement : getExtensibilityElements(binding)) {
        if ("binding".equals(extElement.getElementType().getLocalPart())) {
            BindingType bindingType = (BindingType) extElement;
            assertEquals(bindingType.getRepositoryID(), "IDL:BasePortType:1.0");
        }
    }
    Iterator<?> j = binding.getBindingOperations().iterator();
    while (j.hasNext()) {
        BindingOperation bindingOperation = (BindingOperation) j.next();
        assertEquals(1, bindingOperation.getExtensibilityElements().size());
        assertEquals(bindingOperation.getBindingInput().getName(), "echoString");
        assertEquals(bindingOperation.getBindingOutput().getName(), "echoStringResponse");
        for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
            if ("operation".equals(extElement.getElementType().getLocalPart())) {
                OperationType corbaOpType = (OperationType) extElement;
                assertEquals(corbaOpType.getName(), "echoString");
                assertEquals(3, corbaOpType.getParam().size());
                assertEquals(corbaOpType.getReturn().getName(), "return");
                assertEquals(corbaOpType.getReturn().getIdltype(), CorbaConstants.NT_CORBA_STRING);
                assertEquals(corbaOpType.getParam().get(0).getName(), "x");
                assertEquals(corbaOpType.getParam().get(0).getMode().value(), "in");
                QName qname = new QName("http://schemas.apache.org/tests/corba/typemap/", "StringEnum1", "ns1");
                assertEquals(corbaOpType.getParam().get(0).getIdltype(), qname);
            }
        }
    }
}
Also used : WSDLToCorbaBinding(org.apache.cxf.tools.corba.processors.wsdl.WSDLToCorbaBinding) Binding(javax.wsdl.Binding) BindingOperation(javax.wsdl.BindingOperation) QName(javax.xml.namespace.QName) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) Definition(javax.wsdl.Definition) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Test(org.junit.Test)

Example 65 with Binding

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

the class WSDLToCorbaBindingTest method testExceptionCORBABindingGeneration.

// next story to add Fault support
@Test
public void testExceptionCORBABindingGeneration() throws Exception {
    String fileName = getClass().getResource("/wsdl/exceptions.wsdl").toString();
    generator.setWsdlFile(fileName);
    generator.addInterfaceName("TestException.ExceptionTest");
    Definition model = generator.generateCORBABinding();
    QName bName = new QName("http://schemas.apache.org/idl/exceptions.idl", "TestException.ExceptionTestCORBABinding", "tns");
    Binding binding = model.getBinding(bName);
    assertNotNull(binding);
    assertEquals("TestException.ExceptionTestCORBABinding", binding.getQName().getLocalPart());
    assertEquals("TestException.ExceptionTest", binding.getPortType().getQName().getLocalPart());
    assertEquals(1, binding.getExtensibilityElements().size());
    assertEquals(1, binding.getBindingOperations().size());
    for (ExtensibilityElement extElement : getExtensibilityElements(binding)) {
        if ("binding".equals(extElement.getElementType().getLocalPart())) {
            BindingType bindingType = (BindingType) extElement;
            assertEquals(bindingType.getRepositoryID(), "IDL:TestException/ExceptionTest:1.0");
        }
    }
    Iterator<?> j = binding.getBindingOperations().iterator();
    while (j.hasNext()) {
        BindingOperation bindingOperation = (BindingOperation) j.next();
        assertEquals(1, bindingOperation.getExtensibilityElements().size());
        assertEquals(bindingOperation.getBindingInput().getName(), "review_data");
        assertEquals(bindingOperation.getBindingOutput().getName(), "review_dataResponse");
        Iterator<?> f = bindingOperation.getBindingFaults().values().iterator();
        boolean hasBadRecord = false;
        boolean hasMyException = false;
        while (f.hasNext()) {
            BindingFault bindingFault = (BindingFault) f.next();
            if ("TestException.BadRecord".equals(bindingFault.getName())) {
                hasBadRecord = true;
            } else if ("MyException".equals(bindingFault.getName())) {
                hasMyException = true;
            } else {
                fail("Unexpected BindingFault: " + bindingFault.getName());
            }
        }
        assertTrue("Did not get expected TestException.BadRecord", hasBadRecord);
        assertTrue("Did not get expected MyException", hasMyException);
        for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
            if ("operation".equals(extElement.getElementType().getLocalPart())) {
                OperationType corbaOpType = (OperationType) extElement;
                assertEquals(corbaOpType.getName(), "review_data");
                assertEquals(1, corbaOpType.getParam().size());
                assertEquals(2, corbaOpType.getRaises().size());
                hasBadRecord = false;
                hasMyException = false;
                for (int k = 0; k < corbaOpType.getRaises().size(); k++) {
                    String localPart = corbaOpType.getRaises().get(k).getException().getLocalPart();
                    if ("TestException.BadRecord".equals(localPart)) {
                        hasBadRecord = true;
                    } else if ("MyExceptionType".equals(localPart)) {
                        hasMyException = true;
                    } else {
                        fail("Unexpected Raises: " + localPart);
                    }
                }
                assertTrue("Did not find expected TestException.BadRecord", hasBadRecord);
                assertTrue("Did not find expected MyException", hasMyException);
            }
        }
    }
}
Also used : WSDLToCorbaBinding(org.apache.cxf.tools.corba.processors.wsdl.WSDLToCorbaBinding) Binding(javax.wsdl.Binding) BindingOperation(javax.wsdl.BindingOperation) BindingFault(javax.wsdl.BindingFault) QName(javax.xml.namespace.QName) BindingType(org.apache.cxf.binding.corba.wsdl.BindingType) Definition(javax.wsdl.Definition) OperationType(org.apache.cxf.binding.corba.wsdl.OperationType) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Test(org.junit.Test)

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