Package HTTPSupport

Source Code of HTTPSupport.HTTPConfigManager

/*
Copyright (c) 2003-2009 ITerative Consulting Pty Ltd. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

o Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
 
o Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the distribution.
   
o This jcTOOL Helper Class software, whether in binary or source form may not be used within,
or to derive, any other product without the specific prior written permission of the copyright holder

 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


*/
package HTTPSupport;

import java.io.Serializable;
import java.text.MessageFormat;

import Framework.Application;
import Framework.Array_Of_TextData;
import Framework.SSLExternalConnection;
import Framework.TextData;
import Framework.UsageException;

/**
* The HTTPConfigManager class defines methods to change general configuration
* values to support TCP or SSL sessions. Because there is only one
* HTTPConfigManager instance for HTTPSupport, changing a configuration value
* affects the entire HTTPSupport.
*/
@SuppressWarnings("serial")
public class HTTPConfigManager implements Serializable {

    // ----------
    // Attributes
    // ----------
    private Array_Of_TextData<TextData> configValues;

    // ------------
    // Constructors
    // ------------
    public HTTPConfigManager() {
        // Explicitly call the superclass constructor to prevent the implicit
        // call
        super();

        this.configValues = new Array_Of_TextData<TextData>();

        //  Session default values
        this.configValues
                .set(
                        0,
                        new TextData(
                                Constants.HTTP_TCPSESSION_PERSISTENT,
                                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(1, new TextData(
                Constants.HTTP_SESSION_MAYBE,
                TextData.qq_Resolver.cINTEGERVALUE));

        //  SSL default config values
        this.configValues.set(2, new TextData(
                Constants.SSL_NEVER,
                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(3, new TextData(
                Constants.SSL_ANY,
                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(4, new TextData(
                Constants.SSL_ANY,
                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(5, new TextData(
                Constants.SSL_NONE,
                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(6, new TextData(
                Constants.SSL_ALWAYS,
                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(7, new TextData(
                Constants.SSL_ANONYMOUS,
                TextData.qq_Resolver.cINTEGERVALUE));
        this.configValues.set(8, new TextData(""));
        this.configValues.set(9, new TextData(""));
        this.configValues.set(10, new TextData(""));
        this.configValues.set(11, new TextData(""));
        this.configValues.set(12, new TextData(""));
        this.configValues.set(13, new TextData(""));

    }

    // ----------------------
    // Accessors and Mutators
    // ----------------------
    public void setconfigValues(Array_Of_TextData<TextData> pValue) {
        this.configValues = pValue;
    }

    public Array_Of_TextData<TextData> getconfigValues() {
        return this.configValues;
    }

    // -------
    // Methods
    // -------
    /**
     * convertToSSLValue
     * <p>
     * The HTTPDC only deals with SSL_* constants, that are defined <br>
     * in the httpdc.pex file. When time comes to set SSLEC values, <br>
     * this method is called to convert the httpdc SSL values to <br>
     * the ExternalConnection SSL values. <br>
     * <p>
     *
     * @param value
     *            Type: int
     * @return int
     */
    public int convertToSSLValue(int value) {
        int ret = -1;
        switch (value) {
        case Constants.SSL_ANONYMOUS: {
            ret = SSLExternalConnection.ANONYMOUS;
            break;
        }
        case Constants.SSL_NEVER: {
            ret = SSLExternalConnection.NEVER;
            break;
        }
        case Constants.SSL_ANY: {
            ret = SSLExternalConnection.ANY;
            break;
        }
        case Constants.SSL_ALWAYS: {
            ret = SSLExternalConnection.ALWAYS;
            break;
        }
        case Constants.SSL_SIZE: {
            ret = SSLExternalConnection.SIZE;
            break;
        }
        case Constants.SSL_SERVER: {
            ret = SSLExternalConnection.SERVER;
            break;
        }
        case Constants.SSL_BOTH: {
            ret = SSLExternalConnection.BOTH;
            break;
        }
        case Constants.SSL_LOW: {
            ret = SSLExternalConnection.LOW;
            break;
        }
        case Constants.SSL_SPEED: {
            ret = SSLExternalConnection.SPEED;
            break;
        }
        case Constants.SSL_MEDIUM: {
            ret = SSLExternalConnection.MEDIUM;
            break;
        }
        case Constants.SSL_HIGH: {
            ret = SSLExternalConnection.HIGH;
            break;
        }
        case Constants.SSL_NONE: {
            ret = SSLExternalConnection.NONE;
            break;
        }
        }

        //task.lgr.put('convertToSSLValue(');
        //task.lgr.put(self.intToString(value));
        //task.lgr.put(') -> ');
        //task.lgr.putline(ret);
        return ret;
    }

    /**
     * getConfigValue
     * <p>
     * <p>
     * Returns the default configuration value used for the specified
     * configuration parameter.
     *
     * @param config
     *            Type: int
     * @return int
     */
    public int getConfigValue(int config) {

        if ((config >= Constants.HTTP_CONFIG_MIN_VALUE)
                && (config <= Constants.HTTP_CONFIG_MAX_VALUE)) {
            return ((TextData) this.configValues.get(config - 1))
                    .getIntegerValue();
        } else {
            return -1;
        }
    }

    /**
     * getStringConfigValue
     * <p>
     * <p>
     * Returns the configuration value used for the specified configuration
     * parameter.
     *
     * @param config
     *            Type: int
     * @return String
     */
    public String getStringConfigValue(int config) {

        if ((config >= Constants.HTTP_CONFIG_MIN_VALUE)
                && (config <= Constants.HTTP_CONFIG_MAX_VALUE)) {
            return ((TextData) this.configValues.get(config - 1)).toString();
        } else {
            return null;
        }
    }

    /**
     * intToString
     * <p>
     * <p>
     *
     * @param value
     *            Type: int
     * @return String
     */
    public String intToString(int value) {
        //
        switch (value) {
        case Constants.SSL_ANONYMOUS: {
            return "SSL_ANONYMOUS";
        }
        case Constants.SSL_NEVER: {
            return "SSL_NEVER";
        }
        case Constants.SSL_ANY: {
            return "SSL_ANY";
        }
        case Constants.SSL_ALWAYS: {
            return "SSL_ALWAYS";
        }
        case Constants.SSL_SIZE: {
            return "SSL_SIZE";
        }
        case Constants.SSL_SERVER: {
            return "SSL_SERVER";
        }
        case Constants.SSL_BOTH: {
            return "SSL_BOTH";
        }
        case Constants.SSL_LOW: {
            return "SSL_LOW";
        }
        case Constants.SSL_SPEED: {
            return "SSL_SPEED";
        }
        case Constants.SSL_MEDIUM: {
            return "SSL_MEDIUM";
        }
        case Constants.SSL_HIGH: {
            return "SSL_HIGH";
        }
        case Constants.SSL_NONE: {
            return "SSL_NONE";
        }
        case Constants.SSL_SECURE: {
            return "SSL_SECURE ";
        }
        case Constants.SSL_SECRECY: {
            return "SSL_SECRECY";
        }
        case Constants.SSL_INTEGRITY: {
            return "SSL_INTEGRITY";
        }
        case Constants.SSL_COMPRESSION: {
            return "SSL_COMPRESSION";
        }
        case Constants.SSL_RESUME: {
            return "SSL_RESUME";
        }
        case Constants.SSL_AUTHENTICATE: {
            return "SSL_AUTHENTICATE";
        }
        case Constants.SSL_CERTFILE: {
            return "SSL_CERTFILE";
        }
        case Constants.SSL_CERTPASSWORD: {
            return "SSL_CERTPASSWORD";
        }
        case Constants.SSL_CERTPASSWORDFILE: {
            return "SSL_CERTPASSWORDFILE";
        }
        case Constants.SSL_ROOTFILE: {
            return "SSL_ROOTFILE";
        }
        case Constants.SSL_ROOTPASSWORD: {
            return "SSL_ROOTPASSWORD";
        }
        case Constants.SSL_ROOTPASSWORDFILE: {
            return "SSL_ROOTPASSWORDFILE";
        }
        }
        TextData txt = new TextData(value, TextData.qq_Resolver.cINTEGERVALUE);
        return txt.toString();
    }

    /**
     * isValid
     * <p>
     * <p>
     *
     * @param config
     *            Type: int
     * @param value
     *            Type: int
     * @param throw
     *            Type: boolean
     * @return boolean
     */
    public boolean isValid(int config, int value, boolean qq_throw) {
        boolean ret = false;
        switch (config) {
        case Constants.HTTP_CONFIG_TCPSESSION_VALUE: {

            if ((value == Constants.HTTP_TCPSESSION_PERSISTENT)
                    || (value == Constants.HTTP_TCPSESSION_MESSAGE)) {
                ret = true;
            }
            break;
        }
        case Constants.HTTP_CONFIG_SESSION_VALUE: {

            if ((value == Constants.HTTP_SESSION_MAYBE)
                    || (value == Constants.HTTP_SESSION_REQUIRED)
                    || (value == Constants.HTTP_SESSION_NONE)) {
                ret = true;
            }
            break;
        }
        case Constants.SSL_SECURE: {

            if ((value == Constants.SSL_NEVER)
                    || (value == Constants.SSL_ALWAYS)) {
                ret = true;
            }
            break;
        }
        case Constants.SSL_SECRECY: {

            if ((value == Constants.SSL_NONE)
                    || (value == Constants.SSL_LOW)
                    || (value == Constants.SSL_MEDIUM)
                    || (value == Constants.SSL_HIGH)
                    || (value == Constants.SSL_ANY)) {
                ret = true;
            }
            break;
        }
        case Constants.SSL_INTEGRITY: {

            if ((value == Constants.SSL_NONE)
                    || (value == Constants.SSL_LOW)
                    || (value == Constants.SSL_MEDIUM)
                    || (value == Constants.SSL_HIGH)
                    || (value == Constants.SSL_ANY)) {
                ret = true;
            }
            break;
        }
        case Constants.SSL_COMPRESSION: {

            if ((value == Constants.SSL_NONE)
                    || (value == Constants.SSL_SPEED)
                    || (value == Constants.SSL_SIZE)
                    || (value == Constants.SSL_ANY)) {
                ret = true;
            }
            break;
        }
        case Constants.SSL_RESUME: {

            if ((value == Constants.SSL_NEVER)
                    || (value == Constants.SSL_ALWAYS)) {
                ret = true;
            }
            break;
        }
        case Constants.SSL_AUTHENTICATE: {

            if ((value == Constants.SSL_ANONYMOUS)
                    || (value == Constants.SSL_SERVER)
                    || (value == Constants.SSL_BOTH)
                    || (value == Constants.SSL_NONE)) {
                ret = true;
            }
            break;
        }
        }
        //task.lgr.put('isValid(');
        //task.lgr.put(config);
        //task.lgr.put(', ');
        //task.lgr.put(value);
        //task.lgr.put(') -> ');
        //if (ret = FALSE)
        //then
        //  task.lgr.putline('FALSE');
        //else
        //  task.lgr.putline('TRUE');
        //end if;

        if ((ret == false) && qq_throw) {
            UsageException ex = null;
            TextData txt1 = new TextData(this.intToString(value));
            TextData txt2 = new TextData(this.intToString(config));
            Object[] qq_Args = { txt1, txt2 };
            ex = new UsageException(
                    MessageFormat
                            .format(
                                    Application
                                            .getMsgCatalog()
                                            .getString(
                                                    Constants.HTTP_SET,
                                                    Constants.HTTP_MSG_CFGMGR_INVALID_VALUE)
                                            .toString(), qq_Args));
            throw ex;
        }

        return ret;
    }

    /**
     * setConfigValue
     * <p>
     * <p>
     * Sets configuration options for new HTTP sessions.
     *
     * @param config
     *            Type: int
     * @param value
     *            Type: int
     */
    public void setConfigValue(int config, int value) {

        if ((config >= Constants.HTTP_CONFIG_MIN_VALUE)
                && (config <= Constants.HTTP_CONFIG_MAX_VALUE)) {

            if (this.isValid(config, value, true)) {
                ((TextData) this.configValues.get(config - 1)).setValue(value);
            }
        }
    }

    /**
     * setConfigValue
     * <p>
     * <p>
     * Sets configuration options for access to certificates used in new SSL
     * sessions.
     *
     * @param config
     *            Type: int
     * @param value
     *            Type: String
     */
    public void setConfigValue(int config, String value) {

        if ((config >= Constants.HTTP_CONFIG_SSL_CERTFILE)
                && (config <= Constants.HTTP_CONFIG_SSL_ROOTPASSWORDFILE)) {
            ((TextData) this.configValues.get(config - 1)).setValue(value);
        }
    }

    /**
     * stringToInt
     * <p>
     * <p>
     *
     * @param confValue
     *            Type: String
     * @return int
     */
    public int stringToInt(String confValue) {
        int ret = -1;
        TextData txt = new TextData(confValue);

        if (txt.compare("ANONYMOUS", true) == 0) {
            ret = Constants.SSL_ANONYMOUS;
        } else if (txt.compare("NEVER", true) == 0) {
            ret = Constants.SSL_NEVER;
        } else if (txt.compare("ANY", true) == 0) {
            ret = Constants.SSL_ANY;
        } else if (txt.compare("ALWAYS", true) == 0) {
            ret = Constants.SSL_ALWAYS;
        } else if (txt.compare("SIZE", true) == 0) {
            ret = Constants.SSL_SIZE;
        } else if (txt.compare("SERVER", true) == 0) {
            ret = Constants.SSL_SERVER;
        } else if (txt.compare("BOTH", true) == 0) {
            ret = Constants.SSL_BOTH;
        } else if (txt.compare("LOW", true) == 0) {
            ret = Constants.SSL_LOW;
        } else if (txt.compare("SPEED", true) == 0) {
            ret = Constants.SSL_SPEED;
        } else if (txt.compare("MEDIUM", true) == 0) {
            ret = Constants.SSL_MEDIUM;
        } else if (txt.compare("HIGH", true) == 0) {
            ret = Constants.SSL_HIGH;
        } else if (txt.compare("NONE", true) == 0) {
            ret = Constants.SSL_NONE;
        }
        //task.lgr.put('stringToInt(');
        //task.lgr.put(confValue);
        //task.lgr.put(') = ');
        //task.lgr.putline(ret);
        return ret;
    }
} // end class HTTPConfigManager
// c Pass 2 Conversion Time: 1359 milliseconds
TOP

Related Classes of HTTPSupport.HTTPConfigManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.