IServletErrorHandler interface
The interface com.netscape.server.servlet.extension.HttpServletRequest2 uses IServletErrorHandler to inform the user of validation errors or other types of errors.
Although anyone developing an application for NAS can use IServletErrorHandler, this interface is typically used in components generated by Netscape Application Builder.
Package
com.netscape.server.servlet.extension
Methods
handleInputValueError( )
Performs error handling for input parameter validation.
Syntax
public abstract int handleInputValueError(
HttpServletRequest request,
String name,
int errorType)
request.
The HttpServletRequest containing the invalid input.
name.
The parameter name that failed validation.
errorType.
An integer value identifying the error type. The error type is passed in by the HttpServletRequest2.validate( ) method. Values for possible error types are listed under the validate( ) method.
Usage
Typically, the handleInputValueError( ) method is never called directly by the application programmer. Instead, this method is called by HttpServletRequest2.validate( ) for each error that is found during input parameter validation.
handleInputValueError( ) is called if a parameter fails its metadata-driven validation. You can use this method in one of several ways:
The default behavior of handleInputValueError( ) is to add values into three validation vectors. These vectors are listed in three methods of HttpServletRequest2: getErrorCodes( ), getErrorMsgs( ), and getErrorVars( ).
To override the default behavior, implement IServletErrorHandler and implement handleInputValueError( ) to handle errors related to input parameter validation. Before calling validate( ), call setServletErrorHandler( ) on the HttpServletRequest2 object.
Tip
It is recommended that you standardize error handling, so you may want to place error handling functionality in the default BaseServlet.
Return Value
This method returns any of the following integer values:
Example
The following code fragment uses the default handling but changes the template that is streamed. Typically, you would create this code in an inner class of the servlet that uses the error handler.
public class foo implements IServletErrorHandler
{
// The old error handler
IServletErrorHandler m_old
// Store the old servlet error handler somewhere
public foo (HttpServletRequest2 request)
{
m_old = request.getServletErrorHandler();
}
// Handle the error as before, but set additional information
public int handleInputValueError(
HttpServletRequest request,
String name,
int errorType)
{
m_old.handleInputValueError(request, name, errorType);
request.setAttribute("AddlInfo", "name failed");
return FAIL_STREAM_ERROR;
}
// Not interested in session variables,
// so just delegate to the old handler
public int handleSessionVariableError(
HttpServletRequest request,
String name,
int errorType)
{
return m_old.handleSessionVariableError(request, name, errorType);
}
// Handle the validation error appropriately
public int streamError(
HttpServletRequest request,
HttpServletResponse response,
Object errorSrc,
int errorType)
{
if (errorType == ERROR_VALIDATION_FAILED)
{
BaseUtils.includeJSP(request, response, "MyErrorTemplate.jsp");
return FAIL_DONT_STREAM_ERROR;
}
else
{
// handle the other errors by delegation
return m_old.streamError(request,response,errorSrc,errorType)
}
}
In your servlet, you call the validate( ) method after setting the error handler that validate( ) will use when it reports errors:
...
IServletErrorHandler handler = new foo((HttpServletRequest2)request);
((HttpServletRequest2)request).setServletErrorHandler(handler);
...
request.validate(response)
Related Topics
handleSessionVariableError( ), HttpServletRequest2 interface
handleSessionVariableError( )
Performs error handling for session validation.
Syntax
public abstract int handleSessionVariableError(
HttpServletRequest request,
String name,
int errorType)
request.
The HttpServletRequest containing the invalid session.
name.
The parameter name that failed validation.
errorType.
Unused.
Usage
Typically, the handleSessionVariableError( ) method is never called directly by the application programmer. Instead, this method is called by HttpServletRequest2.validate( ) for each error that is found during session validation.
handleSessionVariableError( ) is called if a session variable fails its metadata-driven validation. You can use this method in one of several ways:
The default behavior of handleSessionVariableError( ) is to add values into three validation vectors. These vectors are listed in three methods of HttpServletRequest2: getErrorCodes( ), getErrorMsgs( ), and getErrorVars( ).
To override the default behavior, implement IServletErrorHandler and implement handleSessionVariableError( ) to handle errors related to session validation. Before calling validate( ), call setServletErrorHandler( ) on the HttpServletRequest2 object.
Tip
It is recommended that you standardize error handling, so you may want to place error handling functionality in the default BaseServlet.
Return Value
This method returns any of the following integer values:
Examples
See handleInputValueError( ) for examples.
Related Topics
handleInputValueError( ), HttpServletRequest2 interface
streamError( )
Sends a standard error as a data stream.
Syntax
public abstract int streamError(
HttpServletRequest request,
HttpServletResponse response,
Object errorSource,
int errorType) throws IOException, ServletException
request.
The HttpServletRequest object.
response.
The HttpServletResponse object.
errorSource.
The object containing information about the source of the error.
errorType.
An integer value identifying the error type to report. Specify one of the following values:
Usage
Typically, the streamError( ) method is called directly by the application programmer as well as by HttpServletRequest2.validate( ) for validation errors. In particular, only the variants of validate( ) that stream an error will call the streamError( ) method. This applies to the two variants of validate( ) that take an HttpServletResponse object.
In addition, streamError( ) may be called by BaseUtils.initRowSets( ) when an exception occurs, or streamError( ) may be called by programmer-defined code.
To override the default behavior, implement IServletErrorHandler and implement streamError( ) to define the template or exception to stream when a validation error (or other type of error) occurs. Before calling validate( ), call setServletErrorHandler( ) on the HttpServletRequest2 object.
Return Value
This method returns any of the following integer values. By default, FAIL_DONT_STREAM_ERROR is returned.
Related Topics
HttpServletRequest2 interface
|