Search in sources :

Example 51 with Binding

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

the class WSIBPValidator method checkBinding.

public boolean checkBinding() {
    for (PortType portType : wsdlHelper.getPortTypes(def)) {
        Iterator<?> ite = portType.getOperations().iterator();
        while (ite.hasNext()) {
            Operation operation = (Operation) ite.next();
            if (isOverloading(operation.getName())) {
                continue;
            }
            BindingOperation bop = wsdlHelper.getBindingOperation(def, operation.getName());
            if (bop == null) {
                addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2718") + "A wsdl:binding in a DESCRIPTION MUST have the same set of " + "wsdl:operations as the wsdl:portType to which it refers. " + operation.getName() + " not found in wsdl:binding.");
                return false;
            }
            Binding binding = wsdlHelper.getBinding(bop, def);
            String bindingStyle = binding != null ? SOAPBindingUtil.getBindingStyle(binding) : "";
            String style = StringUtils.isEmpty(SOAPBindingUtil.getSOAPOperationStyle(bop)) ? bindingStyle : SOAPBindingUtil.getSOAPOperationStyle(bop);
            if ("DOCUMENT".equalsIgnoreCase(style) || StringUtils.isEmpty(style)) {
                boolean passed = checkR2201Input(operation, bop) && checkR2201Output(operation, bop) && checkR2209(operation, bop) && checkR2716(bop);
                if (!passed) {
                    return false;
                }
            } else {
                if (!checkR2717AndR2726(bop)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : SOAPBinding(javax.jws.soap.SOAPBinding) Binding(javax.wsdl.Binding) BindingOperation(javax.wsdl.BindingOperation) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation) PortType(javax.wsdl.PortType)

Example 52 with Binding

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

the class WSIBPValidator method checkR2205.

// TODO: Should also check SoapHeader/SoapHeaderFault
public boolean checkR2205() {
    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {
        if (!SOAPBindingUtil.isSOAPBinding(binding)) {
            System.err.println("WSIBP Validator found <" + binding.getQName() + "> is NOT a SOAP binding");
            continue;
        }
        if (binding.getPortType() == null) {
            // will error later
            continue;
        }
        for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) {
            Operation operation = (Operation) ite2.next();
            Collection<Fault> faults = CastUtils.cast(operation.getFaults().values());
            if (CollectionUtils.isEmpty(faults)) {
                continue;
            }
            for (Fault fault : faults) {
                Message message = fault.getMessage();
                Collection<Part> parts = CastUtils.cast(message.getParts().values());
                for (Part part : parts) {
                    if (part.getElementName() == null) {
                        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2205") + "In Message " + message.getQName() + ", part " + part.getName() + " must specify a 'element' attribute");
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : SOAPBinding(javax.jws.soap.SOAPBinding) Binding(javax.wsdl.Binding) Message(javax.wsdl.Message) Part(javax.wsdl.Part) MIMEPart(javax.wsdl.extensions.mime.MIMEPart) Fault(javax.wsdl.Fault) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation)

Example 53 with Binding

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

the class WSDLRefValidator method collectValidationPointsForBindings.

private void collectValidationPointsForBindings() throws Exception {
    Map<QName, XNode> vBindingNodes = new HashMap<>();
    for (Service service : services.values()) {
        vBindingNodes.putAll(getBindings(service));
    }
    for (Map.Entry<QName, XNode> entry : vBindingNodes.entrySet()) {
        QName bName = entry.getKey();
        Binding binding = this.definition.getBinding(bName);
        if (binding == null) {
            LOG.log(Level.SEVERE, bName.toString() + " is not correct, please check that the correct namespace is being used");
            throw new Exception(bName.toString() + " is not correct, please check that the correct namespace is being used");
        }
        XNode vBindingNode = getXNode(binding);
        vBindingNode.setFailurePoint(entry.getValue());
        vNodes.add(vBindingNode);
        if (binding.getPortType() == null) {
            continue;
        }
        portTypeRefNames.add(binding.getPortType().getQName());
        XNode vPortTypeNode = getXNode(binding.getPortType());
        vPortTypeNode.setFailurePoint(vBindingNode);
        vNodes.add(vPortTypeNode);
        Collection<BindingOperation> bops = CastUtils.cast(binding.getBindingOperations());
        for (BindingOperation bop : bops) {
            XNode vOpNode = getOperationXNode(vPortTypeNode, bop.getName());
            XNode vBopNode = getOperationXNode(vBindingNode, bop.getName());
            vOpNode.setFailurePoint(vBopNode);
            vNodes.add(vOpNode);
            if (bop.getBindingInput() != null) {
                String inName = bop.getBindingInput().getName();
                if (!StringUtils.isEmpty(inName)) {
                    XNode vInputNode = getInputXNode(vOpNode, inName);
                    vInputNode.setFailurePoint(getInputXNode(vBopNode, inName));
                    vNodes.add(vInputNode);
                }
            }
            if (bop.getBindingOutput() != null) {
                String outName = bop.getBindingOutput().getName();
                if (!StringUtils.isEmpty(outName)) {
                    XNode vOutputNode = getOutputXNode(vOpNode, outName);
                    vOutputNode.setFailurePoint(getOutputXNode(vBopNode, outName));
                    vNodes.add(vOutputNode);
                }
            }
            for (Iterator<?> iter1 = bop.getBindingFaults().keySet().iterator(); iter1.hasNext(); ) {
                String faultName = (String) iter1.next();
                XNode vFaultNode = getFaultXNode(vOpNode, faultName);
                vFaultNode.setFailurePoint(getFaultXNode(vBopNode, faultName));
                vNodes.add(vFaultNode);
            }
        }
    }
}
Also used : XBinding(org.apache.cxf.tools.validator.internal.model.XBinding) Binding(javax.wsdl.Binding) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) XNode(org.apache.cxf.tools.validator.internal.model.XNode) Service(javax.wsdl.Service) XService(org.apache.cxf.tools.validator.internal.model.XService) URISyntaxException(java.net.URISyntaxException) ToolException(org.apache.cxf.tools.common.ToolException) BindingOperation(javax.wsdl.BindingOperation) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with Binding

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

the class JAXWSDefinitionBuilder method isRPCEncoded.

private boolean isRPCEncoded(Definition def) {
    Iterator<?> ite1 = def.getBindings().values().iterator();
    while (ite1.hasNext()) {
        Binding binding = (Binding) ite1.next();
        String bindingStyle = SOAPBindingUtil.getBindingStyle(binding);
        Iterator<?> ite2 = binding.getBindingOperations().iterator();
        while (ite2.hasNext()) {
            BindingOperation bop = (BindingOperation) ite2.next();
            String bopStyle = SOAPBindingUtil.getSOAPOperationStyle(bop);
            String outputUse = "";
            if (SOAPBindingUtil.getBindingOutputSOAPBody(bop) != null) {
                outputUse = SOAPBindingUtil.getBindingOutputSOAPBody(bop).getUse();
            }
            String inputUse = "";
            if (SOAPBindingUtil.getBindingInputSOAPBody(bop) != null) {
                inputUse = SOAPBindingUtil.getBindingInputSOAPBody(bop).getUse();
            }
            if ((SOAPBinding.Style.RPC.name().equalsIgnoreCase(bindingStyle) || SOAPBinding.Style.RPC.name().equalsIgnoreCase(bopStyle)) && (SOAPBinding.Use.ENCODED.name().equalsIgnoreCase(inputUse) || SOAPBinding.Use.ENCODED.name().equalsIgnoreCase(outputUse))) {
                return true;
            }
        }
    }
    return false;
}
Also used : SOAPBinding(javax.jws.soap.SOAPBinding) JAXWSBinding(org.apache.cxf.tools.wsdlto.frontend.jaxws.customization.JAXWSBinding) Binding(javax.wsdl.Binding) BindingOperation(javax.wsdl.BindingOperation)

Example 55 with Binding

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

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