Search in sources :

Example 6 with SoapBody

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

Example 7 with SoapBody

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

the class ServiceProcessor method processParameter.

private void processParameter(JavaMethod jm, BindingOperationInfo operation) throws ToolException {
    // process input
    List<ExtensibilityElement> inbindings = null;
    if (operation.getInput() != null) {
        inbindings = operation.getInput().getExtensors(ExtensibilityElement.class);
    }
    if (inbindings == null) {
        inbindings = new ArrayList<>();
    }
    String use = null;
    for (ExtensibilityElement ext : inbindings) {
        if (SOAPBindingUtil.isSOAPBody(ext)) {
            SoapBody soapBody = SOAPBindingUtil.getSoapBody(ext);
            use = soapBody.getUse();
        } else if (SOAPBindingUtil.isSOAPHeader(ext)) {
            processSoapHeader(jm, operation, ext);
        }
        if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
            processMultipart(jm, operation, (MIMEMultipartRelated) ext, JavaType.Style.IN);
        }
    }
    // process output
    if (operation.getOutput() != null) {
        List<ExtensibilityElement> outbindings = operation.getOutput().getExtensors(ExtensibilityElement.class);
        if (outbindings == null) {
            outbindings = new ArrayList<>();
        }
        for (ExtensibilityElement ext : outbindings) {
            if (SOAPBindingUtil.isSOAPHeader(ext)) {
                SoapHeader soapHeader = SOAPBindingUtil.getSoapHeader(ext);
                if (isOutOfBandHeader(operation.getOutput(), ext)) {
                    continue;
                }
                boolean found = false;
                for (JavaParameter parameter : jm.getParameters()) {
                    if (soapHeader.getPart().equals(parameter.getPartName())) {
                        setParameterAsHeader(parameter);
                        found = true;
                    }
                }
                if (jm.getReturn().getName() != null && jm.getReturn().getName().equals(soapHeader.getPart())) {
                    found = true;
                }
                if (Boolean.valueOf((String) context.get(ToolConstants.CFG_EXTRA_SOAPHEADER)) && !found) {
                    // Header can't be found in java method parameters, in
                    // different message
                    // other than messages used in porttype operation
                    ParameterProcessor processor = new ParameterProcessor(context);
                    MessagePartInfo exPart = service.getMessage(soapHeader.getMessage()).getMessagePart(new QName(soapHeader.getMessage().getNamespaceURI(), soapHeader.getPart()));
                    JavaParameter jp = processor.addParameterFromBinding(jm, exPart, JavaType.Style.OUT);
                    setParameterAsHeader(jp);
                }
            }
            if (ext instanceof MIMEMultipartRelated && jm.enableMime()) {
                processMultipart(jm, operation, (MIMEMultipartRelated) ext, JavaType.Style.OUT);
            }
        }
    }
    jm.setSoapUse(SOAPBindingUtil.getSoapUse(use));
    if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.ENCODED == jm.getSoapUse()) {
        System.err.println("** Unsupported RPC-Encoded Style Use **");
    }
    if (javax.jws.soap.SOAPBinding.Style.RPC == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.LITERAL == jm.getSoapUse()) {
        return;
    }
    if (javax.jws.soap.SOAPBinding.Style.DOCUMENT == jm.getSoapStyle() && javax.jws.soap.SOAPBinding.Use.LITERAL == jm.getSoapUse()) {
        return;
    }
}
Also used : QName(javax.xml.namespace.QName) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) SoapHeader(org.apache.cxf.binding.soap.wsdl.extensions.SoapHeader) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) MIMEMultipartRelated(javax.wsdl.extensions.mime.MIMEMultipartRelated)

Example 8 with SoapBody

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

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

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

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