<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pentaho.di.trans.steps.webservices.wsdl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import javax.wsdl.Binding;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Port;
import javax.wsdl.extensions.ElementExtensible;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPHeader;
import javax.wsdl.extensions.soap.SOAPOperation;

/**
 * Utilities for getting extensibility elements.
 */
final class WsdlUtils {

    // extensibility element names
    private static final String SOAP_PORT_ADDRESS_NAME = "address";
    private static final String SOAP_BINDING_ELEMENT_NAME = "binding";
    private static final String SOAP_BODY_ELEMENT_NAME = "body";
    private static final String SOAP_HEADER_ELEMENT_NAME = "header";
    private static final String SOAP_OPERATION_ELEMENT_NAME = "operation";

    // return values
    private static final String SOAP_BINDING_DEFAULT = "document";

    // schema names
    protected static final String ELEMENT_FORM_DEFAULT_ATTR = "elementFormDefault";
    protected static final String ANY_TAG_NAME = "any";
    protected static final String TARGET_NAMESPACE_ATTR = "targetNamespace";
    protected static final String ELEMENT_FORM_QUALIFIED = "qualified";
    protected static final String ELEMENT_NAME = "element";
    protected static final String COMPLEX_TYPE_NAME = "complexType";
    protected static final String SCHEMA_ELEMENT_NAME = "schema";
    protected static final String SEQUENCE_TAG_NAME = "sequence";
    protected static final String SIMPLE_TYPE_NAME = "simpleType";
    protected static final String NAME_ATTR = "name";
    protected static final String ELEMENT_TYPE_ATTR = "type";
    protected static final String ELEMENT_REF_ATTR = "ref";
    protected static final String MAXOCCURS_ATTR = "maxOccurs";
    protected static final String MINOCCURS_ATTR = "minOccurs";


    /**
     * Get the SOAP address location for the specified port.
     *
     * @param p A WSDL Port instance.
     * @return The SOAP address URI.
     */
    protected static String getSOAPAddress(Port p) {
        ExtensibilityElement e = findExtensibilityElement(p, SOAP_PORT_ADDRESS_NAME);
        return ((SOAPAddress) e).getLocationURI();
    }

    /**
     * Get the SOAPBinding style for the specifed WSDL Port.
     *
     * @param binding A WSDL Binding instance.
     * @return String either 'document' or 'rpc', if not found in WSDL defaults to 'document'.
     */
    protected static String getSOAPBindingStyle(Binding binding) {
        String style = SOAP_BINDING_DEFAULT;
        ExtensibilityElement soapBindingElem =
                findExtensibilityElement(binding, SOAP_BINDING_ELEMENT_NAME);

        if (soapBindingElem != null) {
        	if (soapBindingElem instanceof SOAPBinding) {
        		style = ((SOAPBinding) soapBindingElem).getStyle(); 
        	}
        }
        return style;<commit_msg>PDI-2111 : Web Service lookup SOAP 1.2 ClassCastException error<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.pentaho.di.trans.steps.webservices.wsdl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import javax.wsdl.Binding;
import javax.wsdl.BindingInput;
import javax.wsdl.BindingOperation;
import javax.wsdl.BindingOutput;
import javax.wsdl.Port;
import javax.wsdl.extensions.ElementExtensible;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap.SOAPBody;
import javax.wsdl.extensions.soap.SOAPHeader;
import javax.wsdl.extensions.soap.SOAPOperation;
import javax.wsdl.extensions.soap12.SOAP12Address;

/**
 * Utilities for getting extensibility elements.
 */
final class WsdlUtils {

    // extensibility element names
    private static final String SOAP_PORT_ADDRESS_NAME = "address";
    private static final String SOAP_BINDING_ELEMENT_NAME = "binding";
    private static final String SOAP_BODY_ELEMENT_NAME = "body";
    private static final String SOAP_HEADER_ELEMENT_NAME = "header";
    private static final String SOAP_OPERATION_ELEMENT_NAME = "operation";

    // return values
    private static final String SOAP_BINDING_DEFAULT = "document";

    // schema names
    protected static final String ELEMENT_FORM_DEFAULT_ATTR = "elementFormDefault";
    protected static final String ANY_TAG_NAME = "any";
    protected static final String TARGET_NAMESPACE_ATTR = "targetNamespace";
    protected static final String ELEMENT_FORM_QUALIFIED = "qualified";
    protected static final String ELEMENT_NAME = "element";
    protected static final String COMPLEX_TYPE_NAME = "complexType";
    protected static final String SCHEMA_ELEMENT_NAME = "schema";
    protected static final String SEQUENCE_TAG_NAME = "sequence";
    protected static final String SIMPLE_TYPE_NAME = "simpleType";
    protected static final String NAME_ATTR = "name";
    protected static final String ELEMENT_TYPE_ATTR = "type";
    protected static final String ELEMENT_REF_ATTR = "ref";
    protected static final String MAXOCCURS_ATTR = "maxOccurs";
    protected static final String MINOCCURS_ATTR = "minOccurs";


    /**
     * Get the SOAP address location for the specified port.
     *
     * @param p A WSDL Port instance.
     * @return The SOAP address URI.
     */
    protected static String getSOAPAddress(Port p) {
        ExtensibilityElement e = findExtensibilityElement(p, SOAP_PORT_ADDRESS_NAME);
        if (e instanceof SOAPAddress) {
        	return ((SOAPAddress) e).getLocationURI();
        } else {
        	return ((SOAP12Address)e).getLocationURI();
        }
    }

    /**
     * Get the SOAPBinding style for the specifed WSDL Port.
     *
     * @param binding A WSDL Binding instance.
     * @return String either 'document' or 'rpc', if not found in WSDL defaults to 'document'.
     */
    protected static String getSOAPBindingStyle(Binding binding) {
        String style = SOAP_BINDING_DEFAULT;
        ExtensibilityElement soapBindingElem =
                findExtensibilityElement(binding, SOAP_BINDING_ELEMENT_NAME);

        if (soapBindingElem != null) {
        	if (soapBindingElem instanceof SOAPBinding) {
        		style = ((SOAPBinding) soapBindingElem).getStyle(); 
        	}
        }
        return style;
{'fraction_non_alphanumeric': 0.07363770250368189, 'fraction_numerical': 0.002454590083456063, 'mean_word_length': 3.8362017804154305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4440441', 'n_tokens_mistral': 2268, 'n_tokens_neox': 2203, 'n_words': 745}