Package HTTPSupport

Source Code of HTTPSupport.HTTPSession

/*
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 org.apache.log4j.Logger;

import Framework.Application;
import Framework.DataValue;
import Framework.DistributedAccessException;
import Framework.LogMgr;
import Framework.Stream;
import Framework.TextData;

/**
* The HTTPSession class implements the GenericSession interface. Use this class to specify the nature of the session established between an HTTP client and an HTTP server. The session object defines the network session and the application session. If no session object is specified, a default session object with default session values (as defined in the HTTPConfigManager) is created.
*/
@SuppressWarnings("serial")
public class HTTPSession implements Serializable, GenericSession {
    private static Logger _log = Logger.getLogger(HTTPSession.class);

    // ----------
    // Attributes
    // ----------
    private int networkSession;
    private int applicationSession;
    private String lastURLAddress;
    private HTTPBaseMessage baseMessage;
    private String sessionID;
    private HTTPConfigManager configValues;

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

        //
        // Location associated to this session. The location is associated when
        // the message is first sent (client sending a request) or first
        // received
        // (server receivind a request). The value is used by the client to send
        // further requests.
        // If the session is a session level application, the session is managed
        // by the use of cookies. Then, the value of the session can be longer
        // than the location lifetime. Furethermore, the application session can
        // use several different locations during its lifetime.
        //
        //        this.location = null;

        //
        // There are two kind of cookie values: a value set by a client
        // trying to initiate an application session and the value set
        // by the server which have established a session.
        //
        //        this.sessionCookie = null;

        //
        // This attribute is used to store the sessionID used by to store
        // the sessionID used by the server to established a session.
        // This sessionID is then stored in the cookie before being sent.
        //
        this.sessionID = null;

        //
        // When the request is sent, the requester checks that this value is
        // the same as the value of the request URL. If this value
        // is NIL, this value is filled with the request URL address.
        //
        this.lastURLAddress = null;

        // Holds the SSL values
        this.configValues = new HTTPConfigManager();

        // Set the SSL options from the config manager
        HTTPHelper helper = new HTTPHelper();
        this.setDefaultValues(helper.findConfigManager());

    }

    // ----------------------
    // Accessors and Mutators
    // ----------------------

    public int getnetworkSession() {
        return this.networkSession;
    }

    public int getapplicationSession() {
        return this.applicationSession;
    }

    public void setlastURLAddress(String pValue) {
        this.lastURLAddress = pValue;
    }

    public String getlastURLAddress() {
        return this.lastURLAddress;
    }

    //    private void setlocation(HTTPLocation pValue) {
    //        this.location = pValue;
    //    }

    public void setbaseMessage(HTTPBaseMessage pValue) {
        this.baseMessage = pValue;
    }

    public HTTPBaseMessage getbaseMessage() {
        return this.baseMessage;
    }

    //    private void setsessionCookie(Cookie pValue) {
    //        this.sessionCookie = pValue;
    //    }

//    private void setsessionID(String pValue) {
//        this.sessionID = pValue;
//    }
//
//    private String getsessionID() {
//        return this.sessionID;
//    }

    public void setconfigValues(HTTPConfigManager pValue) {
        this.configValues = pValue;
    }

    public HTTPConfigManager getconfigValues() {
        return this.configValues;
    }

    // -------
    // Methods
    // -------
    /**
     * close
     * <p>
     * Close the TCP connection associated to the object session. <br>
     * This doesn't invalidate this object since the application <br>
     * can still be valid using a different network session. <br>
     * Only reset the location to NIL in order to allocate a new <br>
     * one the next time this object location will be used. <br>
     * <p>
     */
    public void close() {
        if (this.baseMessage != null) {
            if (/*this.location != null
                    &&*/ this.baseMessage instanceof HTTPBaseResponse) {

                if (LogMgr
                        .getInstance()
                        .test(
                                Framework.Constants.SP_MT_DEBUG,
                                Constants.HTTP_SVC,
                                Constants.HTTP_TRACE,
                                2)) {
                    Logger.getLogger("task.part.logmgr").info(
                            "HTTPSession.close - closing the location");
                    //                _log.error(this.location);
                }
                this.baseMessage.conn.disconnect();
//        this.location.close();
//        this.lastURLAddress = null;
//        this.location = null;
            } else {

                if (this.baseMessage instanceof HTTPBaseRequest){
//            && (this.location.State = DistribObjMgr.qqdo_LocationState.qqDO_LOC_STATE_STARTED)) {
//          DistributedAccessException ex = new DistributedAccessException();
//          ex.SetWithParams(Framework.Constants.SP_ER_USER,
//              application.MsgCatalog.GetString(HTTP_SET,
//                  HTTP_MSG_CLOSE_NETSESSION_FORBIDEN));
//          throw ex;
                } else {
                    _log.debug("HTTPSession.close - no location");
                }
            }
        } else {
//      if (this.location != null) {
                _log.debug("HTTPSession.close - closing the location");
//        _log.error(this.location);
//        this.location.close();
//        this.lastURLAddress = null;
//        this.location = null;
//      }

        }
    }

    /**
     * createSessionID
     * <p>
     * <p>
     *
     * @return String
     */
//    private String createSessionID() {
//        UUIDGen uuid = new UUIDGen();
//        uuid.generate();
//        return uuid.asCharPtr();
//    }

    // Method getApplicationSession() : integer skipped because it is replaced
    // by accessor / mutator.
    /**
     * getID
     * <p>
     * <p>
     *
     * @return String
     */
    public String getID() {
        return this.sessionID;
    }

    /**
     * getLocation
     * <p>
     * <p>
     *
     * @return qqdo_Location
     */
    //    public qqdo_Location getLocation()
    //    {
    //        return this.location;
    //    }
    /**
     * getMessage
     * <p>
     * <p>
     *
     * @return GenericMessage
     */
    public GenericMessage getMessage() {
        return this.baseMessage;
    }

    // Method getNetworkSession() : integer skipped because it is replaced by
    // accessor / mutator.
    /**
     * getSessionCookie
     * <p>
     * <p>
     *
     * @return Cookie
     */
    //    public Cookie getSessionCookie()
    //    {
    //        return this.sessionCookie;
    //    }
    /**
     * getSessionValue
     * <p>
     * Internal use - called when a connection has to be created <br>
     * <p>
     *
     * @param config
     *            Type: int
     * @return int
     */
    public int getSessionValue(int config) {
        return this.configValues.getConfigValue(config);
    }

    /**
     * getStringSessionValue
     * <p>
     * Internal use - called when a connection has to be created <br>
     * <p>
     *
     * @param config
     *            Type: int
     * @return String
     */
    public String getStringSessionValue(int config) {
        return this.configValues.getStringConfigValue(config);
    }

    /**
     * newConnection
     * <p>
     * <p>
     */
    public void newConnection() {
    }

    /**
     * prepareToSend
     * <p>
     * This method can be called by the client before a request sending, <br>
     * or by the server before a response sending. The processing is not <br>
     * the same. <br>
     * <p>
     *
     * @param message
     *            Type: HTTPBaseMessage
     */
    public void prepareToSend(HTTPBaseMessage message) {
        HTTPHelper helper = null;
        this.baseMessage = message;

        // Network value setup is common to request and response
        int minorVersion = message.getMinorVersion();
        int majorVersion = message.getMajorVersion();

        if (this.networkSession == Constants.HTTP_SESSION_UNKNOWN) {
            helper = new HTTPHelper();
            this.networkSession = helper
                    .findConfigManager()
                    .getConfigValue(
                            Constants.HTTP_CONFIG_TCPSESSION_VALUE);
        }

        if (this.applicationSession == Constants.HTTP_SESSION_UNKNOWN) {

            if (helper == null) {
                helper = new HTTPHelper();
            }
            this.applicationSession = helper
                    .findConfigManager()
                    .getConfigValue(
                            Constants.HTTP_CONFIG_SESSION_VALUE);
        }

        if (majorVersion == 1 && minorVersion == 1) {
            //

            if (this.networkSession == Constants.HTTP_TCPSESSION_MESSAGE) {
                message
                        .setHeader(
                                Constants.HTTP_HEADER_CONNECTION,
                                Constants.HTTP_HEADER_CLOSE_VALUE);
            }
        } else {
            //

            if (this.networkSession == Constants.HTTP_TCPSESSION_PERSISTENT) {
                message
                        .setHeader(
                                Constants.HTTP_HEADER_CONNECTION,
                                Constants.HTTP_HEADER_KEEP_ALIVE_VALUE);
            }
        }

        if (message instanceof HTTPBaseRequest) {
            // Client processing
            //
            // If this is the first send, the cookie value is not set and
            // the applicationSession value contains the kind of session
            // requested. They can be: NONE, MAYBE, REQUIRED.
            //
            // If the value is ESTABLISHED, a session has been already set
            // by a previous message send. Just check there is still
            // a session cookie.
            //
            // If the value is NONE, send a special name/value cookie to let
            // the
            // server know we do not want a session.
            // 
            // If the value is MAYBE (default value), do not send anything
            // to the
            // server. The server will automatically try to create a
            // session.
            //
            // If the value is REQUIRED, send a special name/value cookie to
            // let the server know that the client needs a session.
            //
            // Those values are back-checked with the server response in the
            // method processReceived().
            //

            //                if (LogMgr.getInstance().test(Framework.Constants.SP_MT_DEBUG,
            // Constants.HTTP_SVC,
            // Constants.HTTP_TRACE, 2)) {
            //                    Logger.getLogger("task.part.logmgr").info("HTTPSession.prepareToSend
            // - request ");
            //                    Thread.currentThread().getLgr().reportObj(Framework.Constants.SP_MT_ERROR,
            // 0, 0, (byte)0, this);
            //                }
            //
            //
            //                if (this.applicationSession ==
            // Constants.HTTP_SESSION_NONE) {
            //                    this.sessionCookie = new Cookie();
            //                    this.sessionCookie.setName(Constants.HTTP_COOKIE_FORTE_SESSION);
            //                    this.sessionCookie.setValue(Constants.HTTP_COOKIE_PREFIX_SESSION_NONE);
            //
            //                }
            //                else if (this.applicationSession ==
            // Constants.HTTP_SESSION_REQUIRED)
            // {
            //                    this.sessionCookie = new Cookie();
            //                    TextData txt = new
            // TextData(Constants.HTTP_COOKIE_PREFIX_SESSION_REQUIRED);
            //                    this.sessionCookie.setName(Constants.HTTP_COOKIE_FORTE_SESSION);
            //                    txt.concat( this.createSessionID() );
            //                    this.sessionCookie.setValue(txt.toString());
            //
            //                }
            //                else if (this.applicationSession ==
            // Constants.HTTP_SESSION_CLOSE) {
            //                    this.sessionCookie = new Cookie();
            //                    TextData txt = new
            // TextData(Constants.HTTP_COOKIE_PREFIX_SESSION_CLOSE);
            //                    this.sessionCookie.setName(Constants.HTTP_COOKIE_FORTE_SESSION);
            //                    txt.concat( this.sessionID );
            //                    this.sessionCookie.setValue(txt.toString());
            //
            //                }
            //                else if (this.applicationSession ==
            // Constants.HTTP_SESSION_ESTABLISHED
            // && this.sessionCookie == null) {
            //                    // Lost the session - throw
            //                    DistributedAccessException ex = new DistributedAccessException();
            //                    ex.setWithParams(Framework.Constants.SP_ER_USER, new
            // TextData(Application.getMsgCatalog().getString(Constants.HTTP_SET,
            // Constants.HTTP_MSG_APPLICATION_SESSION_LOST)));
            //                    throw ex;
            //
            //                }
            //                else if (this.applicationSession ==
            // Constants.HTTP_SESSION_ENDED) {
            //                    // Lost the session - throw
            //                    DistributedAccessException ex = new DistributedAccessException();
            //                    ex.setWithParams(Framework.Constants.SP_ER_USER, new
            // TextData(Application.getMsgCatalog().getString(Constants.HTTP_SET,
            // Constants.HTTP_MSG_APPLICATION_SESSION_ENDED)));
            //                    throw ex;
            //
            //                }
            //            }
            //            else {
            //                // Server processing
            //
            //                if (LogMgr.getInstance().test(Framework.Constants.SP_MT_DEBUG,
            // Constants.HTTP_SVC,
            // Constants.HTTP_TRACE, 2)) {
            //                    Logger.getLogger("task.part.logmgr").info("HTTPSession.prepareToSend
            // - response ");
            //                    Thread.currentThread().getLgr().reportObj(Framework.Constants.SP_MT_ERROR,
            // 0, 0, (byte)0, this);
            //                }
            //
            //                //
            //                // The server has processed the request and is going to send the
            //                // response. The state of the application session can be:
            //                // NONE, CLOSE or ESTABLISHED. Build the appropriate cookie,
            //                // using the sessionID that the server has stored in
            //        // self.sessionID.
            //                //
            //                // or
            //                // self.applicationSession = HTTP_SESSION_CLOSE
            //
            //                if (this.applicationSession ==
            // Constants.HTTP_SESSION_ESTABLISHED)
            // {
            //                    this.sessionCookie = new Cookie();
            //                    TextData txt = new TextData();
            //                    txt.setValue(
            // Constants.HTTP_COOKIE_PREFIX_SESSION_ESTABLISHED
            // );
            //                    // if self.applicationSession = HTTP_SESSION_ESTABLISHED
            //                    // then
            //                    // txt.setValue(HTTP_COOKIE_PREFIX_SESSION_ESTABLISHED);
            //                    // else
            //                    // //
            //                    // // Fix B#51615, if the client is not an HTTPDC client,
            //                    // // it will send back the CLOSE session cookies.
            //                    // // We need to send back a CLOSED state (different from
            //                    // // CLOSE) which can be ignored by the server
            //                    // // if it is sent back by the client.
            //                    // //
            //                    // txt.setValue(HTTP_COOKIE_PREFIX_SESSION_CLOSED);
            //                    // end if;
            //                    this.sessionCookie.setName(Constants.HTTP_COOKIE_FORTE_SESSION);
            //                    txt.concat( this.sessionID );
            //                    this.sessionCookie.setValue(txt.toString());
            //
            //                }
            //                else {
            //                    // No session cookie to send back. If the original was
            //                    // MAYBE it will remain MAYBE, if it was NONE it will remain
            //          // NONE
            //                    // Also, Fix B#51615: if the application session has been
            //          // closed,
            //                    // do not send back a cookie.
            //                    //
            //                    this.sessionCookie = null;
            //                }
            //            }
            //
            //            // Remove any previous FORTE_SESSION_COOKIE cookie
            //            Array_Of_Cookie qq_localVector = message.getCookies();
            //            if (qq_localVector != null) {
            //                for (Iterator qq_it = qq_localVector.iterator();
            // qq_it.hasNext();) {
            //                    Cookie c = (Cookie)qq_it.next();
            //
            //                    if
            // (Constants.HTTP_COOKIE_FORTE_SESSION.equals(c.getName()))
            // {
            //                        message.getCookies().deleteRow(c);
            //                        break;
            //                    }
            //                }
        }
        //
        //
        //            if (this.sessionCookie != null) {
        //                message.addCookie(this.sessionCookie);
        //            }
    }

    /**
     * print
     * <p>
     * <p>
     *
     * @param stream
     *            Type: Stream
     * @param level
     *            Type: int (default in Forte: 0)
     */
    public void print(Stream stream, int level) {

        stream.writeText("HTTPSession:");
        stream.writeText("\n  Network session: ");
        stream.writeText(this.sessionToString(this.networkSession));

        stream.writeText("\n  Application session: ");
        stream.writeText(this.sessionToString(this.applicationSession));

        stream.writeText("\n  SessionID: ");
        if (this.sessionID == null) {
            stream.writeText("NIL");
        }
        else {
            stream.writeText(this.sessionID);
        }
        stream.writeText("\n");

//        if (this.sessionCookie != null) {
//            this.sessionCookie.print(stream, level);
//        }
//        else {
//            stream.writeText("\n  No cookie");
//        }
        stream.writeText("\n");
    }

    /**
     * processReceived
     * <p>
     * This method can be called by the client receiving a response or <br>
     * the server receiving a request. <br>
     * <p>
     *
     * @param message
     *            Type: HTTPBaseMessage
     * @param sessionCookie
     *            Type: Cookie
     */
    //        public void processReceived(HTTPBaseMessage message, Cookie
    // sessionCookie)
    //        {
    //            this.baseMessage = message;
    //
    //            int minorVersion = message.getMinorVersion();
    //            int majorVersion = message.getMajorVersion();
    //            String value =
    // message.getHeader(Constants.HTTP_HEADER_CONNECTION);
    //
    //            int defaultNetworkSession = 0;
    //
    //
    //            if (majorVersion == 1 && minorVersion == 1) {
    //                //
    //
    //                if
    // (Constants.HTTP_HEADER_CLOSE_VALUE.equals(value))
    // {
    //                    defaultNetworkSession =
    // Constants.HTTP_TCPSESSION_MESSAGE;
    //                }
    //                else {
    //                    defaultNetworkSession =
    // Constants.HTTP_TCPSESSION_PERSISTENT;
    //                }
    //            }
    //            else {
    //                //
    //
    //                if
    // (Constants.HTTP_HEADER_KEEP_ALIVE_VALUE.equals(value))
    // {
    //                    defaultNetworkSession =
    // Constants.HTTP_TCPSESSION_PERSISTENT;
    //                }
    //                else {
    //                    defaultNetworkSession =
    // Constants.HTTP_TCPSESSION_MESSAGE;
    //                }
    //            }
    //
    //
    //            if (message instanceof HTTPBaseRequest) {
    //                //
    //                // Server processing a client request
    //                //
    //                // The server sets its network session policy on a per msg base
    //                this.networkSession = defaultNetworkSession;
    //
    //
    //                if (sessionCookie != null) {
    //                    TextData txt = new TextData(sessionCookie.getValue());
    //                    String prefix = null;
    //
    //                    prefix = txt.copyRange(0,
    // Constants.HTTP_COOKIE_PREFIX_LENGTH).toString();
    //
    //                    if (txt.getActualSize() >
    // Constants.HTTP_COOKIE_PREFIX_LENGTH) {
    //                        this.sessionID =
    // txt.copyRange(Constants.HTTP_COOKIE_PREFIX_LENGTH).toString();
    //                    }
    //                    else {
    //                        this.sessionID = null;
    //                    }
    //
    //
    //                    if
    // (Constants.HTTP_COOKIE_PREFIX_SESSION_NONE.equals(prefix))
    // {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_NONE;
    //                        sessionCookie = null;
    //                    }
    //                    else if
    // (Constants.HTTP_COOKIE_PREFIX_SESSION_REQUIRED.equals(prefix))
    // {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_REQUIRED;
    //                    }
    //                    else if
    // (Constants.HTTP_COOKIE_PREFIX_SESSION_CLOSE.equals(prefix))
    // {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_CLOSE;
    //                        // elseif prefix = HTTP_COOKIE_PREFIX_SESSION_CLOSED
    //                        // then
    //                        // //
    //                        // // Fix B#51615, if the client is not an HTTPDC
    //            // client,
    //                        // // it will send back the CLOSED session cookie.
    //            // Ignore it.
    //                        // //
    //                        // self.applicationSession = HTTP_SESSION_MAYBE;
    //                        // self.sessionID = NIL;
    //                    }
    //                    else if
    // (Constants.HTTP_COOKIE_PREFIX_SESSION_ESTABLISHED.equals(prefix))
    // {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_ESTABLISHED;
    //                    }
    //                    else {
    //                        DistributedAccessException ex = new DistributedAccessException();
    //                        TextData txtPrefix = new TextData();
    //                        txtPrefix.setValue( prefix );
    //                        ex.setWithParams(Framework.Constants.SP_ER_USER, new
    // TextData(Application.getMsgCatalog().getString(Constants.HTTP_SET,
    // Constants.HTTP_MSG_INVALID_SESSION_REQUEST_PREFIX)),
    // txtPrefix, (DataValue)null, (DataValue)null, (DataValue)null,
    // (DataValue)null, (DataValue)null, (DataValue)null, (DataValue)null,
    // (DataValue)null);
    //                        throw ex;
    //                    }
    //                }
    //                else {
    //                    this.applicationSession =
    // Constants.HTTP_SESSION_MAYBE;
    //                }
    //
    //                this.sessionCookie = sessionCookie;
    //
    //
    //                if (LogMgr.getInstance().test(Framework.Constants.SP_MT_DEBUG,
    // Constants.HTTP_SVC,
    // Constants.HTTP_TRACE, 2)) {
    //                    Logger.getLogger("task.part.logmgr").info("HTTPSession.processReceived
    // - request ");
    //                    Thread.currentThread().getLgr().reportObj(Framework.Constants.SP_MT_ERROR,
    // 0, 0, (byte)0, this);
    //                }
    //            }
    //            else {
    //                //
    //                // Client processing a server response.
    //                //
    //                // If the session should close, change the current setting
    //
    //                if (defaultNetworkSession ==
    // Constants.HTTP_TCPSESSION_MESSAGE) {
    //                    this.networkSession = defaultNetworkSession;
    //                }
    //
    //                // If there is no sessionCookie, leave the session as it, else
    //        // update.
    //                this.sessionCookie = sessionCookie;
    //
    //
    //                if (sessionCookie != null) {
    //                    TextData txt = new TextData(sessionCookie.getValue());
    //                    String prefix = null;
    //
    //                    prefix = txt.copyRange(0,
    // Constants.HTTP_COOKIE_PREFIX_LENGTH).toString();
    //
    //                    if (txt.getActualSize() >
    // Constants.HTTP_COOKIE_PREFIX_LENGTH) {
    //                        this.sessionID =
    // txt.copyRange(Constants.HTTP_COOKIE_PREFIX_LENGTH).toString();
    //                    }
    //                    else {
    //                        this.sessionID = null;
    //                    }
    //
    //                    //
    //                    // Fix B#51615, the server is now sending back no cookie
    //          // when
    //                    // the application session has been closed.
    //                    // Leave this test for compatibility purpose (old server
    //                    // running with new clients)
    //                    //
    //
    //                    if
    // (Constants.HTTP_COOKIE_PREFIX_SESSION_CLOSE.equals(prefix))
    // {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_ENDED;
    //                    }
    //                    else if
    // (Constants.HTTP_COOKIE_PREFIX_SESSION_ESTABLISHED.equals(prefix))
    // {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_ESTABLISHED;
    //                    }
    //                    else {
    //                        DistributedAccessException ex = new DistributedAccessException();
    //                        TextData txtPrefix = new TextData();
    //                        txtPrefix.setValue( prefix );
    //                        ex.setWithParams(Framework.Constants.SP_ER_USER, new
    // TextData(Application.getMsgCatalog().getString(Constants.HTTP_SET,
    // Constants.HTTP_MSG_INVALID_SESSION_RESPONSE_PREFIX)),
    // txtPrefix, (DataValue)null, (DataValue)null, (DataValue)null,
    // (DataValue)null, (DataValue)null, (DataValue)null, (DataValue)null,
    // (DataValue)null);
    //                        throw ex;
    //                    }
    //                }
    //                else {
    //                    //
    //                    // Fix B#51615, no cookie sent back. If the session was
    //                    // established, it is now ended.
    //                    //
    //
    //                    if (this.applicationSession ==
    // Constants.HTTP_SESSION_ESTABLISHED) {
    //                        this.applicationSession =
    // Constants.HTTP_SESSION_ENDED;
    //                    }
    //                }
    //
    //
    //                if (LogMgr.getInstance().test(Framework.Constants.SP_MT_DEBUG,
    // Constants.HTTP_SVC,
    // Constants.HTTP_TRACE, 2)) {
    //                    Logger.getLogger("task.part.logmgr").info("HTTPSession.processReceived
    // - response ");
    //                    Thread.currentThread().getLgr().reportObj(Framework.Constants.SP_MT_ERROR,
    // 0, 0, (byte)0, this);
    //                }
    //            }
    //        }
    /**
     * querySession
     * <p>
     * Read the information from the network session <br>
     * <p>
     *
     * @param config
     *            Type: int
     * @return int
     */
    public int querySession(int config) {

        return -1;
    }

    /**
     * sessionToString
     * <p>
     * <p>
     *
     * @param type
     *            Type: int
     * @return String
     */
    public String sessionToString(int type) {
        switch (type) {
        case Constants.HTTP_TCPSESSION_MESSAGE: {
            return "TCP-Message";
        }
        case Constants.HTTP_TCPSESSION_PERSISTENT: {
            return "TCP-Persistent";
        }
        case Constants.HTTP_SESSION_NONE: {
            return "None";
        }
        case Constants.HTTP_SESSION_MAYBE: {
            return "Maybe";
        }
        case Constants.HTTP_SESSION_REQUIRED: {
            return "Required";
        }
        case Constants.HTTP_SESSION_ESTABLISHED: {
            return "Established";
        }
        case Constants.HTTP_SESSION_CLOSE: {
            return "Close";
        }
        case Constants.HTTP_SESSION_ENDED: {
            return "Ended";
        }

        default: {
            TextData txt = new TextData();
            txt.setValue("Unknown(");
            txt.concat(type);
            txt.concat(")");
            return txt.toString();
        }
        }
    }

    /**
     * setApplicationSession
     * <p>
     * Check that the session type is changed to a new valid type <br>
     * <p>
     *
     * @param type
     *            Type: int
     */
    public void setApplicationSession(int type) {
        boolean invalidType = false;

        if (type == this.applicationSession) {
            return;
        }

        if (type == Constants.HTTP_SESSION_ESTABLISHED
                || type == Constants.HTTP_SESSION_ENDED) {
            //
            // These types are internaly changed only. Do not allow the user
            // to use them.
            //
            invalidType = true;
        } else {
            switch (this.applicationSession) {
            case Constants.HTTP_SESSION_UNKNOWN: {
                this.applicationSession = type;

                break;
            }
            case Constants.HTTP_SESSION_NONE: {
                // Can be changed to N, R or M.

                if (type != Constants.HTTP_SESSION_CLOSE) {
                    this.applicationSession = type;
                } else {
                    invalidType = true;
                }

                break;
            }
            case Constants.HTTP_SESSION_MAYBE: {
                // Can be changed to N, R or M.

                if (type != Constants.HTTP_SESSION_CLOSE) {
                    this.applicationSession = type;
                } else {
                    invalidType = true;
                }

                break;
            }
            case Constants.HTTP_SESSION_REQUIRED: {
                // Can only change to N (reject the session)

                if (type == Constants.HTTP_SESSION_NONE) {
                    this.applicationSession = type;
                } else {
                    invalidType = true;
                }

                break;
            }
            case Constants.HTTP_SESSION_ESTABLISHED: {
                // Can only close the session

                if (type == Constants.HTTP_SESSION_CLOSE) {
                    this.applicationSession = type;
                } else {
                    invalidType = true;
                }

                break;
            }
            case Constants.HTTP_SESSION_ENDED: {

                if (type == Constants.HTTP_SESSION_RESET) {
                    this.applicationSession = Constants.HTTP_SESSION_UNKNOWN;
                    this.sessionID = null;
                    //                            this.sessionCookie = null;
                } else {
                    invalidType = true;
                }

                break;
            }

            default: {
                invalidType = true;
                break;
            }
            }
        }

        if (invalidType) {
            // Lost the session - throw
            DistributedAccessException ex = new DistributedAccessException();
            TextData txt1 = new TextData();
            TextData txt2 = new TextData();

            txt1.setValue(this.sessionToString(this.applicationSession));
            txt2.setValue(this.sessionToString(type));

            if (LogMgr.getInstance().test(
                    Framework.Constants.SP_MT_DEBUG,
                    Constants.HTTP_SVC,
                    Constants.HTTP_TRACE, 5)) {
                Logger
                        .getLogger("task.part.logmgr")
                        .info(
                                "HTTPSession.setApplicationSession - current sesion type is ");
                Logger.getLogger("task.part.logmgr").info(
                        txt1.toString());
                Logger.getLogger("task.part.logmgr").info(
                        "therefore it cannot be changed to ");
                Logger.getLogger("task.part.logmgr").info(
                        txt2.toString());
            }

            ex
                    .setWithParams(
                            Framework.Constants.SP_ER_USER,
                            new TextData(
                                    Application
                                            .getMsgCatalog()
                                            .getString(
                                                    Constants.HTTP_SET,
                                                    Constants.HTTP_MSG_APPLICATION_SESSION_TYPE_INVALID)),
                            txt1, txt2, (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null,
                            (DataValue) null);
            throw ex;
        }
    }

    /**
     * setDefaultValues
     * <p>
     * <p>
     *
     * @param configMgr
     *            Type: HTTPConfigManager
     */
    public void setDefaultValues(HTTPConfigManager configMgr) {
        for (int i = Constants.SSL_SECURE; i <= Constants.SSL_AUTHENTICATE; i++) {
            this.configValues.setConfigValue(i, configMgr.getConfigValue(i));
        }
        // Bad practice but makes things easier (see the httpdc.pex file).
        for (int i = Constants.SSL_CERTFILE; i <= Constants.SSL_ROOTPASSWORDFILE; i++) {
            this.configValues.setConfigValue(i, configMgr
                    .getStringConfigValue(i));
        }
    }

    /**
     * setID
     * <p>
     * (not part of the GenericSession) <br>
     * When a server is processing a NONE or MAYBE request, it will <br>
     * create the sessionID. When the MAYBE becomes an ESTABLISHED, <br>
     * the value must be sent back to the client as the sessionID. <br>
     * The purpose of this function is to provide the server <br>
     * a way of saving the ID in the session object to be used <br>
     * later at prepareToSend() time. <br>
     * <p>
     *
     * @param sessionID
     *            Type: String
     */
    public void setID(String sessionID) {
        this.sessionID = sessionID;
    }

    /**
     * setLocation
     * <p>
     * <p>
     *
     * @param location
     *            Type: qqdo_Location
     */
    //        public void setLocation(qqdo_Location location)
    //        {
    //
    //            if (location instanceof HTTPLocation) {
    //                this.location = (HTTPLocation)location;
    //            }
    //            else {
    //                DistributedAccessException ex = new DistributedAccessException();
    //                TextData txt = new TextData();
    //
    //                if (location != null) {
    //                    txt.setValue(((Object)location).getClass().getSimpleName());
    //                }
    //                ex.setWithParams(Framework.Constants.SP_ER_USER, new
    // TextData(Application.getMsgCatalog().getString(Constants.HTTP_SET,
    // Constants.HTTP_MSG_NOT_HTTP_LOCATION)),
    // txt, (DataValue)null, (DataValue)null, (DataValue)null, (DataValue)null,
    // (DataValue)null, (DataValue)null, (DataValue)null, (DataValue)null);
    //                throw ex;
    //            }
    //        }
    /**
     * setMessage
     * <p>
     * <p>
     *
     * @param message
     *            Type: GenericMessage
     */
    public void setMessage(GenericMessage message) {

        if (message == null) {
            this.baseMessage = null;
        } else if (((Object) message) instanceof HTTPBaseMessage) {
            this.baseMessage = (HTTPBaseMessage) message;
        } else {
            DistributedAccessException ex = new DistributedAccessException();
            TextData txt = new TextData();

            if (message != null) {
                txt.setValue(((Object) message).getClass().getName());
            }
            ex
                    .setWithParams(
                            Framework.Constants.SP_ER_USER,
                            new TextData(
                                    Application
                                            .getMsgCatalog()
                                            .getString(
                                                    Constants.HTTP_SET,
                                                    Constants.HTTP_MSG_NOT_HTTP_MESSAGE)),
                            txt, (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null);
            throw ex;
        }
    }

    /**
     * setNetworkSession
     * <p>
     * <p>
     *
     * @param type
     *            Type: int
     */
    public void setNetworkSession(int type) {

        if (type == Constants.HTTP_TCPSESSION_MESSAGE
                || type == Constants.HTTP_TCPSESSION_PERSISTENT) {
            this.networkSession = type;
        } else {
            DistributedAccessException ex = new DistributedAccessException();
            TextData txt = new TextData();

            txt.setValue(this.sessionToString(type));
            ex
                    .setWithParams(
                            Framework.Constants.SP_ER_USER,
                            new TextData(
                                    Application
                                            .getMsgCatalog()
                                            .getString(
                                                    Constants.HTTP_SET,
                                                    Constants.HTTP_MSG_NETWORK_SESSION_TYPE_INVALID)),
                            txt, (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null,
                            (DataValue) null, (DataValue) null);
            throw ex;
        }
    }

    /**
     * setSessionValue
     * <p>
     * <p>
     *
     * @param config
     *            Type: int
     * @param value
     *            Type: int
     */
    public void setSessionValue(int config, int value) {

    }

    /**
     * setSessionValue
     * <p>
     * <p>
     *
     * @param config
     *            Type: int
     * @param value
     *            Type: String
     */
    public void setSessionValue(int config, String value) {

    }

    public int getApplicationSession() {
        return 0;
    }

    public int getNetworkSession() {
        return 0;
    }

} // end class HTTPSession
// c Pass 2 Conversion Time: 3188 milliseconds
TOP

Related Classes of HTTPSupport.HTTPSession

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.