Search in sources :

Example 41 with BindingOperation

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

the class WSDLToXMLProcessor method addBindingOperation.

@SuppressWarnings("unchecked")
private void addBindingOperation() throws ToolException {
    List<Operation> ops = portType.getOperations();
    for (Operation op : ops) {
        BindingOperation bindingOperation = wsdlDefinition.createBindingOperation();
        bindingOperation.setName(op.getName());
        if (op.getInput() != null) {
            bindingOperation.setBindingInput(getBindingInput(op.getInput(), op.getName()));
        }
        if (op.getOutput() != null) {
            bindingOperation.setBindingOutput(getBindingOutput(op.getOutput(), op.getName()));
        }
        if (op.getFaults() != null && op.getFaults().size() > 0) {
            addXMLFaults(op, bindingOperation);
        }
        bindingOperation.setOperation(op);
        binding.addBindingOperation(bindingOperation);
    }
}
Also used : BindingOperation(javax.wsdl.BindingOperation) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation)

Example 42 with BindingOperation

use of javax.wsdl.BindingOperation 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 43 with BindingOperation

use of javax.wsdl.BindingOperation 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 44 with BindingOperation

use of javax.wsdl.BindingOperation 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 45 with BindingOperation

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

the class UniqueBodyPartsValidator method isValid.

public boolean isValid() {
    Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
    for (Binding binding : bindings) {
        uniqueBodyPartsMap = new HashMap<>();
        List<BindingOperation> ops = CastUtils.cast(binding.getBindingOperations());
        for (BindingOperation op : ops) {
            Operation operation = op.getOperation();
            if (operation != null && operation.getInput() != null) {
                Message inMessage = operation.getInput().getMessage();
                BindingInput bin = op.getBindingInput();
                Set<String> headers = new HashSet<>();
                if (bin != null) {
                    List<ExtensibilityElement> lst = CastUtils.cast(bin.getExtensibilityElements());
                    for (ExtensibilityElement ext : lst) {
                        if (!(ext instanceof SOAPHeader)) {
                            continue;
                        }
                        SOAPHeader header = (SOAPHeader) ext;
                        if (!header.getMessage().equals(inMessage.getQName())) {
                            continue;
                        }
                        headers.add(header.getPart());
                    }
                }
                if (inMessage != null && !isUniqueBodyPart(operation.getName(), inMessage, headers, binding.getQName())) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Binding(javax.wsdl.Binding) Message(javax.wsdl.Message) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) BindingInput(javax.wsdl.BindingInput) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) BindingOperation(javax.wsdl.BindingOperation) SOAPHeader(javax.wsdl.extensions.soap.SOAPHeader) HashSet(java.util.HashSet)

Aggregations

BindingOperation (javax.wsdl.BindingOperation)54 Binding (javax.wsdl.Binding)25 QName (javax.xml.namespace.QName)20 Operation (javax.wsdl.Operation)16 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)13 BindingInput (javax.wsdl.BindingInput)12 Test (org.junit.Test)12 File (java.io.File)9 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)9 OperationType (org.apache.cxf.binding.corba.wsdl.OperationType)9 Definition (javax.wsdl.Definition)8 Message (javax.wsdl.Message)8 BindingFault (javax.wsdl.BindingFault)7 Port (javax.wsdl.Port)7 Service (javax.wsdl.Service)7 SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)7 ToolException (org.apache.cxf.tools.common.ToolException)7 Input (javax.wsdl.Input)6 SOAPOperation (javax.wsdl.extensions.soap.SOAPOperation)6 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)6