AddPacketToSendQueue() public méthode

add a package to the collection of packets to be send to tomcat
public AddPacketToSendQueue ( BonCodeAJP13.BonCodeAJP13Packet singlePacket ) : void
singlePacket BonCodeAJP13.BonCodeAJP13Packet
Résultat void
 public void AddPacketToSendQueueTest()
 {
     BonCodeAJP13ServerConnection target = new BonCodeAJP13ServerConnection(); // TODO: Initialize to an appropriate value
     BonCodeAJP13Packet singlePacket = null; // TODO: Initialize to an appropriate value
     target.AddPacketToSendQueue(singlePacket);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }
Exemple #2
0
        /// <summary>
        /// Main process hook for IIS invocation.
        /// </summary>
        public void ProcessRequest(HttpContext context)
        {
            //check execution
            string executionFeedback = CheckExecution(context.Request.ServerVariables);
            bool blnProceed = true;

            /* debug: dump headers
            string strOut = GetHeaders(context.Request.ServerVariables);
            context.Response.Write(strOut);
            */

            if (executionFeedback.Length == 0)
            {
                //determine web doc root if needed
                if (BonCodeAJP13Settings.BONCODEAJP13_HEADER_SUPPORT)
                {
                    BonCodeAJP13Settings.BonCodeAjp13_DocRoot = System.Web.HttpContext.Current.Server.MapPath("~");
                }

                //check whether we are resuable, we discard and re-establish connections if MAX_BONCODEAJP13_CONCURRENT_CONNECTIONS is set to zero
                if (BonCodeAJP13Settings.MAX_BONCODEAJP13_CONCURRENT_CONNECTIONS == 0)
                {
                    p_isReusable = false;
                }
                //determine whether we are declaring ourself as part of a reusable pool. If not we need to also take steps to
                //kill connections if we are close to the max of pool we maintain a ten thread margin
                //this allows limited processing to continue even if we are close to maxed out on connections
                if (p_isReusable && BonCodeAJP13Settings.MAX_BONCODEAJP13_CONCURRENT_CONNECTIONS < (p_InstanceCount + 10))
                {
                    p_isReusable = false; //new connections will be dropped immediatly
                };

                //assign reference to context to an instance handler
                p_Context = context;
                long streamLen = context.Request.InputStream.Length;
                //create TcpClient to pass to AJP13 processor, this will re-use connection until this instance is destroyed
                if (p_TcpClient == null)
                {
                    try
                    {
                        p_TcpClient = new TcpClient(BonCodeAJP13Settings.BONCODEAJP13_SERVER, BonCodeAJP13Settings.BONCODEAJP13_PORT);
                    }
                    catch (Exception e)
                    {
                        //check whether we had issues connecting to tomcat
                        string errMsg = "Error connecting to Apache Tomcat instance.<hr>Please check that a Tomcat server is running at given location and port.<br>Details:<br>" + e.Message;
                        context.Response.Write(errMsg);
                        blnProceed = false;

                    }

                    //determine whether we will need to remove the connection later
                    if (!p_isReusable)
                    {
                        p_FlagKillConnection = true;
                    }
                    else
                    {
                        p_FlagKillConnection = false;
                    }

                }

                if (blnProceed)
                {
                    //initialize AJP13 protocol connection
                    BonCodeAJP13ServerConnection sconn = new BonCodeAJP13ServerConnection();
                    sconn.FlushDelegateFunction = PrintFlush;  //this function will do the transfer to browser if we use Flush detection, we pass as delegate
                    sconn.FlushStatusFunction = IsFlushing; //will let the implementation know if flushing is still in progress
                    sconn.SetTcpClient = p_TcpClient;
                    //setup basic information (base ForwardRequest package)
                    BonCodeAJP13ForwardRequest FR = new BonCodeAJP13ForwardRequest(context.Request.ServerVariables);
                    sconn.AddPacketToSendQueue(FR);

                    //determine if extra ForwardRequests are needed.
                    //We need to create a collection of Requests (for form data and file uploads etc.)
                    if (context.Request.ContentLength > 0)
                    {
                        // need to create a collection of forward requests to package data in
                        int numOfPackets = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(context.Request.ContentLength / Convert.ToDouble(BonCodeAJP13Consts.MAX_BONCODEAJP13_USERDATA_LENGTH))));
                        int iStart = 0;
                        int iCount = 0;
                        for (int i = 1; i <= numOfPackets; i++)
                        {
                            //we need to breakdown data into multiple FR packages to tomcat
                            if (i * BonCodeAJP13Consts.MAX_BONCODEAJP13_USERDATA_LENGTH <= streamLen)
                            {
                                //we are in the middle of transferring data grab next 8188 bytes and create package
                                iStart = (i - 1) * BonCodeAJP13Consts.MAX_BONCODEAJP13_USERDATA_LENGTH;
                                iCount = Convert.ToInt32(BonCodeAJP13Consts.MAX_BONCODEAJP13_USERDATA_LENGTH);
                            }
                            else
                            {
                                //last user package
                                iStart = (i - 1) * BonCodeAJP13Consts.MAX_BONCODEAJP13_USERDATA_LENGTH;
                                iCount = Convert.ToInt32(streamLen) - iStart;
                            }
                            //add package to collection
                            byte[] streamInput = new byte[iCount];
                            context.Request.InputStream.Read(streamInput, 0, iCount); //stream pointer moves with each read so we allways start at zero position
                            sconn.AddPacketToSendQueue(new BonCodeAJP13ForwardRequest(streamInput));

                        }
                        //add an empty Forward Request packet as terminator to collection if multiple packets are used
                        //sconn.AddPacketToSendQueue(new BonCodeAJP13ForwardRequest(new byte[] { }));

                    }

                    //run connection (send and receive cycle)
                    sconn.BeginConnection();

                    //write the response to browser (if not already flushed)
                    PrintFlush(sconn.ReceivedDataCollection);

                    //kill connections if we are not reusing connections
                    if (p_FlagKillConnection)
                    {
                        KillConnection();
                    }
                }; // proceed is true

            }
            else
            {
                //execution was denied by logic, only print message
                context.Response.Write(executionFeedback);

            }
        }