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.
This commit is contained in:
@@ -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//
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user