public void LogPacketTest() { string fileName = string.Empty; // TODO: Initialize to an appropriate value Mutex loggerMutex = null; // TODO: Initialize to an appropriate value BonCodeAJP13Logger target = new BonCodeAJP13Logger(fileName, loggerMutex); // TODO: Initialize to an appropriate value BonCodeAJP13Packet packet = null; // TODO: Initialize to an appropriate value bool logAllways = false; // TODO: Initialize to an appropriate value int onlyAboveLogLevel = 0; // TODO: Initialize to an appropriate value target.LogPacket(packet, logAllways, onlyAboveLogLevel); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
private void ComunicateWithTomcat() { int numOfBytesReceived = 0; byte[] receivedPacketBuffer = new byte[BonCodeAJP13Consts.MAX_BONCODEAJP13_PACKET_LENGTH]; byte[] notProcessedBytes = null; int sendPacketCount = 0; p_IsLastPacket = false; //send packages. If multiple forward requests (i.e. form data or files) there is a different behavior expected if (p_PacketsToSend.Count > 1) { foreach (Object oIterate in p_PacketsToSend) { //we will continue sending all packets in queue unless tomcat sends us End Comm package if (!p_IsLastPacket) { sendPacketCount++; BonCodeAJP13Packet sendPacket = oIterate as BonCodeAJP13Packet; //only objects derived from this class should be in the collection //send first two packets immediatly p_NetworkStream.Write(sendPacket.GetDataBytes(), 0, sendPacket.PacketLength); //log packet if (p_Logger != null) { p_Logger.LogPacket(sendPacket, false, BonCodeAJP13LogLevels.BONCODEAJP13_LOG_HEADERS); } //after the second packet in a packet collection we have to listen and receive a TomcatGetBodyChunk if (sendPacketCount >= 2) { numOfBytesReceived = p_NetworkStream.Read(receivedPacketBuffer, 0, receivedPacketBuffer.Length); notProcessedBytes = AnalyzePackage(receivedPacketBuffer, true); //no flush processing during sending of data //we expect a 7 byte response except for the last package record, if not record a warning if (sendPacketCount != p_PacketsToSend.Count && numOfBytesReceived > 7) { if (p_Logger != null) { p_Logger.LogMessageAndType("Incorrect response received from Tomcat", "warning", 1); } } } } else { break; } } //if the last received message from tomcat is "GET_BODY_CHUNK" we need to send terminator package if (p_PacketsReceived[p_PacketsReceived.Count - 1] is TomcatGetBodyChunk) { BonCodeAJP13Packet sendPacket = new BonCodeAJP13ForwardRequest(new byte[] { }); //create terminator (empty) package p_NetworkStream.Write(sendPacket.GetDataBytes(), 0, sendPacket.PacketLength); //log packet as it is sent if (p_Logger != null) { p_Logger.LogPacket(sendPacket, false, BonCodeAJP13LogLevels.BONCODEAJP13_LOG_HEADERS); } } } else if (p_PacketsToSend.Count == 1) { //send package BonCodeAJP13Packet sendPacket = p_PacketsToSend[0] as BonCodeAJP13Packet; //only objects derived from this class should be in the collection p_NetworkStream.Write(sendPacket.GetDataBytes(), 0, sendPacket.PacketLength); //log each packet as it is sent if (p_Logger != null) { p_Logger.LogPacket(sendPacket, false, BonCodeAJP13LogLevels.BONCODEAJP13_LOG_HEADERS); } } else { //nothing to do CloseConnectionNoError("Nothing to send. Closing Connection."); return; } //switch into Receiving Mode. Receive the TcpServer.response. if (!p_IsLastPacket) { p_NetworkStream.Read(receivedPacketBuffer, 0, 0); //call empty read so we block this thread until we receive a response or we time out } numOfBytesReceived = 0; try { int readCount = 0; while (p_NetworkStream.CanRead && !p_AbortConnection && !p_IsLastPacket) { //check to see whether we need to send extra termination package if (p_SendTermPacket) { p_SendTermPacket = false; BonCodeAJP13ForwardRequest terminatorFR = new BonCodeAJP13ForwardRequest(new byte[] { }); p_NetworkStream.Write(terminatorFR.GetDataBytes(), 0, terminatorFR.PacketLength); } //clear reading array Array.Clear(receivedPacketBuffer, 0, receivedPacketBuffer.Length); //read incoming packets until timeout or last package has been received. readCount++; numOfBytesReceived = p_NetworkStream.Read(receivedPacketBuffer, 0, receivedPacketBuffer.Length); //analyze packet so far (adjust bytes from Receiving buffer):combine notProcessed with new Read bytes into new Received buffer if needed if (notProcessedBytes != null) { //create tempArray that contains new set of bytes to be send a combination of newly received bytes as well as bytes that we were not able to process yet byte[] tempArray = new byte[numOfBytesReceived + notProcessedBytes.Length]; Array.Copy(notProcessedBytes, 0, tempArray, 0, notProcessedBytes.Length); Array.Copy(receivedPacketBuffer, 0, tempArray, notProcessedBytes.Length, numOfBytesReceived); notProcessedBytes = AnalyzePackage(tempArray); } else { //send bytes we received for analysis byte[] tempArray = new byte[numOfBytesReceived]; Array.Copy(receivedPacketBuffer, 0, tempArray, 0, numOfBytesReceived); notProcessedBytes = AnalyzePackage(tempArray); } } } catch (System.IO.IOException ex) { ConnectionError("Server Connection is closing, Read timeout reached and no tomcat activity was detected.", "TimeOut"); if (p_Logger != null) { p_Logger.LogException(ex); } return; } if (p_AbortConnection) { ConnectionError("Server Connection was aborted:", "Failed"); return; } if (numOfBytesReceived == 0) { // Nothing received from tomcat! ConnectionError("Nothing received from the tomcat. Closing the Connection.", "Failed"); return; } if (p_IsLastPacket == true) { // keep alive timer needs reset (we are maintaining connection but resetting the timer if (p_KeepAliveTimer != null) { p_KeepAliveTimer.Stop(); p_KeepAliveTimer.Start(); } //CloseConnectionNoError(); } else { //do nothing for now } }