Search in sources :

Example 1 with SoapFault

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.

the class SoapBindingFactory method createSoapBinding.

private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
    boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
    Bus bs = getBus();
    WSDLManager m = bs.getExtension(WSDLManager.class);
    ExtensionRegistry extensionRegistry = m.getExtensionRegistry();
    SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
    soapBinding.setStyle(bi.getStyle());
    soapBinding.setTransportURI(bi.getTransportURI());
    bi.addExtensor(soapBinding);
    for (BindingOperationInfo b : bi.getOperations()) {
        for (BindingFaultInfo faultInfo : b.getFaults()) {
            SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
            soapFault.setUse("literal");
            soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
            faultInfo.addExtensor(soapFault);
        }
        SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);
        SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
        soapOperation.setSoapActionURI(soi.getAction());
        soapOperation.setStyle(soi.getStyle());
        boolean isRpc = "rpc".equals(soapOperation.getStyle());
        b.addExtensor(soapOperation);
        if (b.getInput() != null) {
            List<String> bodyParts = null;
            List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
            if (headerInfos != null && !headerInfos.isEmpty()) {
                bodyParts = new ArrayList<>();
                for (MessagePartInfo part : b.getInput().getMessageParts()) {
                    bodyParts.add(part.getName().getLocalPart());
                }
                for (SoapHeaderInfo headerInfo : headerInfos) {
                    SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
                    soapHeader.setMessage(b.getInput().getMessageInfo().getName());
                    soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
                    soapHeader.setUse("literal");
                    bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
                    headerInfo.getPart().setProperty(HEADER, true);
                    b.getInput().addExtensor(soapHeader);
                }
            }
            SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
            body.setUse("literal");
            if (isRpc) {
                body.setNamespaceURI(b.getName().getNamespaceURI());
            }
            if (bodyParts != null) {
                body.setParts(bodyParts);
            }
            b.getInput().addExtensor(body);
        }
        if (b.getOutput() != null) {
            List<String> bodyParts = null;
            List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
            if (headerInfos != null && !headerInfos.isEmpty()) {
                bodyParts = new ArrayList<>();
                for (MessagePartInfo part : b.getOutput().getMessageParts()) {
                    bodyParts.add(part.getName().getLocalPart());
                }
                for (SoapHeaderInfo headerInfo : headerInfos) {
                    SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
                    soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
                    soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
                    soapHeader.setUse("literal");
                    bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
                    b.getOutput().addExtensor(soapHeader);
                }
            }
            SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
            body.setUse("literal");
            if (isRpc) {
                body.setNamespaceURI(b.getName().getNamespaceURI());
            }
            if (bodyParts != null) {
                body.setParts(bodyParts);
            }
            b.getOutput().addExtensor(body);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry) WSDLManager(org.apache.cxf.wsdl.WSDLManager) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 2 with SoapFault

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.

the class WSIBPValidator method checkR2717AndR2726.

private boolean checkR2717AndR2726(final BindingOperation bop) {
    if (null == bop) {
        return true;
    }
    SoapBody inSoapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
    SoapBody outSoapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
    if (inSoapBody != null && StringUtils.isEmpty(inSoapBody.getNamespaceURI()) || outSoapBody != null && StringUtils.isEmpty(outSoapBody.getNamespaceURI())) {
        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2717") + "soapBody in the input/output of the binding operation '" + bop.getName() + "' MUST have namespace attribute");
        return false;
    }
    SoapHeader inSoapHeader = SOAPBindingUtil.getBindingInputSOAPHeader(bop);
    SoapHeader outSoapHeader = SOAPBindingUtil.getBindingOutputSOAPHeader(bop);
    if (inSoapHeader != null && !StringUtils.isEmpty(inSoapHeader.getNamespaceURI()) || outSoapHeader != null && !StringUtils.isEmpty(outSoapHeader.getNamespaceURI())) {
        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2726") + "Operation '" + bop.getName() + "' soapHeader MUST NOT have namespace attribute");
        return false;
    }
    List<SoapFault> soapFaults = SOAPBindingUtil.getBindingOperationSoapFaults(bop);
    for (SoapFault fault : soapFaults) {
        if (!StringUtils.isEmpty(fault.getNamespaceURI())) {
            addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2726") + "Operation '" + bop.getName() + "' soapFault MUST NOT have namespace attribute");
            return false;
        }
    }
    return true;
}
Also used : SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)

Example 3 with SoapFault

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.

the class WSDLToSoapProcessor method setSoapFaultExtElement.

private void setSoapFaultExtElement(BindingFault bf) throws ToolException {
    if (extReg == null) {
        extReg = wsdlFactory.newPopulatedExtensionRegistry();
    }
    final SoapFault soapFault;
    try {
        soapFault = SOAPBindingUtil.createSoapFault(extReg, isSOAP12());
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
        throw new ToolException(msg, wse);
    }
    soapFault.setName(bf.getName());
    soapFault.setUse((String) env.get(ToolConstants.CFG_USE));
    if (WSDLConstants.RPC.equalsIgnoreCase((String) env.get(ToolConstants.CFG_STYLE)) && env.optionSet(ToolConstants.CFG_NAMESPACE)) {
        soapFault.setNamespaceURI((String) env.get(ToolConstants.CFG_NAMESPACE));
    }
    bf.addExtensibilityElement(soapFault);
}
Also used : SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 4 with SoapFault

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.

the class WSIBPValidator method checkR2716.

private boolean checkR2716(final BindingOperation bop) {
    SoapBody inSoapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
    SoapBody outSoapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
    if (inSoapBody != null && !StringUtils.isEmpty(inSoapBody.getNamespaceURI()) || outSoapBody != null && !StringUtils.isEmpty(outSoapBody.getNamespaceURI())) {
        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2716") + "Operation '" + bop.getName() + "' soapBody MUST NOT have namespace attribute");
        return false;
    }
    SoapHeader inSoapHeader = SOAPBindingUtil.getBindingInputSOAPHeader(bop);
    SoapHeader outSoapHeader = SOAPBindingUtil.getBindingOutputSOAPHeader(bop);
    if (inSoapHeader != null && !StringUtils.isEmpty(inSoapHeader.getNamespaceURI()) || outSoapHeader != null && !StringUtils.isEmpty(outSoapHeader.getNamespaceURI())) {
        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2716") + "Operation '" + bop.getName() + "' soapHeader MUST NOT have namespace attribute");
        return false;
    }
    List<SoapFault> soapFaults = SOAPBindingUtil.getBindingOperationSoapFaults(bop);
    for (SoapFault fault : soapFaults) {
        if (!StringUtils.isEmpty(fault.getNamespaceURI())) {
            addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2716") + "Operation '" + bop.getName() + "' soapFault MUST NOT have namespace attribute");
            return false;
        }
    }
    return true;
}
Also used : SoapFault(org.apache.cxf.binding.soap.wsdl.extensions.SoapFault) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)

Example 5 with SoapFault

use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault 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

SoapFault (org.apache.cxf.binding.soap.wsdl.extensions.SoapFault)5 SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)3 SoapHeader (org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)3 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)2 SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)2 ToolException (org.apache.cxf.tools.common.ToolException)2 File (java.io.File)1 Binding (javax.wsdl.Binding)1 BindingFault (javax.wsdl.BindingFault)1 BindingOperation (javax.wsdl.BindingOperation)1 WSDLException (javax.wsdl.WSDLException)1 ExtensionRegistry (javax.wsdl.extensions.ExtensionRegistry)1 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)1 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)1 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 SoapHeaderInfo (org.apache.cxf.binding.soap.model.SoapHeaderInfo)1 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)1 Message (org.apache.cxf.common.i18n.Message)1 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)1