wsdlserializationutil.java

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

JAVA
471
字号
                fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_NAME, null, serviceName +
                        Java2WSDLConstants.HTTP_BINDING));
        binding.addAttribute(fac.createOMAttribute(WSDL2Constants.INTERFACE_LOCAL_NAME, null, tns
                .getPrefix() + ":" + WSDL2Constants.DEFAULT_INTERFACE_NAME));

        binding.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_TYPE, null,
                                                   WSDL2Constants.URI_WSDL2_HTTP));
        Iterator iterator = axisService.getChildren();
        while (iterator.hasNext()) {
            AxisOperation axisOperation = (AxisOperation) iterator.next();
            OMElement opElement = fac.createOMElement(WSDL2Constants.OPERATION_LOCAL_NAME, wsdl);
            binding.addChild(opElement);
            String name = axisOperation.getName().getLocalPart();
            opElement.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_REF, null,
                                                         tns.getPrefix() + ":" + name));
            opElement.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_LOCATION, whttp,
                                                         serviceName + "/" + name));
        }
        return binding;
    }

private static void generateDefaultSOAPBindingOperations(AxisService axisService, OMFactory omFactory, OMElement binding, OMNamespace wsdl, OMNamespace tns, OMNamespace wsoap) {        Iterator iterator = axisService.getChildren();
        while (iterator.hasNext()) {
            AxisOperation axisOperation = (AxisOperation) iterator.next();
            if (axisOperation.isControlOperation()) {
                continue;
            }
            OMElement opElement = omFactory.createOMElement(WSDL2Constants.OPERATION_LOCAL_NAME, wsdl);
            binding.addChild(opElement);
            String name = axisOperation.getName().getLocalPart();
            opElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_REF, null,
                                                         tns.getPrefix() + ":" + name));
            String soapAction = axisOperation.getSoapAction();
            if (soapAction != null) {
                opElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_ACTION, wsoap,
                        soapAction));
            }
        }
    }

    /**
     * Generates a default service element
     * @param omFactory - The OMFactory
     * @param wsdl the WSDL namespace
     * @param tns - The targetnamespace
     * @param axisService - The AxisService
     * @param disableREST only generate REST endpoint if this is false
     * @return - The generated service element
     * @throws AxisFault - Thrown in case an exception occurs
     */
    public static OMElement generateServiceElement(OMFactory omFactory, OMNamespace wsdl,
                                                   OMNamespace tns, AxisService axisService,
                                                   boolean disableREST)
            throws AxisFault {
        return generateServiceElement(omFactory, wsdl, tns, axisService, disableREST, null);
    }
    
    /**
     * Generates a default service element
     * @param omFactory - The OMFactory
     * @param wsdl the WSDL namespace
     * @param tns - The targetnamespace
     * @param axisService - The AxisService
     * @param disableREST only generate REST endpoint if this is false
     * @return - The generated service element
     * @throws AxisFault - Thrown in case an exception occurs
     */
    public static OMElement generateServiceElement(OMFactory omFactory, OMNamespace wsdl,
                                                   OMNamespace tns, AxisService axisService,
                                                   boolean disableREST, String[] eprs)
            throws AxisFault {
        if(eprs == null){
            eprs = axisService.getEPRs();
            if (eprs == null) {
                eprs = new String[]{axisService.getName()};
            }
        }
        OMElement serviceElement;
        serviceElement = omFactory.createOMElement(WSDL2Constants.SERVICE_LOCAL_NAME, wsdl);
                    serviceElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_NAME,
                                                                            null, axisService.getName()));
                    serviceElement.addAttribute(omFactory.createOMAttribute(
                            WSDL2Constants.INTERFACE_LOCAL_NAME, null,
                            tns.getPrefix() + ":" + WSDL2Constants.DEFAULT_INTERFACE_NAME));
        for (int i = 0; i < eprs.length; i++) {
            String name = "";
            String epr = eprs[i];
            if (epr.startsWith("https://")) {
                name = WSDL2Constants.DEFAULT_HTTPS_PREFIX;
            }
            OMElement soap11EndpointElement =
                    omFactory.createOMElement(WSDL2Constants.ENDPOINT_LOCAL_NAME, wsdl);
            soap11EndpointElement.addAttribute(omFactory.createOMAttribute(
                    WSDL2Constants.ATTRIBUTE_NAME, null,
                    name + WSDL2Constants.DEFAULT_SOAP11_ENDPOINT_NAME));
            soap11EndpointElement.addAttribute(omFactory.createOMAttribute(
                    WSDL2Constants.BINDING_LOCAL_NAME, null,
                    tns.getPrefix() + ":" + axisService.getName() +
                            Java2WSDLConstants.BINDING_NAME_SUFFIX));
            soap11EndpointElement.addAttribute(
                    omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_ADDRESS, null, epr));
            serviceElement.addChild(soap11EndpointElement);
            OMElement soap12EndpointElement =
                    omFactory.createOMElement(WSDL2Constants.ENDPOINT_LOCAL_NAME, wsdl);
            soap12EndpointElement.addAttribute(omFactory.createOMAttribute(
                    WSDL2Constants.ATTRIBUTE_NAME, null,
                    name + WSDL2Constants.DEFAULT_SOAP12_ENDPOINT_NAME));
            soap12EndpointElement.addAttribute(omFactory.createOMAttribute(
                    WSDL2Constants.BINDING_LOCAL_NAME, null,
                    tns.getPrefix() + ":" + axisService.getName() +
                            Java2WSDLConstants.SOAP12BINDING_NAME_SUFFIX));
            soap12EndpointElement.addAttribute(
                    omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_ADDRESS, null, epr));
            serviceElement.addChild(soap12EndpointElement);
            OMElement httpEndpointElement = null;
            if (!disableREST) {
                httpEndpointElement =
                        omFactory.createOMElement(WSDL2Constants.ENDPOINT_LOCAL_NAME, wsdl);
                httpEndpointElement.addAttribute(omFactory.createOMAttribute(
                        WSDL2Constants.ATTRIBUTE_NAME, null,
                        name + WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME));
                httpEndpointElement.addAttribute(omFactory.createOMAttribute(
                        WSDL2Constants.BINDING_LOCAL_NAME, null,
                        tns.getPrefix() + ":" + axisService.getName() + Java2WSDLConstants
                                .HTTP_BINDING));
                httpEndpointElement.addAttribute(
                        omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_ADDRESS, null, epr));
                serviceElement.addChild(httpEndpointElement);
            }
            if (epr.startsWith("https://")) {
                OMElement soap11Documentation = omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
                soap11Documentation.setText("This endpoint exposes a SOAP 11 binding over a HTTPS");
                soap11EndpointElement.addChild(soap11Documentation);
                OMElement soap12Documentation = omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
                soap12Documentation.setText("This endpoint exposes a SOAP 12 binding over a HTTPS");
                soap12EndpointElement.addChild(soap12Documentation);
                if (!disableREST) {
                    OMElement httpDocumentation =
                            omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
                    httpDocumentation.setText("This endpoint exposes a HTTP binding over a HTTPS");
                    httpEndpointElement.addChild(httpDocumentation);
                }
            } else if (epr.startsWith("http://")) {
                OMElement soap11Documentation = omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
                soap11Documentation.setText("This endpoint exposes a SOAP 11 binding over a HTTP");
                soap11EndpointElement.addChild(soap11Documentation);
                OMElement soap12Documentation = omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
                soap12Documentation.setText("This endpoint exposes a SOAP 12 binding over a HTTP");
                soap12EndpointElement.addChild(soap12Documentation);
                if (!disableREST) {
                    OMElement httpDocumentation =
                            omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
                    httpDocumentation.setText("This endpoint exposes a HTTP binding over a HTTP");
                    httpEndpointElement.addChild(httpDocumentation);
                }
            }
        }
        return serviceElement;
    }

    /**
     * Adds the namespaces to the given OMElement
     *
     * @param descriptionElement - The OMElement that the namespaces should be added to
     * @param nameSpaceMap - The namespaceMap
     */
    public static void populateNamespaces(OMElement descriptionElement, Map nameSpaceMap) {
        if (nameSpaceMap != null) {
        Iterator keys = nameSpaceMap.keySet().iterator();
        while (keys.hasNext()) {
            String key = (String) keys.next();
            if ("".equals(key)) {
                descriptionElement.declareDefaultNamespace((String) nameSpaceMap.get(key));
            } else {
                descriptionElement.declareNamespace((String) nameSpaceMap.get(key), key);
            }
            }
        }
    }

    public static void addWSAWActionAttribute(OMElement element,
                                              String action ,
                                              OMNamespace wsaw) {
        if (action == null || action.length() == 0) {
            return;
        }
        element.addAttribute("Action", action, wsaw);
    }

    public static void addExtensionElement(OMFactory fac, OMElement element,
                                     String name, String att1Name, String att1Value,
                                     OMNamespace soapNameSpace) {
        OMElement extElement = fac.createOMElement(name, soapNameSpace);
        element.addChild(extElement);
        extElement.addAttribute(att1Name, att1Value, null);
    }

    public static void addWSAddressingToBinding(String addressingFlag,
                                                OMFactory omFactory,
                                                OMElement bindingElement ,
                                                OMNamespace wsaw) {
        // Add WS-Addressing UsingAddressing element if appropriate
        // SHOULD be on the binding element per the specification
        if (addressingFlag.equals(AddressingConstants.ADDRESSING_OPTIONAL)) {
            WSDLSerializationUtil.addExtensionElement(omFactory, bindingElement,
                                AddressingConstants.USING_ADDRESSING,
                                "required", "true",
                                wsaw);
        } else if (addressingFlag.equals(AddressingConstants.ADDRESSING_REQUIRED)) {
            WSDLSerializationUtil.addExtensionElement(omFactory, bindingElement,
                                AddressingConstants.USING_ADDRESSING,
                                "required", "true",
                                wsaw);
        }
    }

    public static void addWSDLDocumentationElement(AxisDescription axisDescription, OMElement omElement, OMFactory omFactory, OMNamespace wsdl) {
        String documentationString = axisDescription.getDocumentation();
        OMElement documentation;
        if (documentationString != null && !"".equals(documentationString)) {
            documentation = omFactory.createOMElement(WSDL2Constants.DOCUMENTATION, wsdl);
            OMText omText;
            if (documentationString.indexOf(CDATA_START) > -1) {
                documentationString = documentationString.replaceFirst(CDATA_START_REGEX, "");
                documentationString = documentationString.replaceFirst(CDATA_END_REGEX, "");
                omText = omFactory.createOMText(documentationString, XMLStreamConstants.CDATA);
            } else {
            omText =  omFactory.createOMText(documentationString);
            }
            documentation.addChild(omText);
            omElement.addChild(documentation);
        }
    }
}

⌨️ 快捷键说明

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