Search in sources :

Example 6 with Soap12Body

use of com.helger.phase4.soap12.Soap12Body 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 Soap12Body

use of com.helger.phase4.soap12.Soap12Body in project axis-axis2-java-core by apache.

the class DescriptionUtils method getNamespaceFromSOAPElement.

/**
 * This method will loop through a list of extensibility elements looking for one
 * of four objects: SOAPBody, SOAP12Body, SOAPHeader, SOAP12Header. If any of these
 * objects are found the namespace URI from this object will be returned.
 */
public static String getNamespaceFromSOAPElement(List extElements) {
    Iterator extIter = extElements.iterator();
    while (extIter.hasNext()) {
        Object extObj = extIter.next();
        if (extObj instanceof SOAPBody) {
            if (log.isDebugEnabled()) {
                log.debug("Returning SOAPBody namespace: " + ((SOAPBody) extObj).getNamespaceURI());
            }
            return ((SOAPBody) extObj).getNamespaceURI();
        } else if (extObj instanceof SOAP12Body) {
            if (log.isDebugEnabled()) {
                log.debug("Returning SOAP12Body namespace: " + ((SOAP12Body) extObj).getNamespaceURI());
            }
            return ((SOAP12Body) extObj).getNamespaceURI();
        } else if (extObj instanceof SOAPHeader) {
            if (log.isDebugEnabled()) {
                log.debug("Returning SOAPHeader namespace: " + ((SOAPHeader) extObj).getNamespaceURI());
            }
            return ((SOAPHeader) extObj).getNamespaceURI();
        } else if (extObj instanceof SOAP12Header) {
            if (log.isDebugEnabled()) {
                log.debug("Returning SOAP12Header namespace: " + ((SOAP12Header) extObj).getNamespaceURI());
            }
            return ((SOAP12Header) extObj).getNamespaceURI();
        } else if (extObj instanceof MIMEMultipartRelated) {
            if (log.isDebugEnabled()) {
                log.debug("Found a MIMEMultipartRelated element.  Unwrapping to get SOAP binding.");
            }
            MIMEMultipartRelated mime = (MIMEMultipartRelated) extObj;
            List mimeParts = mime.getMIMEParts();
            Iterator itr = mimeParts.iterator();
            while (itr.hasNext()) {
                MIMEPart mimePart = (MIMEPart) itr.next();
                List elements = mimePart.getExtensibilityElements();
                String ns = getNamespaceFromSOAPElement(elements);
                return ns;
            }
        }
    }
    return null;
}
Also used : SOAPBody(javax.wsdl.extensions.soap.SOAPBody) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) SOAP12Header(javax.wsdl.extensions.soap12.SOAP12Header) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SOAPHeader(javax.wsdl.extensions.soap.SOAPHeader) MIMEMultipartRelated(javax.wsdl.extensions.mime.MIMEMultipartRelated) MIMEPart(javax.wsdl.extensions.mime.MIMEPart)

Example 8 with Soap12Body

use of com.helger.phase4.soap12.Soap12Body in project carbon-business-process by wso2.

the class WSDLAwareSOAPProcessor method processMessageParts.

private WSDLAwareMessage processMessageParts(BindingInput bindingInput) throws AxisFault {
    WSDLAwareMessage message = new WSDLAwareMessage();
    message.setBinding(wsdlBinding);
    List parts;
    String namespace;
    if (soap12) {
        SOAP12Body soapBodyDef = getFirstExtensibilityElement(bindingInput, SOAP12Body.class);
        if (soapBodyDef == null) {
            String errMessage = "SOAPBody null for binding input.";
            log.error(errMessage);
            throw new AxisFault(errMessage);
        }
        parts = soapBodyDef.getParts();
        namespace = soapBodyDef.getNamespaceURI();
    } else {
        SOAPBody soapBodyDef = getFirstExtensibilityElement(bindingInput, SOAPBody.class);
        if (soapBodyDef == null) {
            String errMessage = "SOAPBody null for binding input.";
            log.error(errMessage);
            throw new AxisFault(errMessage);
        }
        parts = soapBodyDef.getParts();
        namespace = soapBodyDef.getNamespaceURI();
    }
    QName axisOperationName = inMessageCtx.getAxisOperation().getName();
    /**
     * Local part of the axis Operation's name equals to WSDL Operation name.
     */
    Operation op = wsdlBinding.getPortType().getOperation(axisOperationName.getLocalPart(), null, null);
    String rpcWrapper = op.getName();
    List bodyParts = op.getInput().getMessage().getOrderedParts(parts);
    if (isRPC) {
        message.setRPC(true);
        QName rpWrapperQName = new QName(namespace, rpcWrapper);
        OMElement partWrapper = inMessageCtx.getEnvelope().getBody().getFirstChildWithName(rpWrapperQName);
        if (partWrapper == null) {
            String errMsg = "SOAP Body doesn't contain expected part wrapper.";
            log.error(errMsg);
            throw new AxisFault(errMsg);
        }
        /* In RPC the body element is the operation name, wrapping parts. Order doesn't really
             * matter as far as we're concerned. All we need to do is copy the soap:body children,
             * since doc-lit rpc looks the same in ode and soap.*/
        for (Object partDef : bodyParts) {
            OMElement srcPart = partWrapper.getFirstChildWithName(new QName(null, ((Part) partDef).getName()));
            if (srcPart == null) {
                throw new AxisFault("SOAP Body doesn't contain required part " + ((Part) partDef).getName() + ".");
            }
            message.addBodyPart(srcPart.getLocalName(), srcPart);
        }
    } else {
        /**
         * In doc-literal style, we expect the elements in the body to correspond (in order) to
         * the parts defined in the binding. All the parts should be element-typed, otherwise
         * it is a mess.
         */
        message.setRPC(false);
        Iterator srcParts = inMessageCtx.getEnvelope().getBody().getChildElements();
        for (Object partDef : bodyParts) {
            if (!srcParts.hasNext()) {
                throw new AxisFault("SOAP Body does not contain required part" + ((Part) partDef).getName() + ".");
            }
            OMElement srcPart = (OMElement) srcParts.next();
            if (((Part) partDef).getElementName() == null) {
                throw new AxisFault("Binding defines non-element document literal part(s)");
            }
            if (!srcPart.getQName().equals(((Part) partDef).getElementName())) {
                throw new AxisFault("Unexpected element in SOAP body.");
            }
            message.addBodyPart(((Part) partDef).getName(), srcPart);
        }
    }
    processSoapHeaderParts(message, bindingInput, op);
    return message;
}
Also used : AxisFault(org.apache.axis2.AxisFault) SOAPBody(javax.wsdl.extensions.soap.SOAPBody) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) QName(javax.xml.namespace.QName) Part(javax.wsdl.Part) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) OMElement(org.apache.axiom.om.OMElement) Operation(javax.wsdl.Operation) BindingOperation(javax.wsdl.BindingOperation)

Example 9 with Soap12Body

use of com.helger.phase4.soap12.Soap12Body in project carbon-business-process by wso2.

the class SOAPUtils method populateSOAPBody.

@SuppressWarnings("unchecked")
private static void populateSOAPBody(SOAPEnvelope soapEnvelope, ElementExtensible bindingInput, boolean soap12, SOAPFactory soapFactory, Operation operation, Message messageDefinition, org.apache.ode.bpel.iapi.Message messageFromODE, boolean isRPC, boolean isRequest) throws BPELFault {
    if (soap12) {
        SOAP12Body soapBodyDefinition = getSOAP12Body(bindingInput);
        if (soapBodyDefinition != null) {
            SOAPBody soapBody;
            if (soapEnvelope.getBody() != null) {
                soapBody = soapEnvelope.getBody();
            } else {
                soapBody = soapFactory.createSOAPBody(soapEnvelope);
            }
            OMElement partHolder;
            if (isRPC) {
                String rpcWrapperElementName;
                if (isRequest) {
                    rpcWrapperElementName = operation.getName();
                } else {
                    rpcWrapperElementName = operation.getName() + "Response";
                }
                partHolder = createRPCWrapperElement(soapBody, soapFactory, new QName(soapBodyDefinition.getNamespaceURI(), rpcWrapperElementName));
            } else {
                partHolder = soapBody;
            }
            List<Part> parts = messageDefinition.getOrderedParts(soapBodyDefinition.getParts());
            for (Part p : parts) {
                Element partContent = DOMUtils.findChildByName(messageFromODE.getMessage(), new QName(null, p.getName()));
                if (partContent == null) {
                    throw new BPELFault("Missing required part in ODE Message: " + new QName(null, p.getName()));
                }
                OMElement omPartContent = OMUtils.toOM(partContent, soapFactory);
                if (isRPC) {
                    partHolder.addChild(omPartContent);
                } else {
                    for (Iterator<OMNode> i = omPartContent.getChildren(); i.hasNext(); ) {
                        partHolder.addChild(i.next());
                    }
                }
            }
        }
    } else {
        javax.wsdl.extensions.soap.SOAPBody soapBodyDefinition = getSOAP11Body(bindingInput);
        if (soapBodyDefinition != null) {
            SOAPBody soapBody;
            if (soapEnvelope.getBody() != null) {
                soapBody = soapEnvelope.getBody();
            } else {
                soapBody = soapFactory.createSOAPBody(soapEnvelope);
            }
            OMElement partHolder;
            if (isRPC) {
                String rpcWrapperElementName;
                if (isRequest) {
                    rpcWrapperElementName = operation.getName();
                } else {
                    rpcWrapperElementName = operation.getName() + "Response";
                }
                partHolder = createRPCWrapperElement(soapBody, soapFactory, new QName(soapBodyDefinition.getNamespaceURI(), rpcWrapperElementName));
            } else {
                partHolder = soapBody;
            }
            List<Part> parts = messageDefinition.getOrderedParts(soapBodyDefinition.getParts());
            for (Part p : parts) {
                Element partContent = DOMUtils.findChildByName(messageFromODE.getMessage(), new QName(null, p.getName()));
                if (partContent == null) {
                    throw new BPELFault("Missing required part in ODE Message: " + new QName(null, p.getName()));
                }
                OMElement omPartContent = OMUtils.toOM(partContent, soapFactory);
                if (isRPC) {
                    partHolder.addChild(omPartContent);
                } else {
                    for (Iterator<OMNode> i = omPartContent.getChildren(); i.hasNext(); ) {
                        partHolder.addChild(i.next());
                    }
                }
            }
        }
    }
}
Also used : SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) OMNode(org.apache.axiom.om.OMNode) SOAPBody(org.apache.axiom.soap.SOAPBody) Part(javax.wsdl.Part)

Example 10 with Soap12Body

use of com.helger.phase4.soap12.Soap12Body in project carbon-business-process by wso2.

the class SOAPUtils method parseSOAPResponseFromPartner.

public static org.apache.ode.bpel.iapi.Message parseSOAPResponseFromPartner(BPELMessageContext partnerInvocationContext, MessageExchange partnerRoleMessageExchange) throws BPELFault {
    org.apache.ode.bpel.iapi.Message messageToODE = partnerRoleMessageExchange.createMessage(partnerRoleMessageExchange.getOperation().getOutput().getMessage().getQName());
    BindingOperation bindingOp = getBindingOperation(partnerInvocationContext, partnerRoleMessageExchange.getOperationName());
    BindingOutput bindingOutPut = getBindingOutPut(bindingOp);
    SOAPEnvelope responseFromPartnerService = partnerInvocationContext.getOutMessageContext().getEnvelope();
    if (partnerInvocationContext.isSoap12()) {
        javax.wsdl.extensions.soap12.SOAP12Body soapBodyDefinition = getSOAP12Body(bindingOutPut);
        if (soapBodyDefinition != null) {
            if (responseFromPartnerService.getBody() != null) {
                extractSOAPBodyParts(partnerRoleMessageExchange, messageToODE, responseFromPartnerService.getBody(), soapBodyDefinition.getParts(), soapBodyDefinition.getNamespaceURI(), partnerInvocationContext.isRPCStyleOperation());
            } else {
                throw new BPELFault("SOAP Body cannot be null for WSDL operation which " + "requires SOAP Body.");
            }
        }
    } else {
        javax.wsdl.extensions.soap.SOAPBody soapBodyDefinition = getSOAP11Body(bindingOutPut);
        if (soapBodyDefinition != null) {
            if (responseFromPartnerService.getBody() != null) {
                extractSOAPBodyParts(partnerRoleMessageExchange, messageToODE, responseFromPartnerService.getBody(), soapBodyDefinition.getParts(), soapBodyDefinition.getNamespaceURI(), partnerInvocationContext.isRPCStyleOperation());
            } else {
                throw new BPELFault("SOAP Body cannot be null for WSDL operation which " + "requires SOAP Body.");
            }
        }
    }
    if (getSOAPHeaders(bindingOutPut) != null && responseFromPartnerService.getHeader() != null) {
        extractSoapHeaderParts(messageToODE, partnerInvocationContext.getBpelServiceWSDLDefinition(), responseFromPartnerService.getHeader(), getSOAPHeaders(bindingOutPut), partnerRoleMessageExchange.getOperation().getOutput().getMessage());
    }
    return messageToODE;
}
Also used : BindingOutput(javax.wsdl.BindingOutput) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFaultCode(org.apache.axiom.soap.SOAPFaultCode) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) BindingOperation(javax.wsdl.BindingOperation) SOAP12Body(javax.wsdl.extensions.soap12.SOAP12Body)

Aggregations

SOAP12Body (javax.wsdl.extensions.soap12.SOAP12Body)12 SOAPBody (javax.wsdl.extensions.soap.SOAPBody)8 BindingOperation (javax.wsdl.BindingOperation)6 Iterator (java.util.Iterator)5 QName (javax.xml.namespace.QName)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 BindingInput (javax.wsdl.BindingInput)4 Part (javax.wsdl.Part)4 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)4 SOAP12Operation (javax.wsdl.extensions.soap12.SOAP12Operation)4 Binding (javax.wsdl.Binding)3 BindingOutput (javax.wsdl.BindingOutput)3 Message (javax.wsdl.Message)3 MIMEMultipartRelated (javax.wsdl.extensions.mime.MIMEMultipartRelated)3 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)3 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)3 Soap12Body (com.helger.phase4.soap12.Soap12Body)2 Soap12Envelope (com.helger.phase4.soap12.Soap12Envelope)2 Soap12Header (com.helger.phase4.soap12.Soap12Header)2