com.ibm.wbi.http.beans
Class ErrorPageGenerator

com.ibm.wbi.plugin.Meg
  |
  +--com.ibm.wbi.plugin.Generator
        |
        +--com.ibm.wbi.http.plugin.HttpGenerator
              |
              +--com.ibm.wbi.http.beans.FourStepHttpGenerator
                    |
                    +--com.ibm.wbi.http.beans.ErrorPageGenerator

public class ErrorPageGenerator
extends FourStepHttpGenerator

A Generator for producing an HTTP response that corresponds to an error condition. It is designed to work in conjunction with the ErrorPageException class. Typically, the programmer will write a Generator with a try block around code where an error condition could occur. When the error is detected, an ErrorPageException object should be constructed and thrown. The catch block would then construct an ErrorPageGenerator from the ErrorPageException and forward the original RequestEvent to it for handling. The ErrorPageGenerator will then produce the appropriate response.

For example:

  public void handleRequest(RequestEvent e) {
    try {
      ... determine if error has occurred ...
      if (error) throw new ErrorPageException(404, "URL does not exist");
      .. do other stuff ...
    } catch (ErrorPageException epe) {
      forwardRequest(new ErrorPageGenerator(epe), e);
    }
  }
  

There are three properties that can be set: ResponseCode, ResponseText, and PageText. The ResponseCode is the HTTP code that will be in the HTTP response. The ResponseText is the short message that is part of the HTTP response. The PageText is the HTML that accompanies the HTTP response.

See Also:
ErrorPageException

Field Summary
static java.lang.String COPYRIGHT
          IBM copyright information
protected  java.lang.String pageText
          The page text.
 
Fields inherited from class com.ibm.wbi.http.plugin.HttpGenerator
COPYRIGHT, http
 
Fields inherited from class com.ibm.wbi.plugin.Generator
COPYRIGHT
 
Fields inherited from class com.ibm.wbi.plugin.Meg
COPYRIGHT, EDITOR, GENERATOR, MONITOR, REQUEST_EDITOR, UNDEFINED
 
Constructor Summary
ErrorPageGenerator()
          Construct an instance with a ResponseCode of 400, a ResponseText of "Unknown Error", and a PageText of "".
ErrorPageGenerator(ErrorPageException e)
          Construct an instance from the information in the ErrorPageException.
 
Method Summary
protected  java.lang.String getHeader(RequestEvent e)
          Get the header.
 java.lang.String getPageText()
          Access the PageText property.
 int getResponseCode()
          Access the ResponseCode property.
 java.lang.String getResponseText()
          Access the ResponseText property.
 void setPageText(java.lang.String pt)
          Set the PageText property.
 void setResponseCode(int rc)
          Set the ResponseCode property.
 void setResponseText(java.lang.String rt)
          Set the ResponseText property.
protected  void writeContent(RequestEvent e)
          Write the content to the output stream.
 
Methods inherited from class com.ibm.wbi.http.beans.FourStepHttpGenerator
handleRequest, initialize, verify
 
Methods inherited from class com.ibm.wbi.http.plugin.HttpGenerator
add, addCookie, getContentType, getHttpResponse, getHttpResponseString, isCache, produceHeader, set, setCache, setContentLength, setContentType, setServer, writeHeader
 
Methods inherited from class com.ibm.wbi.plugin.Generator
getMegType
 
Methods inherited from class com.ibm.wbi.plugin.Meg
forwardRequest, getCondition, getEnabled, getName, getPlugin, getPriority, isEnabled, processRejectedRequest, setCondition, setEnabled, setName, setPriority, setup, setup, setup, setup, threadManagerRun
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
IBM copyright information

pageText

protected java.lang.String pageText
The page text.
Constructor Detail

ErrorPageGenerator

public ErrorPageGenerator()
Construct an instance with a ResponseCode of 400, a ResponseText of "Unknown Error", and a PageText of "".

ErrorPageGenerator

public ErrorPageGenerator(ErrorPageException e)
Construct an instance from the information in the ErrorPageException.
Parameters:
e - The exception which indicates the type and cause of the error.
Method Detail

setPageText

public void setPageText(java.lang.String pt)
Set the PageText property.
Parameters:
pt - The HTML that will be passed back to the browser for display.

getPageText

public java.lang.String getPageText()
Access the PageText property.

setResponseCode

public void setResponseCode(int rc)
Set the ResponseCode property.
Parameters:
rc - The HTTP response code that will be passed back to the browser (e.g. 200, meaning "Ok").
Overrides:
setResponseCode in class HttpGenerator

getResponseCode

public int getResponseCode()
Access the ResponseCode property.
Returns:
The ResponseCode
Overrides:
getResponseCode in class HttpGenerator

setResponseText

public void setResponseText(java.lang.String rt)
Set the ResponseText property.
Parameters:
rt - The response text that accompanies the HTTP response (e.g. "Ok").
Overrides:
setResponseText in class HttpGenerator

getResponseText

public java.lang.String getResponseText()
Access the ResponseText property.
Returns:
The ResponseText
Overrides:
getResponseText in class HttpGenerator

getHeader

protected java.lang.String getHeader(RequestEvent e)
Get the header.
Parameters:
e - The request event,
Returns:
The header.
Overrides:
getHeader in class FourStepHttpGenerator

writeContent

protected void writeContent(RequestEvent e)
                     throws java.io.IOException
Write the content to the output stream.
Parameters:
e - The request event.
Throws:
java.io.IOException - If an error occurs.
Overrides:
writeContent in class FourStepHttpGenerator