Search in sources :

Example 6 with Soap12Header

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

the class WSDL11ToAxisServiceBuilder method copyExtensibleElements.

/**
 * Get the Extensible elements form wsdl4jExtensibleElements
 * <code>Vector</code> if any and copy them to <code>Component</code>
 * <p/> Note - SOAP body extensible element will be processed differently
 *
 * @param wsdl4jExtensibleElements
 * @param description                   where is the ext element (port , portype , biding)
 * @param wsdl4jDefinition
 * @param originOfExtensibilityElements -
 *                                      this will indicate the place this extensibility element came
 *                                      from.
 */
private void copyExtensibleElements(List wsdl4jExtensibleElements, Definition wsdl4jDefinition, AxisDescription description, String originOfExtensibilityElements) throws AxisFault {
    ExtensibilityElement wsdl4jExtensibilityElement;
    for (Iterator iterator = wsdl4jExtensibleElements.iterator(); iterator.hasNext(); ) {
        wsdl4jExtensibilityElement = (ExtensibilityElement) iterator.next();
        if (wsdl4jExtensibilityElement instanceof UnknownExtensibilityElement) {
            UnknownExtensibilityElement unknown = (UnknownExtensibilityElement) (wsdl4jExtensibilityElement);
            QName type = unknown.getElementType();
            // <wsp:Policy>
            if (Constants.isPolicyElement(type)) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: PolicyElement found " + unknown);
                }
                Policy policy = (Policy) PolicyUtil.getPolicyComponent(unknown.getElement());
                description.getPolicySubject().attachPolicy(policy);
            // int attachmentScope =
            // getPolicyAttachmentPoint(description, originOfExtensibilityElements);
            // if (attachmentScope > -1) {
            // description.getPolicyInclude().addPolicyElement(
            // attachmentScope, policy);
            // }
            // <wsp:PolicyReference>
            } else if (Constants.isPolicyRef(type)) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: PolicyReference found " + unknown);
                }
                PolicyReference policyReference = (PolicyReference) PolicyUtil.getPolicyComponent(unknown.getElement());
                description.getPolicySubject().attachPolicyReference(policyReference);
            // int attachmentScope =
            // getPolicyAttachmentPoint(description, originOfExtensibilityElements);
            // if (attachmentScope > -1) {
            // description.getPolicyInclude().addPolicyRefElement(
            // attachmentScope, policyReference);
            // }
            } else if (AddressingConstants.Final.WSAW_USING_ADDRESSING.equals(type) || AddressingConstants.Submission.WSAW_USING_ADDRESSING.equals(unknown.getElementType())) {
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: wsaw:UsingAddressing found " + unknown);
                }
                // AxisBinding .
                if (originOfExtensibilityElements.equals(PORT) || originOfExtensibilityElements.equals(BINDING)) {
                    if (Boolean.TRUE.equals(unknown.getRequired())) {
                        AddressingHelper.setAddressingRequirementParemeterValue(axisService, AddressingConstants.ADDRESSING_REQUIRED);
                    } else {
                        AddressingHelper.setAddressingRequirementParemeterValue(axisService, AddressingConstants.ADDRESSING_OPTIONAL);
                    }
                }
            } else if (wsdl4jExtensibilityElement.getElementType() != null && wsdl4jExtensibilityElement.getElementType().getNamespaceURI().equals(org.apache.axis2.namespace.Constants.FORMAT_BINDING)) {
                Element typeMapping = unknown.getElement();
                NodeList typeMaps = typeMapping.getElementsByTagNameNS(org.apache.axis2.namespace.Constants.FORMAT_BINDING, "typeMap");
                int count = typeMaps.getLength();
                HashMap typeMapper = new HashMap();
                for (int index = 0; index < count; index++) {
                    Node node = typeMaps.item(index);
                    NamedNodeMap attributes = node.getAttributes();
                    Node typeName = attributes.getNamedItem("typeName");
                    if (typeName != null) {
                        String prefix = getPrefix(typeName.getNodeValue());
                        if (prefix != null) {
                            String ns = (String) wsdl4jDefinition.getNamespaces().get(prefix);
                            if (ns != null) {
                                Node formatType = attributes.getNamedItem("formatType");
                                typeMapper.put(new QName(ns, getTypeName(typeName.getNodeValue())), formatType.getNodeValue());
                            }
                        }
                    }
                }
            } else if (wsdl4jExtensibilityElement.getElementType() != null && wsdl4jExtensibilityElement.getElementType().getNamespaceURI().equals(org.apache.axis2.namespace.Constants.JAVA_NS)) {
                Element unknowJavaElement = unknown.getElement();
                if (unknowJavaElement.getLocalName().equals("address")) {
                    NamedNodeMap nameAttributes = unknowJavaElement.getAttributes();
                    Node node = nameAttributes.getNamedItem("className");
                    Parameter serviceClass = new Parameter();
                    serviceClass.setName("className");
                    serviceClass.setValue(node.getNodeValue());
                    axisService.addParameter(serviceClass);
                    Parameter transportName = new Parameter();
                    transportName.setName("TRANSPORT_NAME");
                    transportName.setValue("java");
                    axisService.addParameter(transportName);
                }
            } else {
                // Ignore this element - it is a totally unknown element
                if (isTraceEnabled) {
                    log.trace("copyExtensibleElements:: Unknown Extensibility Element found " + unknown);
                }
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAP12Address) {
            SOAP12Address soapAddress = (SOAP12Address) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI());
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAPAddress) {
            SOAPAddress soapAddress = (SOAPAddress) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, soapAddress.getLocationURI());
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPAddress) {
            HTTPAddress httpAddress = (HTTPAddress) wsdl4jExtensibilityElement;
            if (description instanceof AxisEndpoint) {
                setEndpointURL((AxisEndpoint) description, httpAddress.getLocationURI());
            }
        } else if (wsdl4jExtensibilityElement instanceof Schema) {
            Schema schema = (Schema) wsdl4jExtensibilityElement;
            // just add this schema - no need to worry about the imported
            // ones
            axisService.addSchema(getXMLSchema(schema.getElement(), schema.getDocumentBaseURI()));
        } else if (wsdl4jExtensibilityElement instanceof SOAP12Operation) {
            SOAP12Operation soapOperation = (SOAP12Operation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;
            String style = soapOperation.getStyle();
            if (style != null) {
                axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }
            String soapActionURI = soapOperation.getSoapActionURI();
            if (this.isCodegen && ((soapActionURI == null) || (soapActionURI.equals("")))) {
                soapActionURI = axisBindingOperation.getAxisOperation().getInputAction();
            }
            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
                log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: " + soapActionURI);
            if (soapActionURI != null && !soapActionURI.equals("")) {
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapActionURI);
                axisBindingOperation.getAxisOperation().setSoapAction(soapActionURI);
                if (!isServerSide) {
                    axisBindingOperation.getAxisOperation().setOutputAction(soapActionURI);
                }
                axisService.mapActionToOperation(soapActionURI, axisBindingOperation.getAxisOperation());
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAPOperation) {
            SOAPOperation soapOperation = (SOAPOperation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;
            String style = soapOperation.getStyle();
            if (style != null) {
                axisBindingOperation.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }
            String soapAction = soapOperation.getSoapActionURI();
            if (this.isCodegen && ((soapAction == null) || (soapAction.equals("")))) {
                soapAction = axisBindingOperation.getAxisOperation().getInputAction();
            }
            if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled())
                log.debug("WSDL Binding Operation: " + axisBindingOperation.getName() + ", SOAPAction: " + soapAction);
            if (soapAction != null && !soapAction.equals("")) {
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, soapAction);
                axisBindingOperation.getAxisOperation().setSoapAction(soapAction);
                if (!isServerSide) {
                    axisBindingOperation.getAxisOperation().setOutputAction(soapAction);
                }
                axisService.mapActionToOperation(soapAction, axisBindingOperation.getAxisOperation());
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPOperation) {
            HTTPOperation httpOperation = (HTTPOperation) wsdl4jExtensibilityElement;
            AxisBindingOperation axisBindingOperation = (AxisBindingOperation) description;
            String httpLocation = httpOperation.getLocationURI();
            if (httpLocation != null) {
                // change the template to make it same as WSDL 2 template
                httpLocation = httpLocation.replaceAll("\\(", "{");
                httpLocation = httpLocation.replaceAll("\\)", "}");
                axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, httpLocation);
            }
            axisBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        } else if (wsdl4jExtensibilityElement instanceof SOAP12Header) {
            SOAP12Header soapHeader = (SOAP12Header) wsdl4jExtensibilityElement;
            SOAPHeaderMessage headerMessage = new SOAPHeaderMessage();
            headerMessage.setNamespaceURI(soapHeader.getNamespaceURI());
            headerMessage.setUse(soapHeader.getUse());
            Boolean required = soapHeader.getRequired();
            if (required != null) {
                headerMessage.setRequired(required.booleanValue());
            }
            if (wsdl4jDefinition != null) {
                // find the relevant schema part from the messages
                Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage());
                if (msg == null) {
                    msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet());
                }
                if (msg == null) {
                    // TODO i18n this
                    throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL ");
                }
                Part msgPart = msg.getPart(soapHeader.getPart());
                if (msgPart == null) {
                    // TODO i18n this
                    throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL ");
                }
                // see basic profile 4.4.2 Bindings and Faults header, fault and headerfaults
                // can only have elements
                headerMessage.setElement(msgPart.getElementName());
            }
            headerMessage.setMessage(soapHeader.getMessage());
            headerMessage.setPart(soapHeader.getPart());
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders == null) {
                    soapHeaders = new ArrayList();
                    bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders);
                }
                soapHeaders.add(headerMessage);
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAPHeader) {
            SOAPHeader soapHeader = (SOAPHeader) wsdl4jExtensibilityElement;
            SOAPHeaderMessage headerMessage = new SOAPHeaderMessage();
            headerMessage.setNamespaceURI(soapHeader.getNamespaceURI());
            headerMessage.setUse(soapHeader.getUse());
            Boolean required = soapHeader.getRequired();
            if (null != required) {
                headerMessage.setRequired(required.booleanValue());
            }
            if (null != wsdl4jDefinition) {
                // find the relevant schema part from the messages
                Message msg = wsdl4jDefinition.getMessage(soapHeader.getMessage());
                if (msg == null) {
                    msg = getMessage(wsdl4jDefinition, soapHeader.getMessage(), new HashSet());
                }
                if (msg == null) {
                    // todo i18n this
                    throw new AxisFault("message " + soapHeader.getMessage() + " not found in the WSDL ");
                }
                Part msgPart = msg.getPart(soapHeader.getPart());
                if (msgPart == null) {
                    // todo i18n this
                    throw new AxisFault("message part " + soapHeader.getPart() + " not found in the WSDL ");
                }
                headerMessage.setElement(msgPart.getElementName());
            }
            headerMessage.setMessage(soapHeader.getMessage());
            headerMessage.setPart(soapHeader.getPart());
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                List soapHeaders = (List) bindingMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders == null) {
                    soapHeaders = new ArrayList();
                    bindingMessage.setProperty(WSDL2Constants.ATTR_WSOAP_HEADER, soapHeaders);
                }
                soapHeaders.add(headerMessage);
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAPBinding) {
            SOAPBinding soapBinding = (SOAPBinding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;
            axisBinding.setType(soapBinding.getTransportURI());
            axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
            String style = soapBinding.getStyle();
            if (style != null) {
                axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }
        } else if (wsdl4jExtensibilityElement instanceof SOAP12Binding) {
            SOAP12Binding soapBinding = (SOAP12Binding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;
            axisBinding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
            String style = soapBinding.getStyle();
            if (style != null) {
                axisBinding.setProperty(WSDLConstants.WSDL_1_1_STYLE, style);
            }
            String transportURI = soapBinding.getTransportURI();
            axisBinding.setType(transportURI);
        } else if (wsdl4jExtensibilityElement instanceof HTTPBinding) {
            HTTPBinding httpBinding = (HTTPBinding) wsdl4jExtensibilityElement;
            AxisBinding axisBinding = (AxisBinding) description;
            // set the binding style same as the wsd2 to process smoothly
            axisBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
            axisBinding.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, httpBinding.getVerb());
        } else if (wsdl4jExtensibilityElement instanceof MIMEContent) {
            if (description instanceof AxisBindingMessage) {
                MIMEContent mimeContent = (MIMEContent) wsdl4jExtensibilityElement;
                String messageSerialization = mimeContent.getType();
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(), originOfExtensibilityElements, messageSerialization);
            }
        } else if (wsdl4jExtensibilityElement instanceof MIMEMimeXml) {
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(), originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_TEXT_XML);
            }
        } else if (wsdl4jExtensibilityElement instanceof HTTPUrlEncoded) {
            if (description instanceof AxisBindingMessage) {
                AxisBindingMessage bindingMessage = (AxisBindingMessage) description;
                setMessageSerialization((AxisBindingOperation) bindingMessage.getParent(), originOfExtensibilityElements, HTTPConstants.MEDIA_TYPE_X_WWW_FORM);
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) AxisFault(org.apache.axis2.AxisFault) HTTPAddress(javax.wsdl.extensions.http.HTTPAddress) SOAPOperation(javax.wsdl.extensions.soap.SOAPOperation) SOAPHeaderMessage(org.apache.axis2.wsdl.SOAPHeaderMessage) Message(javax.wsdl.Message) HashMap(java.util.HashMap) SOAP12Header(javax.wsdl.extensions.soap12.SOAP12Header) OMElement(org.apache.axiom.om.OMElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Schema(javax.wsdl.extensions.schema.Schema) ArrayList(java.util.ArrayList) PolicyReference(org.apache.neethi.PolicyReference) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) HTTPOperation(javax.wsdl.extensions.http.HTTPOperation) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) SOAP12Operation(javax.wsdl.extensions.soap12.SOAP12Operation) MIMEContent(javax.wsdl.extensions.mime.MIMEContent) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) SOAPHeader(javax.wsdl.extensions.soap.SOAPHeader) HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) HashSet(java.util.HashSet) HTTPUrlEncoded(javax.wsdl.extensions.http.HTTPUrlEncoded) NamedNodeMap(org.w3c.dom.NamedNodeMap) SOAPHeaderMessage(org.apache.axis2.wsdl.SOAPHeaderMessage) QName(javax.xml.namespace.QName) NodeList(org.w3c.dom.NodeList) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) MIMEMimeXml(javax.wsdl.extensions.mime.MIMEMimeXml) Part(javax.wsdl.Part) MIMEPart(javax.wsdl.extensions.mime.MIMEPart) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress)

Aggregations

ArrayList (java.util.ArrayList)4 SOAP12Header (javax.wsdl.extensions.soap12.SOAP12Header)4 HashSet (java.util.HashSet)3 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)3 Soap12Body (com.helger.phase4.soap12.Soap12Body)2 Soap12Envelope (com.helger.phase4.soap12.Soap12Envelope)2 Soap12Header (com.helger.phase4.soap12.Soap12Header)2 Iterator (java.util.Iterator)2 List (java.util.List)2 MIMEPart (javax.wsdl.extensions.mime.MIMEPart)2 SOAPHeader (javax.wsdl.extensions.soap.SOAPHeader)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 Soap11Body (com.helger.phase4.soap11.Soap11Body)1 Soap11Envelope (com.helger.phase4.soap11.Soap11Envelope)1 Soap11Header (com.helger.phase4.soap11.Soap11Header)1 HashMap (java.util.HashMap)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BindingInput (javax.wsdl.BindingInput)1