Search in sources :

Example 1 with SoapBody

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

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

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

the class WSIBPValidator method checkR2201Output.

private boolean checkR2201Output(final Operation operation, final BindingOperation bop) {
    int outmessagePartsCount = wsdlHelper.getOutMessageParts(operation).size();
    SoapBody soapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
    if (soapBody != null) {
        List<?> parts = soapBody.getParts();
        int boundPartSize = parts == null ? outmessagePartsCount : parts.size();
        SoapHeader soapHeader = SOAPBindingUtil.getBindingOutputSOAPHeader(bop);
        boundPartSize = soapHeader != null && soapHeader.getMessage().equals(operation.getOutput().getMessage().getQName()) ? boundPartSize - 1 : boundPartSize;
        if (parts != null) {
            Iterator<?> partsIte = parts.iterator();
            while (partsIte.hasNext()) {
                String partName = (String) partsIte.next();
                boolean isDefined = false;
                for (Part part : wsdlHelper.getOutMessageParts(operation)) {
                    if (partName.equalsIgnoreCase(part.getName())) {
                        isDefined = true;
                        break;
                    }
                }
                if (!isDefined) {
                    addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2201") + "Operation '" + operation.getName() + "' soapBody parts : " + partName + " not found in the message, wrong WSDL");
                    return false;
                }
            }
        } else {
            if (wsdlHelper.getOutMessageParts(operation).size() > 1) {
                addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2210") + "Operation '" + operation.getName() + "' more than one part bound to body");
                return false;
            }
        }
        if (boundPartSize > 1) {
            addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2201") + "Operation '" + operation.getName() + "' more than one part bound to body");
            return false;
        }
    }
    return true;
}
Also used : Part(javax.wsdl.Part) MIMEPart(javax.wsdl.extensions.mime.MIMEPart) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)

Example 4 with SoapBody

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

the class WSDLToSoapProcessor method getSoapBody.

private SoapBody getSoapBody(Class<?> parent) throws ToolException {
    if (extReg == null) {
        extReg = wsdlFactory.newPopulatedExtensionRegistry();
    }
    final SoapBody soapBody;
    try {
        soapBody = SOAPBindingUtil.createSoapBody(extReg, parent, isSOAP12());
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
        throw new ToolException(msg, wse);
    }
    soapBody.setUse((String) env.get(ToolConstants.CFG_USE));
    if (WSDLConstants.RPC.equalsIgnoreCase((String) env.get(ToolConstants.CFG_STYLE)) && env.optionSet(ToolConstants.CFG_NAMESPACE)) {
        soapBody.setNamespaceURI((String) env.get(ToolConstants.CFG_NAMESPACE));
    }
    return soapBody;
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) ToolException(org.apache.cxf.tools.common.ToolException)

Example 5 with SoapBody

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

the class WSDLToSoapProcessorTest method testNewSoap12Binding.

@Test
public void testNewSoap12Binding() throws Exception {
    String[] args = new String[] { "-i", "Greeter", "-soap12", "-b", "Greeter_SOAP12Binding", "-d", output.getCanonicalPath(), "-o", "hello_world_soap12_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_soap12_nobinding.wsdl") };
    WSDLToSoap.main(args);
    File outputFile = new File(output, "hello_world_soap12_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_SOAP12Binding"));
        if (binding == null) {
            fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
        }
        for (Object obj : binding.getExtensibilityElements()) {
            assertTrue(SOAPBindingUtil.isSOAPBinding(obj));
            assertTrue(obj instanceof SOAP12Binding);
            SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
            assertNotNull(soapBinding);
            assertTrue("document".equalsIgnoreCase(soapBinding.getStyle()));
            assertTrue(WSDLConstants.NS_SOAP_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 SOAP12Operation);
            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 SOAP12Body);
            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) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) 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) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) BindingOperation(javax.wsdl.BindingOperation) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) Test(org.junit.Test)

Aggregations

SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)15 SoapHeader (org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader)8 QName (javax.xml.namespace.QName)7 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)5 SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)5 ToolException (org.apache.cxf.tools.common.ToolException)5 File (java.io.File)4 Binding (javax.wsdl.Binding)4 BindingInput (javax.wsdl.BindingInput)4 BindingOperation (javax.wsdl.BindingOperation)4 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)4 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)4 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)4 Test (org.junit.Test)4 MIMEPart (javax.wsdl.extensions.mime.MIMEPart)3 SoapHeaderInfo (org.apache.cxf.binding.soap.model.SoapHeaderInfo)3 SoapFault (org.apache.cxf.binding.soap.wsdl.extensions.SoapFault)3 Part (javax.wsdl.Part)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 MIMEMultipartRelated (javax.wsdl.extensions.mime.MIMEMultipartRelated)2