wsdl11toaxisservicebuilder.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,531 行 · 第 1/5 页

JAVA
1,531
字号
                                   axisService,
                                   TYPES);
        }

        // process the types in other wsdls
        Iterator iter = wsdlDefinition.getImports().values().iterator();
        Vector values = null;
        Import wsdlImport = null;
        for (; iter.hasNext();) {
            values = (Vector) iter.next();
            for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) {
                wsdlImport = (Import) valuesIter.next();
                // process the types recuresiveilt
                Definition innerDefinition = wsdlImport.getDefinition();
                if(!stack.contains(innerDefinition)){
                    processTypes(innerDefinition, axisService, stack);
            }
        }
    }
        stack.pop();
    }

    private void addDocumentation(AxisDescription axisDescription, Element documentationElement) {
        if ((documentationElement != null) && (documentationElement.getFirstChild() != null)) {
            Node firstChild = documentationElement.getFirstChild();
            String documentation = DOM2Writer.nodeToString(firstChild);
            if (!"".equals(documentation)) {
                axisDescription.setDocumentation(documentation);
            }
        }
    }

    /**
     * @param binding
     * @param wsdl4jService must have atlease one port
     * @throws AxisFault
     */
    private void populateEndpoints(Binding binding,
                                   Service wsdl4jService,
                                   PortType portType) throws AxisFault {

        Map wsdl4jPorts = wsdl4jService.getPorts();
        QName bindingName = binding.getQName();

        Port port;
        AxisEndpoint axisEndpoint = null;

        processedBindings = new HashMap();

        // process the port type for this binding
        // although we support multiports they must be belongs to same port type and should have the
        // same soap style
        populatePortType(portType);

        Binding currentBinding;

        for (Iterator iterator = wsdl4jPorts.values().iterator(); iterator.hasNext();) {
            port = (Port) iterator.next();
            // if the user has picked a port then we have to process only that port
            if ((this.portName == null) || (this.portName.equals(port.getName()))) {
                // we process the port only if it has the same port type as the selected binding
                currentBinding = getBinding(port.getBinding().getQName(), wsdl4jDefinition);

                if (currentBinding.getPortType().getQName().equals(binding.getPortType().getQName())) {
                    axisEndpoint = new AxisEndpoint();
                    axisEndpoint.setName(port.getName());

                    if (axisService.getEndpointName() == null &&
                        bindingName.equals(port.getBinding().getQName())) {
                        populateEndpoint(axisEndpoint, port, true);
                        axisService.setEndpointName(axisEndpoint.getName());
                        axisService.setBindingName(axisEndpoint.getBinding().getName().getLocalPart());
                    } else {
                        populateEndpoint(axisEndpoint, port, false);
                    }

                    axisEndpoint.setParent(axisService);
                    axisService.addEndpoint(port.getName(), axisEndpoint);
                }
            }
        }
    }

    /**
     * setting message qname is a binding dependent process for an example message element depends on the
     * soap style (rpc or document) and parts elememet of the soap body
     * On the otherhand we keep only one set of axis operations belongs to a selected port type in axis service
     * So setting qname refetences done only with the selected binding processing
     *
     * @param axisEndpoint
     * @param wsdl4jPort
     * @param isSetMessageQNames
     * @throws AxisFault
     */
    private void populateEndpoint(AxisEndpoint axisEndpoint, Port wsdl4jPort,
                                  boolean isSetMessageQNames)
            throws AxisFault {

        copyExtensibleElements(wsdl4jPort.getExtensibilityElements(), wsdl4jDefinition,
                               axisEndpoint, BINDING);


        Binding wsdl4jBinding = getBinding(wsdl4jPort.getBinding().getQName(), wsdl4jDefinition);

        addDocumentation(axisEndpoint, wsdl4jPort.getDocumentationElement());
        if (processedBindings.containsKey(wsdl4jBinding.getQName())) {
            axisEndpoint.setBinding(
                    (AxisBinding) processedBindings.get(wsdl4jBinding.getQName()));
        } else {
            AxisBinding axisBinding = new AxisBinding();
            axisBinding.setName(wsdl4jBinding.getQName());
            axisBinding.setParent(axisEndpoint);
            axisEndpoint.setBinding(axisBinding);
            axisBinding.setParent(axisEndpoint);
            populateBinding(axisBinding, wsdl4jBinding, isSetMessageQNames);
            processedBindings.put(wsdl4jBinding.getQName(), axisBinding);
        }

    }

    private void populatePortType(PortType wsdl4jPortType) throws AxisFault {
        List wsdl4jOperations = wsdl4jPortType.getOperations();

        // Added to use in ?wsdl2 as the interface name
        axisService.addParameter(new Parameter(WSDL2Constants.INTERFACE_LOCAL_NAME,
                                               wsdl4jPortType.getQName().getLocalPart()));
        if (wsdl4jOperations.size() < 1) {
            throw new AxisFault("No operation found in the portType element");
        }

        AxisOperation axisOperation;
        List operationNames = new ArrayList();

        QName opName;
        Operation wsdl4jOperation;

        for (Iterator iterator = wsdl4jOperations.iterator(); iterator.hasNext();) {
            wsdl4jOperation = (Operation) iterator.next();

            axisOperation = populateOperations(wsdl4jOperation, wsdl4jPortType, wsdl4jDefinition);
            addDocumentation(axisOperation, wsdl4jOperation.getDocumentationElement());
            axisOperation.setParent(axisService);
            axisService.addChild(axisOperation);
            operationNames.add(axisOperation.getName());
        }

        // this is used only in codegen to preserve operation order
        if (isCodegen) {
            axisService.setOperationsNameList(operationNames);
        }

    }

    private void populateBinding(AxisBinding axisBinding, Binding wsdl4jBinding,
                                 boolean isSetMessageQNames)
            throws AxisFault {

        copyExtensibleElements(wsdl4jBinding.getExtensibilityElements(), wsdl4jDefinition,
                               axisBinding, BINDING);

        List wsdl4jBidingOperations = wsdl4jBinding.getBindingOperations();

        if (wsdl4jBidingOperations.size() < 1) {
            throw new AxisFault("No operation found for the binding");
        }

        addDocumentation(axisBinding, wsdl4jBinding.getDocumentationElement());

        AxisOperation axisOperation;
        Operation wsdl4jOperation;

        AxisBindingOperation axisBindingOperation;
        BindingOperation wsdl4jBindingOperation;

        Map httpLocationMap = new TreeMap();
        String httpLocation = null;

        PortType portType = getPortType(wsdl4jBinding.getPortType().getQName(), wsdl4jDefinition);

        String targetNamespace = wsdl4jDefinition.getTargetNamespace();

        for (Iterator iterator = wsdl4jBidingOperations.iterator(); iterator.hasNext();) {

            axisBindingOperation = new AxisBindingOperation();
            wsdl4jBindingOperation = (BindingOperation) iterator.next();
            wsdl4jOperation = findOperation(portType, wsdl4jBindingOperation);

            axisBindingOperation.setName(new QName(targetNamespace, wsdl4jBindingOperation.getName()));
            addDocumentation(axisBindingOperation, wsdl4jBindingOperation.getDocumentationElement());

            axisOperation = axisService.getOperation(new QName(targetNamespace, wsdl4jOperation.getName()));
            axisBindingOperation.setAxisOperation(axisOperation);

            // process ExtensibilityElements of the wsdl4jBinding
            copyExtensibleElements(wsdl4jBindingOperation.getExtensibilityElements(),
                                   wsdl4jDefinition, axisBindingOperation, BINDING_OPERATION);

            httpLocation =
                    (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
            if (httpLocation != null) {
                httpLocationMap.put(RESTUtil.getConstantFromHTTPLocation(httpLocation),
                                    axisBindingOperation.getAxisOperation());
            }

            BindingInput wsdl4jBindingInput = wsdl4jBindingOperation.getBindingInput();

            if (wsdl4jBindingInput != null &&
                WSDLUtil.isInputPresentForMEP(axisOperation.getMessageExchangePattern())) {
                AxisBindingMessage axisBindingInMessage = new AxisBindingMessage();
                addDocumentation(axisBindingInMessage, wsdl4jBindingInput.getDocumentationElement());
                copyExtensibleElements(wsdl4jBindingInput.getExtensibilityElements(),
                                       wsdl4jDefinition,
                                       axisBindingInMessage, BINDING_OPERATION_INPUT);

                AxisMessage axisInMessage =
                        axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
                //This is a hack to get AXIS2-2771 working , I had to copy soap headers
                //  from binding message to AxisMessage
                List soapHeaders = (List) axisBindingInMessage.getProperty(
                        WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders != null) {
                    for (int i = 0; i < soapHeaders.size(); i++) {
                        SOAPHeaderMessage headerMessage = (SOAPHeaderMessage) soapHeaders.get(i);
                        axisInMessage.addSoapHeader(headerMessage);
                    }
                }

                if (isSetMessageQNames) {
                    addQNameReference(axisInMessage, wsdl4jOperation,
                                      wsdl4jBindingInput,
                                      wrappableOperations.contains(wsdl4jBindingOperation));
                }

                axisBindingInMessage.setAxisMessage(axisInMessage);
                axisBindingInMessage.setDirection(axisInMessage.getDirection());

                axisBindingInMessage.setParent(axisBindingOperation);
                axisBindingOperation
                        .addChild(axisBindingInMessage.getDirection(), axisBindingInMessage);
            }

            BindingOutput wsdl4jBindingOutput = wsdl4jBindingOperation.getBindingOutput();

            if (wsdl4jBindingOutput != null &&
                WSDLUtil.isOutputPresentForMEP(axisOperation.getMessageExchangePattern())) {
                AxisBindingMessage axisBindingOutMessage = new AxisBindingMessage();
                addDocumentation(axisBindingOutMessage, wsdl4jBindingOutput.getDocumentationElement());
                AxisMessage axisOutMessage =
                        axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);

                copyExtensibleElements(wsdl4jBindingOutput.getExtensibilityElements(),
                                       wsdl4jDefinition,
                                       axisBindingOutMessage, BINDING_OPERATION_OUTPUT);

                //This is a hack to get AXIS2-2771 working , I had to copy soap headers
                //  from binding message to AxisMessage
                List soapHeaders =
                        (List) axisBindingOutMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
                if (soapHeaders != null) {
                    for (int i = 0; i < soapHeaders.size(); i++) {
                        SOAPHeaderMessage headerMessage = (SOAPHeaderMessage) soapHeaders.get(i);
                        axisOutMessage.addSoapHeader(headerMessage);
                    }
                }

                if (isSetMessageQNames) {
                    addQNameReference(axisOutMessage, wsdl4jOperation,
                                      wsdl4jBindingOutput,
                                      wrappableOperations.contains(wsdl4jBindingOperation));
                }


                axisBindingOutMessage.setAxisMessage(axisOutMessage);
                axisBindingOutMessage.setDirection(axisOutMessage.getDirection());

                axisBindingOutMessage.setParent(axisBindingOperation);
                axisBindingOperation
                        .addChild(axisBindingOutMessage.getDirection(), axisBindingOutMessage);
            }

            Map bindingFaultsMap = wsdl4jBindingOperation.getBindingFaults();

            /* process the binding faults */
            for (Iterator bindingFaults = bindingFaultsMap.values().iterator();
                 bindingFaults.hasNext();) {

                BindingFault bindingFault = (BindingFault) bindingFaults.next();
                Fault wsdl4jFault = wsdl4jOperation.getFault(bindingFault.getName());
                Message wsdl4jFaultMessge = wsdl4jFault.getMessage();

                AxisMessage faultMessage = findFaultMessage(
                        wsdl4jFaultMessge.getQName().getLocalPart(),
                        axisOperation.getFaultMessages());

                AxisBindingMessage axisBindingFaultMessage = new AxisBindingMessage();
                addDocumentation(axisBindingFaultMessage, wsdl4jFaultMessge.getDocumentationElement());
                axisBindingFaultMessage.setFault(true);
                axisBindingFaultMessage.setAxisMessage(faultMessage);
                axisBindingFaultMessage.setParent(axisBindingOperation);

                axisBindingOperation.addFault(axisBindingFaultMessage);
                if (isSetMessageQNames) {
                    addQNameReference(faultMessage, wsdl4jFault.getMessage());
                }
            }

            axisBindingOperation.setParent(axisBinding);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?