From b3648439e6715b4d01533dfc81ac0fe7e8fcf158 Mon Sep 17 00:00:00 2001 From: wcrisman Date: Mon, 29 Dec 2014 09:18:59 -0800 Subject: [PATCH] Fixed bug where initialization wasn't affecting the isClosed status of a message (not initialized meant that the buffer was null which indicated the message was closed before it had ever started being sent). Moved isInitialized into the MessageBuffer base class. --- .../foundation/web/server/HttpMessageBuffer.java | 6 ++---- .../com/foundation/web/server/MessageBuffer.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Foundation Web Core/src/com/foundation/web/server/HttpMessageBuffer.java b/Foundation Web Core/src/com/foundation/web/server/HttpMessageBuffer.java index c3fd884..bc57820 100644 --- a/Foundation Web Core/src/com/foundation/web/server/HttpMessageBuffer.java +++ b/Foundation Web Core/src/com/foundation/web/server/HttpMessageBuffer.java @@ -20,8 +20,6 @@ public class HttpMessageBuffer extends MessageBuffer { private Response response = null; /** The content if there is any. */ private IContent content = null; - /** Flag indicating if initialization is required. */ - private boolean isInitialized = false; /** * HttpMessageBuffer constructor. * @param socketContext The socket context associated with this message buffer. @@ -37,8 +35,8 @@ public Response getResponse() {return response;} * @see com.foundation.web.server.WebServer.MessageBuffer#initialize() */ public boolean initialize() { - if(!isInitialized) { - isInitialized = true; + if(!getIsInitialized()) { + super.initialize(); prepareResponse(response); }//if// diff --git a/Foundation Web Core/src/com/foundation/web/server/MessageBuffer.java b/Foundation Web Core/src/com/foundation/web/server/MessageBuffer.java index 8a6db16..5278097 100644 --- a/Foundation Web Core/src/com/foundation/web/server/MessageBuffer.java +++ b/Foundation Web Core/src/com/foundation/web/server/MessageBuffer.java @@ -14,6 +14,8 @@ class MessageBuffer { private ByteBuffer buffer = null; /** The ability to chain message buffers into a linked list. */ private MessageBuffer next = null; + /** Flag indicating if initialization is required. */ + private boolean isInitialized = false; /** * MessageBuffer constructor. * @param socketContext The socket context associated with this message buffer. @@ -34,6 +36,8 @@ public MessageBuffer(AbstractSocketContext socketContext, ByteBuffer buffer) { protected WebServer getWebServer() {return socketContext.getWebServer();} /** Gets the socket context that this message buffer exists within. */ protected AbstractSocketContext getSocketContext() {return socketContext;} +/** Gets the whether the buffer has been initialized yet. */ +protected boolean getIsInitialized() {return isInitialized;} /** * Sets the actual underlying buffer for the message buffer. * @param buffer @@ -45,11 +49,12 @@ protected void setBuffer(ByteBuffer buffer) { if(buffer != null && buffer.position() != 0) buffer.flip(); }//setBuffer()// /** - * Initializes the message buffer for use. + * Initializes the message buffer for use. Subclasses may implement but must call this method to set the isInitialized flag. * @return Whether initialization succeded. Intialization should be considered a success even if none is required or has already been performed. If it fails the caller should close the socket. */ public boolean initialize() { - //Does nothing by default. Subclasses may implement.// + isInitialized = true; + return true; }//initialize()// /** @@ -57,13 +62,14 @@ public boolean initialize() { * @return If the bytes have all been sent. */ public boolean isClosed() { - return buffer == null; + return isInitialized && buffer == null; }//isClosed()// /** * Closes the message buffer. */ public void close() { - this.buffer = null; + buffer = null; + isInitialized = true; }//close()// /** * Gets the byte buffer containing the current portion of the message to be sent.