Search in sources :

Example 6 with BindingFault

use of javax.wsdl.BindingFault in project tomee by apache.

the class WsdlVisitor method walkTree.

public void walkTree() {
    begin();
    try {
        visit(definition);
        for (Iterator iterator = definition.getImports().entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String namespaceURI = (String) entry.getKey();
            List importsForNamespace = (List) entry.getValue();
            for (Iterator iterator1 = importsForNamespace.iterator(); iterator1.hasNext(); ) {
                Import anImport = (Import) iterator1.next();
                visit(anImport);
            }
        }
        visit(definition.getTypes());
        Collection messages = definition.getMessages().values();
        for (Iterator iterator = messages.iterator(); iterator.hasNext(); ) {
            Message message = (Message) iterator.next();
            visit(message);
            Collection parts = message.getParts().values();
            for (Iterator iterator2 = parts.iterator(); iterator2.hasNext(); ) {
                Part part = (Part) iterator2.next();
                visit(part);
            }
        }
        Collection services = definition.getServices().values();
        for (Iterator iterator = services.iterator(); iterator.hasNext(); ) {
            Service service = (Service) iterator.next();
            visit(service);
            Collection ports = service.getPorts().values();
            for (Iterator iterator1 = ports.iterator(); iterator1.hasNext(); ) {
                Port port = (Port) iterator1.next();
                visit(port);
                Binding binding = port.getBinding();
                visit(binding);
                List bindingOperations = binding.getBindingOperations();
                for (int i = 0; i < bindingOperations.size(); i++) {
                    BindingOperation bindingOperation = (BindingOperation) bindingOperations.get(i);
                    visit(bindingOperation);
                    visit(bindingOperation.getBindingInput());
                    visit(bindingOperation.getBindingOutput());
                    Collection bindingFaults = bindingOperation.getBindingFaults().values();
                    for (Iterator iterator2 = bindingFaults.iterator(); iterator2.hasNext(); ) {
                        BindingFault bindingFault = (BindingFault) iterator2.next();
                        visit(bindingFault);
                    }
                }
                PortType portType = binding.getPortType();
                visit(portType);
                List operations = portType.getOperations();
                for (int i = 0; i < operations.size(); i++) {
                    Operation operation = (Operation) operations.get(i);
                    visit(operation);
                    {
                        Input input = operation.getInput();
                        visit(input);
                    }
                    {
                        Output output = operation.getOutput();
                        visit(output);
                    }
                    Collection faults = operation.getFaults().values();
                    for (Iterator iterator2 = faults.iterator(); iterator2.hasNext(); ) {
                        Fault fault = (Fault) iterator2.next();
                        visit(fault);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    } finally {
        end();
    }
}
Also used : SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) Binding(javax.wsdl.Binding) Import(javax.wsdl.Import) Message(javax.wsdl.Message) BindingFault(javax.wsdl.BindingFault) Port(javax.wsdl.Port) Service(javax.wsdl.Service) BindingFault(javax.wsdl.BindingFault) Fault(javax.wsdl.Fault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingOperation(javax.wsdl.BindingOperation) BindingInput(javax.wsdl.BindingInput) Input(javax.wsdl.Input) Part(javax.wsdl.Part) BindingOutput(javax.wsdl.BindingOutput) Output(javax.wsdl.Output) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) Map(java.util.Map) PortType(javax.wsdl.PortType)

Example 7 with BindingFault

use of javax.wsdl.BindingFault 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)

Example 8 with BindingFault

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

the class WSDLToSoapProcessorTest method testDocLitWithFault.

@Test
public void testDocLitWithFault() throws Exception {
    String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world_doc_lit.wsdl") };
    WSDLToSoap.main(args);
    File outputFile = new File(output, "hello_world_doc_lit-soapbinding.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_Binding"));
        if (binding == null) {
            fail("Element wsdl:binding Greeter_Binding Missed!");
        }
        boolean found = false;
        for (Object obj : binding.getExtensibilityElements()) {
            SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
            if (soapBinding != null && soapBinding.getStyle().equalsIgnoreCase("document")) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail("Element soap:binding Missed!");
        }
        BindingOperation bo = binding.getBindingOperation("pingMe", null, null);
        if (bo == null) {
            fail("Element <wsdl:operation name=\"pingMe\"> Missed!");
        }
        found = false;
        for (Object obj : bo.getExtensibilityElements()) {
            SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
            if (soapOperation != null && soapOperation.getStyle().equalsIgnoreCase("document")) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail("Element soap:operation Missed!");
        }
        BindingFault fault = bo.getBindingFault("pingMeFault");
        if (fault == null) {
            fail("Element <wsdl:fault name=\"pingMeFault\"> Missed!");
        }
        found = false;
        for (Object obj : fault.getExtensibilityElements()) {
            if (SOAPBindingUtil.isSOAPFault(obj)) {
                found = true;
                break;
            }
        }
        if (!found) {
            fail("Element soap:fault Missed!");
        }
        List<SoapFault> faults = SOAPBindingUtil.getBindingOperationSoapFaults(bo);
        assertEquals(1, faults.size());
        assertEquals("pingMeFault", faults.get(0).getName());
    } 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) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) BindingFault(javax.wsdl.BindingFault) QName(javax.xml.namespace.QName) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) 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 9 with BindingFault

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

the class WSDLToCorbaBinding method addBindingOperations.

private void addBindingOperations(Definition definition, PortType portType, Binding binding) throws Exception {
    List<Operation> ops = CastUtils.cast(portType.getOperations());
    for (Operation op : ops) {
        try {
            BindingOperation bindingOperation = definition.createBindingOperation();
            addCorbaOperationExtElement(bindingOperation, op);
            bindingOperation.setName(op.getName());
            if (op.getInput() != null) {
                BindingInput bindingInput = definition.createBindingInput();
                bindingInput.setName(op.getInput().getName());
                bindingOperation.setBindingInput(bindingInput);
            }
            if (op.getOutput() != null) {
                BindingOutput bindingOutput = definition.createBindingOutput();
                bindingOutput.setName(op.getOutput().getName());
                bindingOperation.setBindingOutput(bindingOutput);
            }
            // add Faults
            if (op.getFaults() != null && op.getFaults().size() > 0) {
                Collection<Fault> faults = CastUtils.cast(op.getFaults().values());
                for (Fault fault : faults) {
                    BindingFault bindingFault = definition.createBindingFault();
                    bindingFault.setName(fault.getName());
                    bindingOperation.addBindingFault(bindingFault);
                }
            }
            bindingOperation.setOperation(op);
            binding.addBindingOperation(bindingOperation);
        } catch (Exception ex) {
            LOG.warning("Operation " + op.getName() + " not mapped to CORBA binding.");
        }
    }
}
Also used : BindingOperation(javax.wsdl.BindingOperation) BindingOutput(javax.wsdl.BindingOutput) BindingFault(javax.wsdl.BindingFault) Fault(javax.wsdl.Fault) BindingFault(javax.wsdl.BindingFault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingInput(javax.wsdl.BindingInput) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 10 with BindingFault

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

the class PartialWSDLProcessor method addSoapFaults.

private static void addSoapFaults(Operation op, BindingOperation bindingOperation, Definition wsdlDefinition, ExtensionRegistry extReg) throws Exception {
    Map<String, Fault> faults = CastUtils.cast(op.getFaults());
    for (Fault fault : faults.values()) {
        BindingFault bf = wsdlDefinition.createBindingFault();
        bf.setName(fault.getName());
        setSoapFaultExtElement(bf, extReg);
        bindingOperation.addBindingFault(bf);
    }
}
Also used : BindingFault(javax.wsdl.BindingFault) BindingFault(javax.wsdl.BindingFault) Fault(javax.wsdl.Fault) SOAPFault(javax.wsdl.extensions.soap.SOAPFault)

Aggregations

BindingFault (javax.wsdl.BindingFault)11 BindingOperation (javax.wsdl.BindingOperation)7 QName (javax.xml.namespace.QName)6 Fault (javax.wsdl.Fault)5 Binding (javax.wsdl.Binding)4 BindingInput (javax.wsdl.BindingInput)3 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)3 ToolException (org.apache.cxf.tools.common.ToolException)3 Test (org.junit.Test)3 File (java.io.File)2 BindingOutput (javax.wsdl.BindingOutput)2 Definition (javax.wsdl.Definition)2 Message (javax.wsdl.Message)2 Operation (javax.wsdl.Operation)2 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)2 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)2 SoapFault (org.apache.cxf.binding.soap.wsdl.extensions.SoapFault)2 SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)2 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2