Search in sources :

Example 1 with SoapOperation

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

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

the class WSDLToSoapProcessor method setSoapOperationExtElement.

private void setSoapOperationExtElement(BindingOperation bo) throws ToolException {
    if (extReg == null) {
        extReg = wsdlFactory.newPopulatedExtensionRegistry();
    }
    final SoapOperation soapOperation;
    try {
        soapOperation = SOAPBindingUtil.createSoapOperation(extReg, isSOAP12());
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
        throw new ToolException(msg, wse);
    }
    soapOperation.setStyle((String) env.get(ToolConstants.CFG_STYLE));
    soapOperation.setSoapActionURI("");
    bo.addExtensibilityElement(soapOperation);
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) ToolException(org.apache.cxf.tools.common.ToolException)

Example 3 with SoapOperation

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

the class ServiceProcessor method getSoapOperationProp.

private Map<String, Object> getSoapOperationProp(BindingOperationInfo bop) {
    Map<String, Object> soapOPProp = new HashMap<>();
    if (bop.getExtensor(ExtensibilityElement.class) != null) {
        for (ExtensibilityElement ext : bop.getExtensors(ExtensibilityElement.class)) {
            if (SOAPBindingUtil.isSOAPOperation(ext)) {
                SoapOperation soapOP = SOAPBindingUtil.getSoapOperation(ext);
                soapOPProp.put(this.soapOPAction, soapOP.getSoapActionURI());
                soapOPProp.put(this.soapOPStyle, soapOP.getStyle());
            }
        }
    } else {
        for (ExtensibilityElement ext : bop.getBinding().getExtensors(ExtensibilityElement.class)) {
            if (SOAPBindingUtil.isSOAPOperation(ext)) {
                SoapOperation soapOP = SOAPBindingUtil.getSoapOperation(ext);
                soapOPProp.put(this.soapOPAction, soapOP.getSoapActionURI());
                soapOPProp.put(this.soapOPStyle, soapOP.getStyle());
            }
        }
    }
    return soapOPProp;
}
Also used : HashMap(java.util.HashMap) SoapOperation(org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 4 with SoapOperation

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

Example 5 with SoapOperation

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

the class WSDLToSoapProcessorTest method testAddSoap12Binding.

@Test
public void testAddSoap12Binding() 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.wsdl") };
    WSDLToSoap.main(args);
    File outputFile = new File(output, "hello_world_soap12_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_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()));
        }
        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()));
        }
        bo = binding.getBindingOperation("pingMe", null, null);
        assertNotNull(bo);
        Iterator<?> it = bo.getExtensibilityElements().iterator();
        assertTrue(it != null && it.hasNext());
        assertTrue(it.next() instanceof SOAP12Operation);
        it = bo.getBindingInput().getExtensibilityElements().iterator();
        assertTrue(it != null && it.hasNext());
        assertTrue(it.next() instanceof SOAP12Body);
        it = bo.getBindingOutput().getExtensibilityElements().iterator();
        assertTrue(it != null && it.hasNext());
        assertTrue(it.next() instanceof SOAP12Body);
        Map<?, ?> faults = bo.getBindingFaults();
        assertTrue(faults != null && faults.size() == 1);
        Object bf = faults.get("pingMeFault");
        assertNotNull(bf);
        assertTrue(bf instanceof BindingFault);
        assertEquals("pingMeFault", ((BindingFault) bf).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) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) BindingFault(javax.wsdl.BindingFault) 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

SoapOperation (org.apache.cxf.binding.soap.wsdl.extensions.SoapOperation)10 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)7 BindingOperation (javax.wsdl.BindingOperation)6 ToolException (org.apache.cxf.tools.common.ToolException)6 File (java.io.File)5 Binding (javax.wsdl.Binding)5 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)5 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)5 QName (javax.xml.namespace.QName)5 SoapBody (org.apache.cxf.binding.soap.wsdl.extensions.SoapBody)5 Test (org.junit.Test)5 BindingInput (javax.wsdl.BindingInput)4 BindingFault (javax.wsdl.BindingFault)2 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)2 SOAP12Body (javax.wsdl.extensions.soap12.SOAP12Body)2 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)2 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)2 SoapFault (org.apache.cxf.binding.soap.wsdl.extensions.SoapFault)2 HashMap (java.util.HashMap)1 WSDLException (javax.wsdl.WSDLException)1