com.ibm.wbi.protocol.http.beans
Class ErrorPageEditor

com.ibm.wbi.Meg
  |
  +--com.ibm.wbi.Editor
        |
        +--com.ibm.wbi.protocol.http.beans.ErrorPageEditor

public class ErrorPageEditor
extends Editor

An Editor 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 an Editor with a try block around code where an error condition could occur. When the error is detected, an ErrorPageException object is constructed and one of the following actions is taken: 1. the object is attached to the request event's (RequestInfo) transaction data. The response code in the header is modified to an appropriate value to indicate the error. This (the ErrorPageEditor is invoked by WBI to handle a request when the error code matches configured conditions. or 2. an ErrorPageEditor is constructed using the ErrorPageException and the response is forwarded to the editor for handling the error.

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
protected  java.lang.String contentType
          The content type
static java.lang.String COPYRIGHT
          IBM copyright information
protected  ErrorPageException m_EPE
           
protected  java.lang.String pageText
          The page text.
 
Fields inherited from class com.ibm.wbi.Meg
EDITOR, GENERATOR, MONITOR, REQUEST_EDITOR, UNDEFINED
 
Constructor Summary
ErrorPageEditor()
          Construct an instance with a ResponseCode of 400, a ResponseText of "Unknown Error", and a PageText of "".
ErrorPageEditor(RequestEvent re, ErrorPageException e)
          Construct an instance from the information in the ErrorPageException.
ErrorPageEditor(SystemContext systemContext, RequestEvent re, ErrorPageException e)
          Construct an instance from the information in the ErrorPageException.
 
Method Summary
 int getContentLength(RequestEvent re)
          Access the Content-Length property.
protected  java.lang.String getHeader(RequestEvent re)
           
 java.lang.String getPageText()
          Access the PageText property.
 int getResponseCode(RequestEvent re)
          Access the ResponseCode property.
 int getType()
          getType - required
 void handleRequest(RequestEvent requestEvent)
          Called by WBI on incoming requests-- or called by direct invocation (via forward()): responsible for returning an error page based on response code
 void initialize()
          Called by WBI (or some other environment) to let us know where to get our environmental configuration from (in case we need it).
 void setContentLength(RequestEvent re, int len)
          Set the Content-Length property.
 void setContentType(RequestEvent re, java.lang.String ct)
          Set the contentType property.
 void setPageText(java.lang.String pt)
          Set the PageText property.
 void setResponseCode(RequestEvent re, int rc)
          Set the ResponseCode property.
 void setResponseText(RequestEvent re, java.lang.String rt)
          Set the ResponseText property.
protected  void writeContent(RequestEvent re)
          Write the content to the output stream.
 
Methods inherited from class com.ibm.wbi.Meg
forwardRequest, getCondition, getEnabled, getMegProperty, getMegProperty, getMegPropertyKeys, getName, getPlugin, getPriority, getSystemContext, initialize, isEnabled, isMegApplicable, loadMegResources, run, setCondition, setEnabled, setMegProperty, setName, setPriority, setSystemContext, setup, setup, setup, setup
 

Field Detail

COPYRIGHT

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

pageText

protected java.lang.String pageText
The page text.

contentType

protected java.lang.String contentType
The content type

m_EPE

protected ErrorPageException m_EPE
Constructor Detail

ErrorPageEditor

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

ErrorPageEditor

public ErrorPageEditor(RequestEvent re,
                       ErrorPageException e)
Construct an instance from the information in the ErrorPageException.
Parameters:
re - The Request Event being worked on
e - The exception which indicates the type and cause of the error.

ErrorPageEditor

public ErrorPageEditor(SystemContext systemContext,
                       RequestEvent re,
                       ErrorPageException e)
Construct an instance from the information in the ErrorPageException.
Parameters:
re - The Request Event being worked on
e - The exception which indicates the type and cause of the error.
Method Detail

initialize

public void initialize()
Called by WBI (or some other environment) to let us know where to get our environmental configuration from (in case we need it).
Overrides:
initialize in class Meg
Following copied from class: com.ibm.wbi.Meg
See Also:
Meg.getSystemContext()

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.

setContentLength

public void setContentLength(RequestEvent re,
                             int len)
Set the Content-Length property.
Parameters:
rc - The HTTP Content-Length that will be passed back to the browser

getContentLength

public int getContentLength(RequestEvent re)
Access the Content-Length property.
Returns:
The Content-Length

setResponseCode

public void setResponseCode(RequestEvent re,
                            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").

getResponseCode

public int getResponseCode(RequestEvent re)
Access the ResponseCode property.
Returns:
The ResponseCode

setResponseText

public void setResponseText(RequestEvent re,
                            java.lang.String rt)
Set the ResponseText property.
Parameters:
rt - The response text that accompanies the HTTP response (e.g. "Ok").

setContentType

public void setContentType(RequestEvent re,
                           java.lang.String ct)
Set the contentType property.
Parameters:
ct - The HTTP content-type that will be passed back to the browser

getHeader

protected java.lang.String getHeader(RequestEvent re)

writeContent

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

getType

public int getType()
getType - required
Overrides:
getType in class Editor
Following copied from class: com.ibm.wbi.Editor
Returns:
Always returns Meg.EDITOR.

handleRequest

public void handleRequest(RequestEvent requestEvent)
                   throws RequestRejectedException,
                          java.io.IOException
Called by WBI on incoming requests-- or called by direct invocation (via forward()): responsible for returning an error page based on response code
Overrides:
handleRequest in class Editor
Parameters:
requestEvent - RequestEvent to process