jason.framework.protocol.http
Class HttpResponseBuilderImpl

java.lang.Object
  |
  +--jason.framework.protocol.http.HttpResponseBuilderImpl
All Implemented Interfaces:
HttpResponseBuilder

public class HttpResponseBuilderImpl
extends java.lang.Object
implements HttpResponseBuilder

Created Thu Jan 3 13:11:22 2002

This classe is responsable to build a valid HTTP response. User must set parameters and call the build method for a valid response.

Here a short desciption of an HTTP response from the RFC 2068 :

 generic-message = start-line
                   *message-header
 CRLF
 [ message-body ]

 start-line = Request-Line | Status-Line
 Request-Line = Method SP Request-URI SP HTTP-Version CRLF
 Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
 


Constructor Summary
HttpResponseBuilderImpl(HttpRequestParser parser)
          Build an HttpResponseBuilder with the opponent request parser value
HttpResponseBuilderImpl(HttpRequestParser parser, int status)
          Build an HttpResponseBuilderImpl with the opponent request parser value and a status code
 
Method Summary
protected  void buildMessageBodyResponse(java.io.OutputStream output)
          Add the message body part (look at the class header)
protected  void buildMessageHeaderResponse(java.io.PrintWriter pw)
          Build a response with the message-header parser (look at the class header)
protected  void buildRequestLineResponse(java.io.PrintWriter pw)
          Request-Line = Method SP Request-URI SP HTTP-Version CRLF
Build a response for the Request-Line rule (look at the class header)
 void buildResponse(java.io.OutputStream output)
          Build a response from the output stream with the browser
protected  void buildStatusLineResponse(java.io.PrintWriter pw)
          Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
Build a response for the Status-Line rule (look at the class header)
 void setContent(byte[] content)
          Set the content of the [message-body] part
protected  void setContentLength(int length)
          Reset the content-length, it should be coherent with the setContent call.
 void setContentType(java.lang.String type)
          Reset the content-type of the content message-body part
 void setMessageHeader(java.lang.String field, java.lang.String value)
          Stores a message Header that will be sent with the HTTP response (look at the class header for the rule)
 void setServer(java.lang.String server)
          Set the server name for the response
 void setStatusCode(int statusCode)
          A statusCode should be >= 100 and <= 505
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpResponseBuilderImpl

public HttpResponseBuilderImpl(HttpRequestParser parser)
Build an HttpResponseBuilder with the opponent request parser value


HttpResponseBuilderImpl

public HttpResponseBuilderImpl(HttpRequestParser parser,
                               int status)
Build an HttpResponseBuilderImpl with the opponent request parser value and a status code

Method Detail

setStatusCode

public void setStatusCode(int statusCode)
A statusCode should be >= 100 and <= 505

Specified by:
setStatusCode in interface HttpResponseBuilder

buildResponse

public void buildResponse(java.io.OutputStream output)
                   throws java.io.IOException
Build a response from the output stream with the browser

Specified by:
buildResponse in interface HttpResponseBuilder
java.io.IOException

buildMessageHeaderResponse

protected void buildMessageHeaderResponse(java.io.PrintWriter pw)
                                   throws java.io.IOException
Build a response with the message-header parser (look at the class header)

java.io.IOException

buildStatusLineResponse

protected void buildStatusLineResponse(java.io.PrintWriter pw)
                                throws java.io.IOException
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

Build a response for the Status-Line rule (look at the class header)

java.io.IOException

buildRequestLineResponse

protected void buildRequestLineResponse(java.io.PrintWriter pw)
                                 throws java.io.IOException
Request-Line = Method SP Request-URI SP HTTP-Version CRLF

Build a response for the Request-Line rule (look at the class header)

java.io.IOException

buildMessageBodyResponse

protected void buildMessageBodyResponse(java.io.OutputStream output)
                                 throws java.io.IOException
Add the message body part (look at the class header)

java.io.IOException

setMessageHeader

public void setMessageHeader(java.lang.String field,
                             java.lang.String value)
Stores a message Header that will be sent with the HTTP response (look at the class header for the rule)

Specified by:
setMessageHeader in interface HttpResponseBuilder

setContentType

public void setContentType(java.lang.String type)
Reset the content-type of the content message-body part

Specified by:
setContentType in interface HttpResponseBuilder
Parameters:
type - is a MIME type (text/html for instance)

setContentLength

protected void setContentLength(int length)
Reset the content-length, it should be coherent with the setContent call. Note that this last method resets itself this field, you theorically have no reason to reset it


setContent

public void setContent(byte[] content)
Set the content of the [message-body] part

Specified by:
setContent in interface HttpResponseBuilder

setServer

public void setServer(java.lang.String server)
Set the server name for the response

Specified by:
setServer in interface HttpResponseBuilder